Checkmark.php
1.24 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
<?php
namespace ACP\Search\Comparison\Meta;
use AC;
use ACP\Search\Comparison\Meta;
use ACP\Search\Comparison\Values;
use ACP\Search\Operators;
use ACP\Search\Value;
class Checkmark extends Meta
implements Values {
/**
* @param string $meta_key
* @param string $meta_type
*/
public function __construct( $meta_key, $meta_type ) {
$operators = new Operators( [
Operators::EQ,
] );
parent::__construct( $operators, $meta_key, $meta_type );
}
public function get_values() {
return AC\Helper\Select\Options::create_from_array( [
'1' => __( 'True', 'codepress-admin-columns' ),
'0' => __( 'False', 'codepress-admin-columns' ),
] );
}
public function get_meta_query( $operator, Value $value ) {
$meta_query = [];
switch ( $value->get_value() ) {
case '1' :
$meta_query = [
'key' => $this->get_meta_key(),
'value' => [ '0', 'no', 'false', 'off', '' ],
'compare' => 'NOT IN',
];
break;
case '0' :
$meta_query = [
'relation' => 'OR',
[
'key' => $this->get_meta_key(),
'compare' => 'NOT EXISTS',
],
[
'key' => $this->get_meta_key(),
'value' => [ '0', 'no', 'false', 'off', '' ],
],
];
break;
}
return $meta_query;
}
}