MultiSelect.php
995 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
44
45
46
47
48
49
50
51
<?php
namespace ACP\Search\Comparison\Meta;
use AC\Helper\Select\Options;
use ACP\Search\Comparison;
use ACP\Search\Comparison\Values;
use ACP\Search\Helper\MetaQuery\SerializedComparisonFactory;
use ACP\Search\Operators;
use ACP\Search\Value;
class MultiSelect extends Comparison\Meta
implements Values {
/**
* @var array
*/
private $choices;
public function __construct( $meta_key, $meta_type, $choices ) {
parent::__construct( new Operators( [
Operators::EQ,
Operators::NEQ,
Operators::IS_EMPTY,
Operators::NOT_IS_EMPTY,
] ), $meta_key, $meta_type );
$this->choices = $choices;
}
/**
* @param string $operator
* @param Value $value
*
* @return array
*/
protected function get_meta_query( $operator, Value $value ) {
$comparison = SerializedComparisonFactory::create(
$this->get_meta_key(),
$operator,
$value
);
return $comparison();
}
public function get_values() {
return Options::create_from_array( $this->choices );
}
}