Date.php
1.2 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
<?php
namespace ACP\Search\Comparison;
use ACP\Search\Comparison;
use ACP\Search\Helper\DateValueFactory;
use ACP\Search\Helper\Sql\ComparisonFactory;
use ACP\Search\Labels;
use ACP\Search\Operators;
use ACP\Search\Query\Bindings;
use ACP\Search\Value;
use DateTime;
abstract class Date extends Comparison {
/**
* DB column for SQL clause
* @return string
*/
abstract protected function get_column();
public function __construct() {
parent::__construct( $this->operators(), Value::DATE, new Labels\Date() );
}
/**
* @return Operators
*/
public function operators() {
return new Operators( [
Operators::EQ,
Operators::GT,
Operators::LT,
Operators::BETWEEN,
] );
}
protected function create_query_bindings( $operator, Value $value ) {
if ( Operators::EQ === $operator ) {
$value_factory = new DateValueFactory( $value->get_type() );
$value = $value_factory->create_range_single_day( DateTime::createFromFormat( 'Y-m-d', $value->get_value() ) );
$operator = Operators::BETWEEN;
}
$where = ComparisonFactory::create(
$this->get_column(),
$operator,
$value
)->prepare();
$bindings = new Bindings();
$bindings->where( $where );
return $bindings;
}
}