PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / database / Overrides / QueryBuilder.php

QueryBuilder.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at database/Overrides/QueryBuilder.php

219 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\Database\Overrides;
4
5 use DateTimeInterface;
6 use FluentCart\App\Services\DateTime\DateTime;
7 use FluentCart\Framework\Database\Query\Builder;
8 use FluentCart\Framework\Database\Query\Expression;
9
10
11 class QueryBuilder extends Builder
12 {
13
14 public function whereDate($column, $operator, $value = null, $boolean = 'and')
15 {
16 [$value, $operator] = $this->prepareValueAndOperator(
17 $value, $operator, func_num_args() === 2
18 );
19
20 $value = $this->flattenValue($value);
21
22 if ($value instanceof DateTimeInterface) {
23 $value = DateTime::anyTimeToGmt($value)->format('Y-m-d');
24 }
25
26 return $this->addDateBasedWhere('Date', $column, $operator, $value, $boolean);
27 }
28
29 /**
30 * Add an "or where date" statement to the query.
31 *
32 * @param string $column
33 * @param string $operator
34 * @param \DateTimeInterface|string|null $value
35 * @return $this
36 */
37 public function orWhereDate($column, $operator, $value = null)
38 {
39 [$value, $operator] = $this->prepareValueAndOperator(
40 $value, $operator, func_num_args() === 2
41 );
42
43 return $this->whereDate($column, $operator, $value, 'or');
44 }
45
46 /**
47 * Add a "where time" statement to the query.
48 *
49 * @param string $column
50 * @param string $operator
51 * @param \DateTimeInterface|string|null $value
52 * @param string $boolean
53 * @return $this
54 */
55 public function whereTime($column, $operator, $value = null, $boolean = 'and')
56 {
57 [$value, $operator] = $this->prepareValueAndOperator(
58 $value, $operator, func_num_args() === 2
59 );
60
61 $value = $this->flattenValue($value);
62
63 if ($value instanceof DateTimeInterface) {
64 $value = DateTime::anyTimeToGmt($value)->format('H:i:s');
65 }
66
67 return $this->addDateBasedWhere('Time', $column, $operator, $value, $boolean);
68 }
69
70 /**
71 * Add an "or where time" statement to the query.
72 *
73 * @param string $column
74 * @param string $operator
75 * @param \DateTimeInterface|string|null $value
76 * @return $this
77 */
78 public function orWhereTime($column, $operator, $value = null)
79 {
80 [$value, $operator] = $this->prepareValueAndOperator(
81 $value, $operator, func_num_args() === 2
82 );
83
84 return $this->whereTime($column, $operator, $value, 'or');
85 }
86
87 /**
88 * Add a "where day" statement to the query.
89 *
90 * @param string $column
91 * @param string $operator
92 * @param \DateTimeInterface|string|null $value
93 * @param string $boolean
94 * @return $this
95 */
96 public function whereDay($column, $operator, $value = null, $boolean = 'and')
97 {
98 [$value, $operator] = $this->prepareValueAndOperator(
99 $value, $operator, func_num_args() === 2
100 );
101
102 $value = $this->flattenValue($value);
103
104 if ($value instanceof DateTimeInterface) {
105 $value = DateTime::anyTimeToGmt($value)->format('d');
106 }
107
108 if (!$value instanceof Expression) {
109 $value = sprintf('%02d', $value);
110 }
111
112 return $this->addDateBasedWhere('Day', $column, $operator, $value, $boolean);
113 }
114
115 /**
116 * Add an "or where day" statement to the query.
117 *
118 * @param string $column
119 * @param string $operator
120 * @param \DateTimeInterface|string|null $value
121 * @return $this
122 */
123 public function orWhereDay($column, $operator, $value = null)
124 {
125 [$value, $operator] = $this->prepareValueAndOperator(
126 $value, $operator, func_num_args() === 2
127 );
128
129 return $this->whereDay($column, $operator, $value, 'or');
130 }
131
132 /**
133 * Add a "where month" statement to the query.
134 *
135 * @param string $column
136 * @param string $operator
137 * @param \DateTimeInterface|string|null $value
138 * @param string $boolean
139 * @return $this
140 */
141 public function whereMonth($column, $operator, $value = null, $boolean = 'and')
142 {
143 [$value, $operator] = $this->prepareValueAndOperator(
144 $value, $operator, func_num_args() === 2
145 );
146
147 $value = $this->flattenValue($value);
148
149 if ($value instanceof DateTimeInterface) {
150 $value = DateTime::anyTimeToGmt($value)->format('m');
151 }
152
153 if (!$value instanceof Expression) {
154 $value = sprintf('%02d', $value);
155 }
156
157 return $this->addDateBasedWhere('Month', $column, $operator, $value, $boolean);
158 }
159
160 /**
161 * Add an "or where month" statement to the query.
162 *
163 * @param string $column
164 * @param string $operator
165 * @param \DateTimeInterface|string|null $value
166 * @return $this
167 */
168 public function orWhereMonth($column, $operator, $value = null)
169 {
170 [$value, $operator] = $this->prepareValueAndOperator(
171 $value, $operator, func_num_args() === 2
172 );
173
174 return $this->whereMonth($column, $operator, $value, 'or');
175 }
176
177 /**
178 * Add a "where year" statement to the query.
179 *
180 * @param string $column
181 * @param string $operator
182 * @param \DateTimeInterface|string|int|null $value
183 * @param string $boolean
184 * @return $this
185 */
186 public function whereYear($column, $operator, $value = null, $boolean = 'and')
187 {
188 [$value, $operator] = $this->prepareValueAndOperator(
189 $value, $operator, func_num_args() === 2
190 );
191
192 $value = $this->flattenValue($value);
193
194 if ($value instanceof DateTimeInterface) {
195 $value = DateTime::anyTimeToGmt($value)->format('Y');
196 }
197
198 return $this->addDateBasedWhere('Year', $column, $operator, $value, $boolean);
199 }
200
201 /**
202 * Add an "or where year" statement to the query.
203 *
204 * @param string $column
205 * @param string $operator
206 * @param \DateTimeInterface|string|int|null $value
207 * @return $this
208 */
209 public function orWhereYear($column, $operator, $value = null)
210 {
211 [$value, $operator] = $this->prepareValueAndOperator(
212 $value, $operator, func_num_args() === 2
213 );
214
215 return $this->whereYear($column, $operator, $value, 'or');
216 }
217
218
219 }