RelationLegacy.php
2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace ACA\JetEngine\Column;
use AC;
use ACA\JetEngine\Editing;
use ACA\JetEngine\Service\ColumnGroups;
use ACA\JetEngine\Utils\Api;
use ACA\JetEngine\Utils\Relations;
use ACP;
class RelationLegacy extends AC\Column
implements ACP\Search\Searchable, ACP\Editing\Editable {
/**
* @var array
*/
protected $relation_information;
public function __construct() {
$this->set_group( ColumnGroups::JET_ENGINE_RELATION )
->set_label( __( 'JetEngine RelationLegacy', 'codepress-admin-columns' ) );
}
public function get_relation_key() {
return $this->get_type();
}
public function set_config( $relationInfo ) {
$this->relation_information = $relationInfo;
}
/**
* @return string|null
*/
protected function get_related_post_type() {
return Relations::get_related_post_type( $this->relation_information, $this->get_post_type() );
}
public function get_value( $id ) {
$raw_value = $this->get_raw_value( $id );
if ( empty( $raw_value ) ) {
return $this->get_empty_char();
}
$formattedPosts = array_map( function ( $postId ) {
return $this->get_formatted_value( $postId, $postId );
}, is_array( $raw_value ) ? $raw_value : [ $raw_value ] );
return implode( ', ', $formattedPosts );
}
public function get_raw_value( $id ) {
return Api::Relations()->get_related_posts( [
'hash' => $this->get_relation_key(),
'current' => $this->get_post_type(),
'post_id' => $id,
] );
}
protected function register_settings() {
$this->add_setting( new AC\Settings\Column\Post( $this ) );
}
public function search() {
return new ACP\Search\Comparison\Meta\Post( $this->get_relation_key(), 'post', $this->get_related_post_type() );
}
public function editing() {
$related_post_type = $this->get_related_post_type();
return $related_post_type !== null
? new Editing\Service\RelationshipLegacy( $this->get_relation_key(), $this->get_post_type(), $related_post_type, Relations::has_multiple_relations( $this->relation_information, $this->get_post_type() ) )
: null;
}
}