Relation.php
985 Bytes
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
<?php
namespace ACA\MetaBox\Column;
use AC;
use ACA\MetaBox\Entity;
use ACP;
abstract class Relation extends AC\Column implements ACP\Search\Searchable, ACP\Editing\Editable, ACP\Export\Exportable, ACP\ConditionalFormat\Formattable {
use ACP\ConditionalFormat\FilteredHtmlFormatTrait;
/**
* @var Entity\Relation
*/
protected $relation;
public function __construct() {
$this->set_group( 'metabox_relation' )
->set_label( __( 'Metabox Relation', 'codepress-admin-columns' ) );
}
public function set_relation( Entity\Relation $relation ) {
$this->relation = $relation;
}
public function get_value( $id ) {
$ids = $this->get_raw_value( $id );
return empty( $ids )
? $this->get_empty_char()
: implode( ', ', array_map( [ $this, 'get_formatted_value' ], $ids ) );
}
public function get_raw_value( $id ) {
return $this->relation->get_related_ids( $id );
}
public function export() {
return new ACP\Export\Model\StrippedValue( $this );
}
}