Taxonomy.php
1.79 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
<?php
namespace ACA\Pods\Field\Pick;
use AC;
use ACA\Pods\Editing;
use ACA\Pods\Field;
use ACA\Pods\Filtering;
use ACA\Pods\Search;
use ACP\Sorting\FormatValue\SerializedSettingFormatter;
use ACP\Sorting\FormatValue\SettingFormatter;
use ACP\Sorting\Model\MetaFormatFactory;
class Taxonomy extends Field\Pick {
public function get_value( $id ) {
$values = [];
foreach ( $this->get_db_value( $id ) as $term_id ) {
$value = $this->column->get_formatted_value( $term_id, $term_id );
if ( $value ) {
$values[] = $value;
}
}
return implode( ', ', $values );
}
public function sorting() {
$setting = $this->column->get_setting( AC\Settings\Column\Term::NAME );
$formatter = $this->is_multiple()
? new SerializedSettingFormatter( new SettingFormatter( $setting ) )
: new SettingFormatter( $setting );
return ( new MetaFormatFactory() )->create( $this->get_meta_type(), $this->get_meta_key(), $formatter );
}
public function get_raw_value( $id ) {
return $this->get_ids_from_array( parent::get_raw_value( $id ), 'term_id' );
}
public function editing() {
return new Editing\Service\PickTaxonomy(
new Editing\Storage\Field( $this->get_pod(), $this->get_field_name(), new Editing\Storage\Read\DbRaw( $this->get_meta_key(), $this->get_meta_type() ) ),
'multi' === $this->get_option( 'pick_format_type' ),
$this->get_taxonomy()
);
}
public function filtering() {
return new Filtering\PickTaxonomy( $this->column() );
}
public function search() {
return new Search\PickTaxonomy( $this->column()->get_meta_key(), $this->column()->get_meta_type(), (array) $this->get_taxonomy() );
}
public function get_taxonomy() {
return $this->get( 'pick_val' );
}
public function get_dependent_settings() {
return [
new AC\Settings\Column\Term( $this->column ),
];
}
}