1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfEventMgt\Domain\Repository; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand; |
12
|
|
|
use DERHANSEN\SfEventMgt\Service\CategoryService; |
13
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
14
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
15
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; |
16
|
|
|
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The repository for Events |
20
|
|
|
* |
21
|
|
|
* @author Torben Hansen <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class EventRepository extends \TYPO3\CMS\Extbase\Persistence\Repository |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Set default sorting |
27
|
|
|
* |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $defaultOrderings = [ |
31
|
|
|
'startdate' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Disable the use of storage records, because the StoragePage can be set |
36
|
|
|
* in the plugin |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
|
|
public function initializeObject() |
41
|
|
|
{ |
42
|
|
|
$this->defaultQuerySettings = $this->objectManager->get(Typo3QuerySettings::class); |
43
|
|
|
$this->defaultQuerySettings->setRespectStoragePage(false); |
44
|
|
|
} |
45
|
31 |
|
|
46
|
|
|
/** |
47
|
31 |
|
* Returns the objects of this repository matching the given demand |
48
|
31 |
|
* |
49
|
31 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
50
|
|
|
* |
51
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface QueryResultInterface |
52
|
|
|
*/ |
53
|
|
|
public function findDemanded(EventDemand $eventDemand) |
54
|
|
|
{ |
55
|
|
|
$constraints = []; |
56
|
|
|
$query = $this->createQuery(); |
57
|
|
|
$this->setStoragePageConstraint($query, $eventDemand, $constraints); |
58
|
30 |
|
$this->setDisplayModeConstraint($query, $eventDemand, $constraints); |
59
|
|
|
$this->setCategoryConstraint($query, $eventDemand, $constraints); |
60
|
30 |
|
$this->setLocationConstraint($query, $eventDemand, $constraints); |
61
|
30 |
|
$this->setLocationCityConstraint($query, $eventDemand, $constraints); |
62
|
30 |
|
$this->setLocationCountryConstraint($query, $eventDemand, $constraints); |
63
|
30 |
|
$this->setSpeakerConstraint($query, $eventDemand, $constraints); |
64
|
30 |
|
$this->setOrganisatorConstraint($query, $eventDemand, $constraints); |
65
|
30 |
|
$this->setStartEndDateConstraint($query, $eventDemand, $constraints); |
66
|
30 |
|
$this->setSearchConstraint($query, $eventDemand, $constraints); |
67
|
30 |
|
$this->setTopEventConstraint($query, $eventDemand, $constraints); |
68
|
30 |
|
$this->setYearMonthDayRestriction($query, $eventDemand, $constraints); |
69
|
30 |
|
|
70
|
30 |
|
/** @var Dispatcher $signalSlotDispatcher */ |
71
|
30 |
|
$signalSlotDispatcher = $this->objectManager->get(Dispatcher::class); |
72
|
|
|
$signalSlotDispatcher->dispatch( |
73
|
30 |
|
__CLASS__, |
74
|
30 |
|
__FUNCTION__ . 'ModifyQueryConstraints', |
75
|
30 |
|
[&$constraints, $query, $eventDemand, $this] |
76
|
|
|
); |
77
|
30 |
|
|
78
|
30 |
|
$this->setOrderingsFromDemand($query, $eventDemand); |
79
|
|
|
|
80
|
|
|
if (count($constraints) > 0) { |
81
|
|
|
$query->matching($query->logicalAnd($constraints)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$this->setQueryLimitFromDemand($query, $eventDemand); |
85
|
|
|
|
86
|
|
|
return $query->execute(); |
87
|
|
|
} |
88
|
|
|
|
89
|
30 |
|
/** |
90
|
|
|
* Sets a query limit to the given query for the given demand |
91
|
30 |
|
* |
92
|
30 |
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
93
|
1 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
94
|
30 |
|
* |
95
|
1 |
|
* @return void |
96
|
1 |
|
*/ |
97
|
30 |
|
protected function setQueryLimitFromDemand($query, EventDemand $eventDemand) |
98
|
|
|
{ |
99
|
|
|
if ($eventDemand->getQueryLimit() != null && |
100
|
|
|
MathUtility::canBeInterpretedAsInteger($eventDemand->getQueryLimit()) && |
101
|
|
|
(int)$eventDemand->getQueryLimit() > 0 |
102
|
|
|
) { |
103
|
|
|
$query->setLimit((int)$eventDemand->getQueryLimit()); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
30 |
|
/** |
108
|
|
|
* Sets the ordering to the given query for the given demand |
109
|
30 |
|
* |
110
|
30 |
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
111
|
30 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
112
|
30 |
|
* |
113
|
|
|
* @return void |
114
|
|
|
*/ |
115
|
|
|
protected function setOrderingsFromDemand($query, EventDemand $eventDemand) |
116
|
|
|
{ |
117
|
|
|
$orderings = []; |
118
|
30 |
|
$orderFieldAllowed = GeneralUtility::trimExplode(',', $eventDemand->getOrderFieldAllowed(), true); |
119
|
|
|
if ($eventDemand->getOrderField() != '' && $eventDemand->getOrderDirection() != '' && |
120
|
|
|
!empty($orderFieldAllowed) && in_array($eventDemand->getOrderField(), $orderFieldAllowed, true)) { |
121
|
|
|
$orderings[$eventDemand->getOrderField()] = ((strtolower($eventDemand->getOrderDirection()) == 'desc') ? |
122
|
|
|
\TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING : |
123
|
|
|
\TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING); |
124
|
|
|
$query->setOrderings($orderings); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
30 |
|
* Sets the storagePage constraint to the given constraints array |
130
|
|
|
* |
131
|
30 |
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
132
|
30 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
133
|
30 |
|
* @param array $constraints Constraints |
134
|
30 |
|
* |
135
|
30 |
|
* @return void |
136
|
|
|
*/ |
137
|
|
|
protected function setStoragePageConstraint($query, $eventDemand, &$constraints) |
138
|
|
|
{ |
139
|
|
|
if ($eventDemand->getStoragePage() && $eventDemand->getStoragePage() !== '') { |
140
|
|
|
$pidList = GeneralUtility::intExplode(',', $eventDemand->getStoragePage(), true); |
141
|
|
|
$constraints[] = $query->in('pid', $pidList); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
30 |
|
* Sets the displayMode constraint to the given constraints array |
147
|
|
|
* |
148
|
30 |
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
149
|
30 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
150
|
1 |
|
* @param array $constraints Constraints |
151
|
1 |
|
* |
152
|
29 |
|
* @return void |
153
|
1 |
|
*/ |
154
|
1 |
|
protected function setDisplayModeConstraint($query, $eventDemand, &$constraints) |
155
|
28 |
|
{ |
156
|
30 |
|
switch ($eventDemand->getDisplayMode()) { |
157
|
30 |
|
case 'future': |
158
|
|
|
$constraints[] = $query->greaterThan('startdate', $eventDemand->getCurrentDateTime()); |
159
|
|
|
break; |
160
|
|
|
case 'current_future': |
161
|
|
|
$constraints[] = $query->logicalOr([ |
162
|
|
|
$query->greaterThan('startdate', $eventDemand->getCurrentDateTime()), |
163
|
|
|
$query->logicalAnd([ |
164
|
|
|
$query->greaterThanOrEqual('enddate', $eventDemand->getCurrentDateTime()), |
165
|
|
|
$query->lessThanOrEqual('startdate', $eventDemand->getCurrentDateTime()) |
166
|
|
|
]) |
167
|
|
|
]); |
168
|
30 |
|
break; |
169
|
|
|
case 'past': |
170
|
30 |
|
$constraints[] = $query->lessThanOrEqual('enddate', $eventDemand->getCurrentDateTime()); |
171
|
5 |
|
break; |
172
|
5 |
|
default: |
173
|
1 |
|
} |
174
|
1 |
|
} |
175
|
1 |
|
|
176
|
4 |
|
/** |
177
|
|
|
* Sets the category constraint to the given constraints array |
178
|
5 |
|
* |
179
|
5 |
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
180
|
5 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
181
|
5 |
|
* @param array $constraints Constraints |
182
|
5 |
|
* |
183
|
5 |
|
* @return void |
184
|
5 |
|
*/ |
185
|
30 |
|
protected function setCategoryConstraint($query, $eventDemand, &$constraints) |
186
|
|
|
{ |
187
|
|
|
// If no category constraint is set, categories should not be respected in the query |
188
|
|
|
if ($eventDemand->getCategoryConjunction() === '') { |
189
|
|
|
return; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if ($eventDemand->getCategory() != '') { |
193
|
|
|
$categoryConstraints = []; |
194
|
|
|
if ($eventDemand->getIncludeSubcategories()) { |
195
|
|
|
$categoryList = CategoryService::getCategoryListWithChilds($eventDemand->getCategory()); |
196
|
30 |
|
$categories = GeneralUtility::intExplode(',', $categoryList, true); |
197
|
|
|
} else { |
198
|
30 |
|
$categories = GeneralUtility::intExplode(',', $eventDemand->getCategory(), true); |
199
|
3 |
|
} |
200
|
3 |
|
foreach ($categories as $category) { |
201
|
30 |
|
$categoryConstraints[] = $query->contains('category', $category); |
202
|
|
|
} |
203
|
|
|
if (count($categoryConstraints) > 0) { |
204
|
|
|
$constraints[] = $this->getCategoryConstraint($query, $eventDemand, $categoryConstraints); |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Returns the category constraint depending on the category conjunction configured in eventDemand |
211
|
|
|
* |
212
|
30 |
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
213
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
214
|
30 |
|
* @param array $categoryConstraints |
215
|
2 |
|
* @return mixed |
216
|
2 |
|
*/ |
217
|
30 |
|
public function getCategoryConstraint($query, $eventDemand, $categoryConstraints) |
218
|
|
|
{ |
219
|
|
|
switch (strtolower($eventDemand->getCategoryConjunction())) { |
220
|
|
|
case 'and': |
221
|
|
|
$constraint = $query->logicalAnd($categoryConstraints); |
222
|
|
|
break; |
223
|
|
|
case 'notor': |
224
|
|
|
$constraint = $query->logicalNot($query->logicalOr($categoryConstraints)); |
225
|
|
|
break; |
226
|
|
|
case 'notand': |
227
|
|
|
$constraint = $query->logicalNot($query->logicalAnd($categoryConstraints)); |
228
|
30 |
|
break; |
229
|
|
|
case 'or': |
230
|
30 |
|
default: |
231
|
2 |
|
$constraint = $query->logicalOr($categoryConstraints); |
232
|
2 |
|
} |
233
|
30 |
|
|
234
|
|
|
return $constraint; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Sets the location constraint to the given constraints array |
239
|
|
|
* |
240
|
|
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
241
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
242
|
|
|
* @param array $constraints Constraints |
243
|
|
|
* |
244
|
30 |
|
* @return void |
245
|
|
|
*/ |
246
|
|
|
protected function setLocationConstraint($query, $eventDemand, &$constraints) |
247
|
30 |
|
{ |
248
|
1 |
|
if ($eventDemand->getLocation() !== null && $eventDemand->getLocation() != '') { |
249
|
1 |
|
$constraints[] = $query->equals('location', $eventDemand->getLocation()); |
250
|
|
|
} |
251
|
|
|
} |
252
|
30 |
|
|
253
|
1 |
|
/** |
254
|
1 |
|
* Sets the location.city constraint to the given constraints array |
255
|
30 |
|
* |
256
|
|
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
257
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
258
|
|
|
* @param array $constraints Constraints |
259
|
|
|
* |
260
|
|
|
* @return void |
261
|
|
|
*/ |
262
|
|
|
protected function setLocationCityConstraint($query, $eventDemand, &$constraints) |
263
|
|
|
{ |
264
|
|
|
if ($eventDemand->getLocationCity() !== null && $eventDemand->getLocationCity() != '') { |
265
|
|
|
$constraints[] = $query->equals('location.city', $eventDemand->getLocationCity()); |
266
|
30 |
|
} |
267
|
|
|
} |
268
|
30 |
|
|
269
|
30 |
|
/** |
270
|
3 |
|
* Sets the location.country constraint to the given constraints array |
271
|
30 |
|
* |
272
|
1 |
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
273
|
1 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
274
|
|
|
* @param array $constraints Constraints |
275
|
1 |
|
* |
276
|
|
|
* @return void |
277
|
|
|
*/ |
278
|
|
|
protected function setLocationCountryConstraint($query, $eventDemand, &$constraints) |
279
|
1 |
|
{ |
280
|
1 |
|
if ($eventDemand->getLocationCountry() !== null && $eventDemand->getLocationCountry() != '') { |
281
|
1 |
|
$constraints[] = $query->equals('location.country', $eventDemand->getLocationCountry()); |
282
|
1 |
|
} |
283
|
1 |
|
} |
284
|
1 |
|
|
285
|
|
|
/** |
286
|
1 |
|
* Sets the speaker constraint to the given constraints array |
287
|
1 |
|
* |
288
|
1 |
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
289
|
1 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
290
|
30 |
|
* @param array $constraints Constraints |
291
|
|
|
* |
292
|
|
|
* @return void |
293
|
|
|
*/ |
294
|
|
|
protected function setSpeakerConstraint($query, $eventDemand, &$constraints) |
295
|
|
|
{ |
296
|
|
|
if ($eventDemand->getSpeaker() !== null && $eventDemand->getSpeaker() != '') { |
297
|
|
|
$constraints[] = $query->contains('speaker', $eventDemand->getSpeaker()); |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
301
|
30 |
|
/** |
302
|
|
|
* Sets the organisator constraint to the given constraints array |
303
|
30 |
|
* |
304
|
2 |
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
305
|
2 |
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
306
|
30 |
|
* @param array $constraints Constraints |
307
|
|
|
* |
308
|
|
|
* @return void |
309
|
|
|
*/ |
310
|
|
|
protected function setOrganisatorConstraint($query, $eventDemand, &$constraints) |
311
|
|
|
{ |
312
|
|
|
if ($eventDemand->getOrganisator() !== null && $eventDemand->getOrganisator() != '') { |
313
|
|
|
$constraints[] = $query->equals('organisator', $eventDemand->getOrganisator()); |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* Sets the start- and enddate constraint to the given constraints array |
319
|
|
|
* |
320
|
|
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
321
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
322
|
|
|
* @param array $constraints Constraints |
323
|
|
|
* |
324
|
|
|
* @return void |
325
|
|
|
*/ |
326
|
|
|
protected function setStartEndDateConstraint($query, $eventDemand, &$constraints) |
327
|
|
|
{ |
328
|
|
|
if ($eventDemand->getSearchDemand() && $eventDemand->getSearchDemand()->getStartDate() !== null && |
329
|
|
|
$eventDemand->getSearchDemand()->getEndDate() !== null |
330
|
|
|
) { |
331
|
|
|
/* StartDate and EndDate - Search for events between two given dates */ |
332
|
|
|
$begin = $eventDemand->getSearchDemand()->getStartDate(); |
333
|
|
|
$end = $eventDemand->getSearchDemand()->getEndDate(); |
334
|
|
|
$constraints[] = $query->logicalOr([ |
335
|
|
|
$query->between('startdate', $begin, $end), |
336
|
|
|
$query->between('enddate', $begin, $end), |
337
|
|
|
$query->logicalAnd([ |
338
|
|
|
$query->greaterThanOrEqual('enddate', $begin), |
339
|
|
|
$query->lessThanOrEqual('startdate', $begin) |
340
|
|
|
]) |
341
|
|
|
]); |
342
|
|
|
} elseif ($eventDemand->getSearchDemand() && $eventDemand->getSearchDemand()->getStartDate() !== null) { |
343
|
|
|
/* StartDate - Search for events beginning at a given date */ |
344
|
|
|
$constraints[] = $query->greaterThanOrEqual('startdate', $eventDemand->getSearchDemand()->getStartDate()); |
345
|
|
|
} elseif ($eventDemand->getSearchDemand() && $eventDemand->getSearchDemand()->getEndDate() !== null) { |
346
|
|
|
/* EndDate - Search for events ending on a given date */ |
347
|
|
|
$constraints[] = $query->lessThanOrEqual('enddate', $eventDemand->getSearchDemand()->getEndDate()); |
348
|
|
|
} |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* Sets the search constraint to the given constraints array |
353
|
|
|
* |
354
|
|
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
355
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
356
|
|
|
* @param array $constraints Constraints |
357
|
|
|
* |
358
|
|
|
* @return void |
359
|
|
|
*/ |
360
|
|
|
protected function setSearchConstraint($query, $eventDemand, &$constraints) |
361
|
|
|
{ |
362
|
|
|
if ($eventDemand->getSearchDemand() && |
363
|
|
|
$eventDemand->getSearchDemand()->getSearch() !== null && |
364
|
|
|
$eventDemand->getSearchDemand()->getSearch() !== '' |
365
|
|
|
) { |
366
|
|
|
$searchFields = GeneralUtility::trimExplode(',', $eventDemand->getSearchDemand()->getFields(), true); |
367
|
|
|
$searchConstraints = []; |
368
|
|
|
|
369
|
|
|
if (count($searchFields) === 0) { |
370
|
|
|
throw new \UnexpectedValueException('No search fields defined', 1318497755); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
$searchSubject = $eventDemand->getSearchDemand()->getSearch(); |
374
|
|
|
foreach ($searchFields as $field) { |
375
|
|
|
if (!empty($searchSubject)) { |
376
|
|
|
$searchConstraints[] = $query->like($field, '%' . addcslashes($searchSubject, '_%') . '%', false); |
|
|
|
|
377
|
|
|
} |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
if (count($searchConstraints)) { |
381
|
|
|
$constraints[] = $query->logicalOr($searchConstraints); |
382
|
|
|
} |
383
|
|
|
} |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Sets the topEvent constraint to the given constraints array |
388
|
|
|
* |
389
|
|
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query Query |
390
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand EventDemand |
391
|
|
|
* @param array $constraints Constraints |
392
|
|
|
* |
393
|
|
|
* @return void |
394
|
|
|
*/ |
395
|
|
|
protected function setTopEventConstraint($query, $eventDemand, &$constraints) |
396
|
|
|
{ |
397
|
|
|
if ($eventDemand->getTopEventRestriction() > 0) { |
398
|
|
|
$constraints[] = $query->equals('topEvent', (bool)($eventDemand->getTopEventRestriction() - 1)); |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* Sets the restriction for year, year/month or year/month/day to the given constraints array |
404
|
|
|
* |
405
|
|
|
* @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query |
406
|
|
|
* @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $eventDemand |
407
|
|
|
* @param array $constraints |
408
|
|
|
* |
409
|
|
|
* @return void |
410
|
|
|
*/ |
411
|
|
|
protected function setYearMonthDayRestriction($query, $eventDemand, &$constraints) |
412
|
|
|
{ |
413
|
|
|
if ($eventDemand->getYear() > 0) { |
414
|
|
|
if ($eventDemand->getMonth() > 0) { |
415
|
|
|
if ($eventDemand->getDay() > 0) { |
416
|
|
|
$begin = mktime(0, 0, 0, $eventDemand->getMonth(), $eventDemand->getDay(), $eventDemand->getYear()); |
417
|
|
|
$end = mktime(23, 59, 59, $eventDemand->getMonth(), $eventDemand->getDay(), $eventDemand->getYear()); |
418
|
|
|
} else { |
419
|
|
|
$begin = mktime(0, 0, 0, $eventDemand->getMonth(), 1, $eventDemand->getYear()); |
420
|
|
|
$end = mktime(23, 59, 59, ($eventDemand->getMonth() + 1), 0, $eventDemand->getYear()); |
421
|
|
|
} |
422
|
|
|
} else { |
423
|
|
|
$begin = mktime(0, 0, 0, 1, 1, $eventDemand->getYear()); |
424
|
|
|
$end = mktime(23, 59, 59, 12, 31, $eventDemand->getYear()); |
425
|
|
|
} |
426
|
|
|
$constraints[] = $query->logicalOr([ |
427
|
|
|
$query->between('startdate', $begin, $end), |
428
|
|
|
$query->between('enddate', $begin, $end), |
429
|
|
|
$query->logicalAnd([ |
430
|
|
|
$query->greaterThanOrEqual('enddate', $begin), |
431
|
|
|
$query->lessThanOrEqual('startdate', $begin) |
432
|
|
|
]) |
433
|
|
|
]); |
434
|
|
|
} |
435
|
|
|
} |
436
|
|
|
} |
437
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.