Name.php
1.03 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
<?php
namespace ACP\Search\Comparison\User;
use ACP\Search\Comparison;
use ACP\Search\Helper\MetaQuery\ComparisonFactory;
use ACP\Search\Operators;
use ACP\Search\Query\Bindings;
use ACP\Search\Value;
class Name extends Comparison {
/**
* @var array
*/
private $meta_keys;
/**
* @param array $meta_keys
*/
public function __construct( array $meta_keys ) {
$operators = new Operators( [
Operators::CONTAINS,
Operators::BEGINS_WITH,
Operators::ENDS_WITH,
] );
$this->meta_keys = $meta_keys;
parent::__construct( $operators );
}
public function create_query_bindings( $operator, Value $value ) {
$bindings = new Bindings();
$bindings->meta_query(
$this->get_meta_query( $operator, $value )
);
return $bindings;
}
protected function get_meta_query( $operator, Value $value ) {
$meta_query = [
'relation' => 'OR',
];
foreach ( $this->meta_keys as $key ) {
$mq = ComparisonFactory::create(
$key,
$operator,
$value
);
$meta_query[] = $mq();
}
return $meta_query;
}
}