Checkbox.php
1.09 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
<?php
namespace ACA\MetaBox\Column;
use AC\Helper\Select\Option;
use AC\Type\ToggleOptions;
use ACA;
use ACA\MetaBox\Editing;
use ACA\MetaBox\Search;
use ACP;
class Checkbox extends ACA\MetaBox\Column
implements ACP\Search\Searchable, ACP\Editing\Editable {
public function format_single_value( $value, $id = null ) {
return $value
? ac_helper()->icon->yes()
: ac_helper()->icon->no();
}
public function get_multiple_values( $id ) {
$raw_value = $this->get_raw_value( $id );
if ( ! $raw_value ) {
return $this->get_empty_char();
}
$values = [];
$number_checks = count( (array) $raw_value );
for ( $i = 0; $i < $number_checks; $i++ ) {
$values[] = ac_helper()->icon->yes();
}
return implode( ', ', $values );
}
public function editing() {
return $this->is_clonable()
? false
: new ACP\Editing\Service\Basic(
( new ACP\Editing\View\Toggle( new ToggleOptions( new Option( '' ), new Option( '1' ) ) ) ),
( new Editing\StorageFactory() )->create( $this )
);
}
public function search() {
return ( new Search\Factory\Meta() )->create( $this );
}
}