Meta.php
1.46 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
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace ACP\Search\Comparison;
use ACP\Search\Comparison;
use ACP\Search\Helper\MetaQuery\ComparisonFactory;
use ACP\Search\Labels;
use ACP\Search\Operators;
use ACP\Search\Query\Bindings;
use ACP\Search\Value;
abstract class Meta extends Comparison {
/**
* @var string
*/
protected $meta_key;
/**
* @var string
*/
protected $meta_type;
/**
* Meta constructor.
*
* @param Operators $operators
* @param string $meta_key
* @param string $meta_type
* @param string $type
* @param Labels $labels
*/
public function __construct( $operators, $meta_key, $meta_type, $type = null, $labels = null ) {
$this->meta_key = $meta_key;
$this->meta_type = $meta_type;
parent::__construct( $operators, $type, $labels );
}
/**
* @return string
*/
protected function get_meta_key() {
return $this->meta_key;
}
/**
* @return string
*/
public function get_meta_type() {
return $this->meta_type;
}
public function create_query_bindings( $operator, Value $value ) {
$bindings = new Bindings();
$bindings->meta_query(
$this->get_meta_query( $operator, $value )
);
return $bindings;
}
/**
* Template function that should work most of the cases
*
* @param string $operator
* @param Value $value
*
* @return array
*/
protected function get_meta_query( $operator, Value $value ) {
$comparison = ComparisonFactory::create(
$this->meta_key,
$operator,
$value
);
return $comparison();
}
}