|
1
|
|
|
<?php |
|
2
|
|
|
/******************************************************************************* |
|
3
|
|
|
* This file is part of the GraphQL Bundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) YnloUltratech <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
******************************************************************************/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Model\Filter; |
|
12
|
|
|
|
|
13
|
|
|
use Ynlo\GraphQLBundle\Annotation as GraphQL; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @GraphQL\InputObjectType( |
|
17
|
|
|
* description="Create date comparison expression to filter values by date. |
|
18
|
|
|
|
|
19
|
|
|
#### Example: |
|
20
|
|
|
|
|
21
|
|
|
To select values with date after January 15, 2018: |
|
22
|
|
|
```` |
|
23
|
|
|
op: AFTER |
|
24
|
|
|
strict: true |
|
25
|
|
|
date: '2018-01-15' |
|
26
|
|
|
```` |
|
27
|
|
|
|
|
28
|
|
|
or values using date range to select all records in January, 2018: |
|
29
|
|
|
```` |
|
30
|
|
|
op: BETWEEN |
|
31
|
|
|
date: '2018-01-01' |
|
32
|
|
|
maxDate: '2018-01-31' |
|
33
|
|
|
```` |
|
34
|
|
|
") |
|
35
|
|
|
*/ |
|
36
|
|
|
class DateComparisonExpression |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* @var string|null |
|
40
|
|
|
* |
|
41
|
|
|
* @GraphQL\Field(type="DateComparisonOperator!", description="Comparison operator") |
|
42
|
|
|
*/ |
|
43
|
|
|
private $op; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var bool |
|
47
|
|
|
* |
|
48
|
|
|
* @GraphQL\Field(type="bool", description="If strict mode is enabled the value given in not included.") |
|
49
|
|
|
*/ |
|
50
|
|
|
private $strict = false; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var \DateTime|null |
|
54
|
|
|
* |
|
55
|
|
|
* @GraphQL\Field(type="date!", description="Base date to compare") |
|
56
|
|
|
*/ |
|
57
|
|
|
private $date; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var \DateTime|null |
|
61
|
|
|
* |
|
62
|
|
|
* @GraphQL\Field(type="date", description="Max value when use **BETWEEN** operator") |
|
63
|
|
|
*/ |
|
64
|
|
|
private $maxDate; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return string|null |
|
68
|
|
|
*/ |
|
69
|
6 |
|
public function getOp(): ?string |
|
70
|
|
|
{ |
|
71
|
6 |
|
return $this->op; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param string $op |
|
76
|
|
|
* |
|
77
|
|
|
* @return DateComparisonExpression |
|
78
|
|
|
*/ |
|
79
|
6 |
|
public function setOp(string $op): DateComparisonExpression |
|
80
|
|
|
{ |
|
81
|
6 |
|
$this->op = $op; |
|
82
|
|
|
|
|
83
|
6 |
|
return $this; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return bool |
|
88
|
|
|
*/ |
|
89
|
6 |
|
public function isStrict(): bool |
|
90
|
|
|
{ |
|
91
|
6 |
|
return $this->strict; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param bool $strict |
|
96
|
|
|
*/ |
|
97
|
3 |
|
public function setStrict(bool $strict): void |
|
98
|
|
|
{ |
|
99
|
3 |
|
$this->strict = $strict; |
|
100
|
3 |
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @return \DateTime|null |
|
104
|
|
|
*/ |
|
105
|
6 |
|
public function getDate(): ?\DateTime |
|
106
|
|
|
{ |
|
107
|
6 |
|
return $this->date; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @param \DateTime|null $date |
|
112
|
|
|
* |
|
113
|
|
|
* @return DateComparisonExpression |
|
114
|
|
|
*/ |
|
115
|
8 |
|
public function setDate(?\DateTime $date): DateComparisonExpression |
|
116
|
|
|
{ |
|
117
|
8 |
|
$this->date = $date; |
|
118
|
|
|
|
|
119
|
8 |
|
return $this; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @return \DateTime|null |
|
124
|
|
|
*/ |
|
125
|
6 |
|
public function getMaxDate(): ?\DateTime |
|
126
|
|
|
{ |
|
127
|
6 |
|
return $this->maxDate; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param \DateTime|null $maxDate |
|
132
|
|
|
* |
|
133
|
|
|
* @return DateComparisonExpression |
|
134
|
|
|
*/ |
|
135
|
2 |
|
public function setMaxDate(?\DateTime $maxDate): DateComparisonExpression |
|
136
|
|
|
{ |
|
137
|
2 |
|
$this->maxDate = $maxDate; |
|
138
|
|
|
|
|
139
|
2 |
|
return $this; |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|