Entry.php
1.32 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 ACA\GravityForms\Search\Comparison;
use ACA\GravityForms\Search\Query\Bindings;
use ACP\Search\Comparison;
use ACP\Search\Helper\Sql\ComparisonFactory;
use ACP\Search\Operators;
use ACP\Search\Value;
abstract class Entry extends Comparison {
/**
* @var string
*/
protected $meta_key;
public function __construct( $meta_key, Operators $operators, $value_type = null, $labels = null ) {
parent::__construct( $operators, $value_type, $labels );
$this->meta_key = (string) $meta_key;
}
protected function create_query_bindings( $operator, Value $value ) {
if ( Operators::IS_EMPTY === $operator ) {
return $this->create_empty_query_bindings();
}
$bindings = new Bindings();
$alias = $bindings->get_entry_meta_table_name_alias();
$where = ComparisonFactory::create(
$alias . '.meta_value',
$operator,
$value
);
$bindings->join_entry_meta_table( $alias, $this->meta_key )
->where( $where->prepare() );
return $bindings;
}
/**
* @return Bindings
*/
protected function create_empty_query_bindings() {
$bindings = new Bindings();
$alias = $bindings->get_entry_meta_table_name_alias();
$where = sprintf( '%s.meta_value IS NULL', $alias );
$bindings->join_entry_meta_table( $alias, $this->meta_key, 'LEFT' )
->where( $where );
return $bindings;
}
}