1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Index repository. |
5
|
|
|
*/ |
6
|
|
|
declare(strict_types=1); |
7
|
|
|
|
8
|
|
|
namespace HDNET\Calendarize\Domain\Repository; |
9
|
|
|
|
10
|
|
|
use Exception; |
11
|
|
|
use HDNET\Calendarize\Domain\Model\Index; |
12
|
|
|
use HDNET\Calendarize\Utility\DateTimeUtility; |
13
|
|
|
use HDNET\Calendarize\Utility\ExtensionConfigurationUtility; |
14
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
15
|
|
|
use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager; |
16
|
|
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; |
17
|
|
|
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface; |
18
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
19
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Index repository. |
23
|
|
|
*/ |
24
|
|
|
class IndexRepository extends AbstractRepository |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Default orderings for index records. |
28
|
|
|
* |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $defaultOrderings = [ |
32
|
|
|
'start_date' => QueryInterface::ORDER_ASCENDING, |
33
|
|
|
'start_time' => QueryInterface::ORDER_ASCENDING, |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Index types for selection. |
38
|
|
|
* |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
protected $indexTypes = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Override page ids. |
45
|
|
|
* |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected $overridePageIds = []; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return QueryInterface |
52
|
|
|
*/ |
53
|
|
|
public function createQuery() |
54
|
|
|
{ |
55
|
|
|
$query = parent::createQuery(); |
56
|
|
|
$query->getQuerySettings()->setLanguageMode($this->getIndexLanguageMode()); |
57
|
|
|
|
58
|
|
|
return $query; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Set the index types. |
63
|
|
|
* |
64
|
|
|
* @param array $types |
65
|
|
|
*/ |
66
|
|
|
public function setIndexTypes(array $types) |
67
|
|
|
{ |
68
|
|
|
$this->indexTypes = $types; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Override page IDs. |
73
|
|
|
* |
74
|
|
|
* @param array $overridePageIds |
75
|
|
|
*/ |
76
|
|
|
public function setOverridePageIds($overridePageIds) |
77
|
|
|
{ |
78
|
|
|
$this->overridePageIds = $overridePageIds; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Select indecies for Backend. |
83
|
|
|
* |
84
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
85
|
|
|
*/ |
86
|
|
|
public function findAllForBackend() |
87
|
|
|
{ |
88
|
|
|
$query = $this->createQuery(); |
89
|
|
|
$query->getQuerySettings()->setRespectSysLanguage(false); |
90
|
|
|
|
91
|
|
|
return $query->execute(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Find List. |
96
|
|
|
* |
97
|
|
|
* @param int $limit |
98
|
|
|
* @param int|string $listStartTime |
99
|
|
|
* @param int $startOffsetHours |
100
|
|
|
* @param int $overrideStartDate |
101
|
|
|
* @param int $overrideEndDate |
102
|
|
|
* |
103
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
104
|
|
|
*/ |
105
|
|
|
public function findList( |
106
|
|
|
$limit = 0, |
107
|
|
|
$listStartTime = 0, |
108
|
|
|
$startOffsetHours = 0, |
109
|
|
|
$overrideStartDate = 0, |
110
|
|
|
$overrideEndDate = 0 |
111
|
|
|
) { |
112
|
|
|
if ($overrideStartDate > 0) { |
113
|
|
|
$startTimestamp = $overrideStartDate; |
114
|
|
|
} else { |
115
|
|
|
$now = DateTimeUtility::getNow(); |
116
|
|
|
if ('now' !== $listStartTime) { |
|
|
|
|
117
|
|
|
$now->setTime(0, 0, 0); |
118
|
|
|
} |
119
|
|
|
$now->modify($startOffsetHours . ' hours'); |
120
|
|
|
$startTimestamp = $now->getTimestamp(); |
121
|
|
|
} |
122
|
|
|
$endTimestamp = null; |
123
|
|
|
if ($overrideEndDate > 0) { |
124
|
|
|
$endTimestamp = $overrideEndDate; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
$result = $this->findByTimeSlot($startTimestamp, $endTimestamp); |
128
|
|
|
if ($limit > 0) { |
129
|
|
|
$query = $result->getQuery(); |
130
|
|
|
$query->setLimit($limit); |
131
|
|
|
$result = $query->execute(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $result; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Find by custom search. |
139
|
|
|
* |
140
|
|
|
* @param \DateTime $startDate |
141
|
|
|
* @param \DateTime $endDate |
142
|
|
|
* @param array $customSearch |
143
|
|
|
* @param int $limit |
144
|
|
|
* |
145
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
146
|
|
|
*/ |
147
|
|
|
public function findBySearch(\DateTime $startDate = null, \DateTime $endDate = null, array $customSearch = [], int $limit = 0) |
148
|
|
|
{ |
149
|
|
|
$arguments = [ |
150
|
|
|
'indexIds' => [], |
151
|
|
|
'startDate' => $startDate, |
152
|
|
|
'endDate' => $endDate, |
153
|
|
|
'customSearch' => $customSearch, |
154
|
|
|
'indexTypes' => $this->indexTypes, |
155
|
|
|
'emptyPreResult' => false, |
156
|
|
|
]; |
157
|
|
|
$arguments = $this->callSignal(__CLASS__, __FUNCTION__ . 'Pre', $arguments); |
158
|
|
|
|
159
|
|
|
$query = $this->createQuery(); |
160
|
|
|
$constraints = $this->getDefaultConstraints($query); |
161
|
|
|
|
162
|
|
|
if ($limit > 0) { |
163
|
|
|
$query->setLimit($limit); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
$this->addTimeFrameConstraints( |
167
|
|
|
$constraints, |
168
|
|
|
$query, |
169
|
|
|
$arguments['startDate'] instanceof \DateTime ? DateTimeUtility::getDayStart($arguments['startDate']) : null, |
|
|
|
|
170
|
|
|
$arguments['endDate'] instanceof \DateTime ? DateTimeUtility::getDayEnd($arguments['endDate']) : null |
|
|
|
|
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
if ($arguments['indexIds']) { |
174
|
|
|
$constraints[] = $query->in('foreign_uid', $arguments['indexIds']); |
175
|
|
|
} |
176
|
|
|
if ($arguments['emptyPreResult']) { |
177
|
|
|
$constraints[] = $query->equals('uid', '-1'); |
178
|
|
|
} |
179
|
|
|
$result = [ |
180
|
|
|
'result' => $this->matchAndExecute($query, $constraints), |
181
|
|
|
]; |
182
|
|
|
|
183
|
|
|
$result = $this->callSignal(__CLASS__, __FUNCTION__ . 'Post', $result); |
184
|
|
|
|
185
|
|
|
return $result['result']; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Find Past Events. |
190
|
|
|
* |
191
|
|
|
* @param int $limit |
192
|
|
|
* @param string $sort |
193
|
|
|
* |
194
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
195
|
|
|
*/ |
196
|
|
|
public function findByPast( |
197
|
|
|
$limit, |
198
|
|
|
$sort |
199
|
|
|
) { |
200
|
|
|
//create Query |
201
|
|
|
$query = $this->createQuery(); |
202
|
|
|
//Get actual datetime |
203
|
|
|
$now = DateTimeUtility::getNow()->getTimestamp(); |
204
|
|
|
|
205
|
|
|
$constraints = $this->getDefaultConstraints($query); |
206
|
|
|
$constraints[] = $query->lessThanOrEqual('startDate', $now); |
207
|
|
|
$sort = QueryInterface::ORDER_ASCENDING === $sort ? QueryInterface::ORDER_ASCENDING : QueryInterface::ORDER_DESCENDING; |
208
|
|
|
$query->setOrderings($this->getSorting($sort)); |
209
|
|
|
$query->setLimit($limit); |
210
|
|
|
|
211
|
|
|
return $this->matchAndExecute($query, $constraints); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* Find by traversing information. |
216
|
|
|
* |
217
|
|
|
* @param Index $index |
218
|
|
|
* @param bool|true $future |
219
|
|
|
* @param bool|false $past |
220
|
|
|
* @param int $limit |
221
|
|
|
* @param string $sort |
222
|
|
|
* @param bool $useIndexTime |
223
|
|
|
* |
224
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
225
|
|
|
*/ |
226
|
|
|
public function findByTraversing( |
227
|
|
|
Index $index, |
228
|
|
|
$future = true, |
229
|
|
|
$past = false, |
230
|
|
|
$limit = 100, |
231
|
|
|
$sort = QueryInterface::ORDER_ASCENDING, |
232
|
|
|
$useIndexTime = false |
233
|
|
|
) { |
234
|
|
|
if (!$future && !$past) { |
235
|
|
|
return []; |
236
|
|
|
} |
237
|
|
|
$query = $this->createQuery(); |
238
|
|
|
|
239
|
|
|
$now = DateTimeUtility::getNow() |
240
|
|
|
->getTimestamp(); |
241
|
|
|
if ($useIndexTime) { |
242
|
|
|
$now = $index->getStartDate()->getTimestamp(); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
$constraints = []; |
246
|
|
|
$constraints[] = $query->logicalNot($query->equals('uid', $index->getUid())); |
247
|
|
|
$constraints[] = $query->equals('foreignTable', $index->getForeignTable()); |
248
|
|
|
$constraints[] = $query->equals('foreignUid', $index->getForeignUid()); |
249
|
|
|
if (!$future) { |
250
|
|
|
$constraints[] = $query->lessThanOrEqual('startDate', $now); |
251
|
|
|
} |
252
|
|
|
if (!$past) { |
253
|
|
|
$constraints[] = $query->greaterThanOrEqual('startDate', $now); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
$query->setLimit($limit); |
257
|
|
|
$sort = QueryInterface::ORDER_ASCENDING === $sort ? QueryInterface::ORDER_ASCENDING : QueryInterface::ORDER_DESCENDING; |
258
|
|
|
$query->setOrderings($this->getSorting($sort)); |
259
|
|
|
|
260
|
|
|
return $this->matchAndExecute($query, $constraints); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* Find by traversing information. |
265
|
|
|
* |
266
|
|
|
* @param DomainObjectInterface $event |
267
|
|
|
* @param bool|true $future |
268
|
|
|
* @param bool|false $past |
269
|
|
|
* @param int $limit |
270
|
|
|
* @param string $sort |
271
|
|
|
* |
272
|
|
|
* @throws Exception |
273
|
|
|
* |
274
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
275
|
|
|
*/ |
276
|
|
|
public function findByEventTraversing( |
277
|
|
|
DomainObjectInterface $event, |
278
|
|
|
$future = true, |
279
|
|
|
$past = false, |
280
|
|
|
$limit = 100, |
281
|
|
|
$sort = QueryInterface::ORDER_ASCENDING |
282
|
|
|
) { |
283
|
|
|
if (!$future && !$past) { |
284
|
|
|
return []; |
285
|
|
|
} |
286
|
|
|
$query = $this->createQuery(); |
287
|
|
|
|
288
|
|
|
$uniqueRegisterKey = ExtensionConfigurationUtility::getUniqueRegisterKeyForModel($event); |
289
|
|
|
|
290
|
|
|
$this->setIndexTypes([$uniqueRegisterKey]); |
291
|
|
|
|
292
|
|
|
$now = DateTimeUtility::getNow() |
293
|
|
|
->getTimestamp(); |
294
|
|
|
|
295
|
|
|
$constraints = []; |
296
|
|
|
|
297
|
|
|
$constraints[] = $query->equals('foreignUid', $event->getUid()); |
298
|
|
|
$constraints[] = $query->in('uniqueRegisterKey', $this->indexTypes); |
299
|
|
|
if (!$future) { |
300
|
|
|
$constraints[] = $query->lessThanOrEqual('startDate', $now); |
301
|
|
|
} |
302
|
|
|
if (!$past) { |
303
|
|
|
$constraints[] = $query->greaterThanOrEqual('startDate', $now); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
$query->setLimit($limit); |
307
|
|
|
$sort = QueryInterface::ORDER_ASCENDING === $sort ? QueryInterface::ORDER_ASCENDING : QueryInterface::ORDER_DESCENDING; |
308
|
|
|
$query->setOrderings($this->getSorting($sort)); |
309
|
|
|
|
310
|
|
|
return $this->matchAndExecute($query, $constraints); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* find Year. |
315
|
|
|
* |
316
|
|
|
* @param int $year |
317
|
|
|
* |
318
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
319
|
|
|
*/ |
320
|
|
|
public function findYear(int $year) |
321
|
|
|
{ |
322
|
|
|
return $this->findByTimeSlot(\mktime(0, 0, 0, 1, 1, $year), \mktime(0, 0, 0, 1, 1, $year + 1) - 1); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* find quarter. |
327
|
|
|
* |
328
|
|
|
* @param int $year |
329
|
|
|
* @param int $quarter |
330
|
|
|
* |
331
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
332
|
|
|
*/ |
333
|
|
|
public function findQuarter(int $year, int $quarter) |
334
|
|
|
{ |
335
|
|
|
$startMonth = 1 + (3 * ($quarter - 1)); |
336
|
|
|
|
337
|
|
|
return $this->findByTimeSlot(\mktime(0, 0, 0, $startMonth, 1, $year), \mktime(0, 0, 0, $startMonth + 3, 1, $year) - 1); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* find Month. |
342
|
|
|
* |
343
|
|
|
* @param int $year |
344
|
|
|
* @param int $month |
345
|
|
|
* |
346
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
347
|
|
|
*/ |
348
|
|
|
public function findMonth(int $year, int $month) |
349
|
|
|
{ |
350
|
|
|
$startTime = \mktime(0, 0, 0, $month, 1, $year); |
351
|
|
|
$endTime = \mktime(0, 0, 0, $month + 1, 1, $year) - 1; |
352
|
|
|
|
353
|
|
|
return $this->findByTimeSlot($startTime, $endTime); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* find Week. |
358
|
|
|
* |
359
|
|
|
* @param int $year |
360
|
|
|
* @param int $week |
361
|
|
|
* @param int $weekStart See documentation for settings.weekStart |
362
|
|
|
* |
363
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
364
|
|
|
*/ |
365
|
|
|
public function findWeek($year, $week, $weekStart = 1) |
366
|
|
|
{ |
367
|
|
|
$weekStart = (int) $weekStart; |
368
|
|
|
$daysShift = $weekStart - 1; |
369
|
|
|
$firstDay = DateTimeUtility::convertWeekYear2DayMonthYear($week, $year); |
370
|
|
|
$timezone = DateTimeUtility::getTimeZone(); |
371
|
|
|
$firstDay->setTimezone($timezone); |
372
|
|
|
if ($daysShift !== 0) { |
373
|
|
|
$firstDay->modify('+' . $daysShift . ' days'); |
374
|
|
|
} |
375
|
|
|
$endDate = clone $firstDay; |
376
|
|
|
$endDate->modify('+1 week'); |
377
|
|
|
$endDate->modify('-1 second'); |
378
|
|
|
|
379
|
|
|
return $this->findByTimeSlot($firstDay->getTimestamp(), $endDate->getTimestamp()); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Find different types and locations. |
384
|
|
|
* |
385
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
386
|
|
|
*/ |
387
|
|
|
public function findDifferentTypesAndLocations() |
388
|
|
|
{ |
389
|
|
|
$query = $this->createQuery(); |
390
|
|
|
|
391
|
|
|
return $query |
|
|
|
|
392
|
|
|
->statement('SELECT *' |
393
|
|
|
. 'FROM tx_calendarize_domain_model_index ' |
394
|
|
|
. 'GROUP BY pid,foreign_table') |
395
|
|
|
->execute(); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* find day. |
400
|
|
|
* |
401
|
|
|
* @param int $year |
402
|
|
|
* @param int $month |
403
|
|
|
* @param int $day |
404
|
|
|
* |
405
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
406
|
|
|
* @throws Exception |
407
|
|
|
*/ |
408
|
|
|
public function findDay(int $year, int $month, int $day) |
409
|
|
|
{ |
410
|
|
|
$startTime = \mktime(0, 0, 0, $month, $day, $year); |
411
|
|
|
$startDate = new \DateTime('@' . $startTime); |
412
|
|
|
$endDate = clone $startDate; |
413
|
|
|
$endDate->modify('+1 day'); |
414
|
|
|
$endDate->modify('-1 second'); |
415
|
|
|
|
416
|
|
|
return $this->findByTimeSlot($startDate->getTimestamp(), $endDate->getTimestamp()); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* Set the default sorting direction. |
421
|
|
|
* |
422
|
|
|
* @param string $direction |
423
|
|
|
* @param string $field |
424
|
|
|
*/ |
425
|
|
|
public function setDefaultSortingDirection($direction, $field = '') |
426
|
|
|
{ |
427
|
|
|
$this->defaultOrderings = $this->getSorting($direction, $field); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* Find by time slot. |
432
|
|
|
* |
433
|
|
|
* @param int $startTime |
434
|
|
|
* @param int|null $endTime null means open end |
435
|
|
|
* |
436
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
437
|
|
|
*/ |
438
|
|
|
public function findByTimeSlot($startTime, $endTime = null) |
439
|
|
|
{ |
440
|
|
|
$query = $this->createQuery(); |
441
|
|
|
$constraints = $this->getDefaultConstraints($query); |
442
|
|
|
$this->addTimeFrameConstraints($constraints, $query, $startTime, $endTime); |
443
|
|
|
|
444
|
|
|
return $this->matchAndExecute($query, $constraints); |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
/** |
448
|
|
|
* Find all indices by the given Event model. |
449
|
|
|
* |
450
|
|
|
* @param DomainObjectInterface $event |
451
|
|
|
* |
452
|
|
|
* @throws Exception |
453
|
|
|
* |
454
|
|
|
* @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface |
455
|
|
|
*/ |
456
|
|
|
public function findByEvent(DomainObjectInterface $event) |
457
|
|
|
{ |
458
|
|
|
$query = $this->createQuery(); |
459
|
|
|
|
460
|
|
|
$uniqueRegisterKey = ExtensionConfigurationUtility::getUniqueRegisterKeyForModel($event); |
461
|
|
|
|
462
|
|
|
$this->setIndexTypes([$uniqueRegisterKey]); |
463
|
|
|
$constraints = $this->getDefaultConstraints($query); |
464
|
|
|
$constraints[] = $query->equals('foreignUid', $event->getUid()); |
465
|
|
|
$query->matching($query->logicalAnd($constraints)); |
466
|
|
|
|
467
|
|
|
return $query->execute(); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* Get index language mode. |
472
|
|
|
* |
473
|
|
|
* @return string |
474
|
|
|
*/ |
475
|
|
|
protected function getIndexLanguageMode() |
476
|
|
|
{ |
477
|
|
|
static $mode; |
478
|
|
|
if (null !== $mode) { |
479
|
|
|
return $mode; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
$objectManager = new ObjectManager(); |
483
|
|
|
/** @var ConfigurationManagerInterface $config */ |
484
|
|
|
$config = $objectManager->get(ConfigurationManagerInterface::class); |
485
|
|
|
$pluginConfig = $config->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS); |
486
|
|
|
|
487
|
|
|
$mode = isset($pluginConfig['indexLanguageMode']) ? (string) $pluginConfig['indexLanguageMode'] : 'strict'; |
488
|
|
|
|
489
|
|
|
return $mode; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
/** |
493
|
|
|
* storage page selection. |
494
|
|
|
* |
495
|
|
|
* @return array |
496
|
|
|
*/ |
497
|
|
|
protected function getStoragePageIds() |
498
|
|
|
{ |
499
|
|
|
if (!empty($this->overridePageIds)) { |
500
|
|
|
return $this->overridePageIds; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
$configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class); |
504
|
|
|
$frameworkConfig = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); |
505
|
|
|
$storagePages = isset($frameworkConfig['persistence']['storagePid']) ? GeneralUtility::intExplode( |
506
|
|
|
',', |
507
|
|
|
$frameworkConfig['persistence']['storagePid'] |
508
|
|
|
) : []; |
509
|
|
|
if (!empty($storagePages)) { |
510
|
|
|
return $storagePages; |
511
|
|
|
} |
512
|
|
|
if ($frameworkConfig instanceof BackendConfigurationManager) { |
513
|
|
|
return GeneralUtility::trimExplode(',', $frameworkConfig->getDefaultBackendStoragePid(), true); |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
return $storagePages; |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Get the default constraint for the queries. |
521
|
|
|
* |
522
|
|
|
* @param QueryInterface $query |
523
|
|
|
* |
524
|
|
|
* @return array |
525
|
|
|
*/ |
526
|
|
|
protected function getDefaultConstraints(QueryInterface $query) |
527
|
|
|
{ |
528
|
|
|
$constraints = []; |
529
|
|
|
if (!empty($this->indexTypes)) { |
530
|
|
|
$indexTypes = $this->indexTypes; |
531
|
|
|
$constraints[] = $query->in('uniqueRegisterKey', $indexTypes); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
$storagePages = $this->getStoragePageIds(); |
535
|
|
|
if (!empty($storagePages)) { |
536
|
|
|
$constraints[] = $query->in('pid', $storagePages); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
$arguments = [ |
540
|
|
|
'indexIds' => [], |
541
|
|
|
'indexTypes' => $this->indexTypes, |
542
|
|
|
]; |
543
|
|
|
$arguments = $this->callSignal(__CLASS__, __FUNCTION__, $arguments); |
544
|
|
|
|
545
|
|
|
if ($arguments['indexIds']) { |
546
|
|
|
$constraints[] = $query->in('foreign_uid', $arguments['indexIds']); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
return $constraints; |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
/** |
553
|
|
|
* Add time frame related queries. |
554
|
|
|
* |
555
|
|
|
* @param array $constraints |
556
|
|
|
* @param QueryInterface $query |
557
|
|
|
* @param int $startTime |
558
|
|
|
* @param int|null $endTime |
559
|
|
|
* |
560
|
|
|
* @see IndexUtility::isIndexInRange |
561
|
|
|
*/ |
562
|
|
|
protected function addTimeFrameConstraints(&$constraints, QueryInterface $query, $startTime = null, $endTime = null) |
563
|
|
|
{ |
564
|
|
|
$arguments = [ |
565
|
|
|
'constraints' => &$constraints, |
566
|
|
|
'query' => $query, |
567
|
|
|
'startTime' => $startTime, |
568
|
|
|
'endTime' => $endTime, |
569
|
|
|
]; |
570
|
|
|
$arguments = $this->callSignal(__CLASS__, __FUNCTION__, $arguments); |
571
|
|
|
|
572
|
|
|
if (null === $arguments['startTime'] && null === $arguments['endTime']) { |
573
|
|
|
return; |
574
|
|
|
} |
575
|
|
|
if (null === $arguments['startTime']) { |
576
|
|
|
// Simulate start time |
577
|
|
|
$arguments['startTime'] = DateTimeUtility::getNow()->getTimestamp() - DateTimeUtility::SECONDS_DECADE; |
578
|
|
|
} elseif (null === $arguments['endTime']) { |
579
|
|
|
// Simulate end time |
580
|
|
|
$arguments['endTime'] = DateTimeUtility::getNow()->getTimestamp() + DateTimeUtility::SECONDS_DECADE; |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
$orConstraint = []; |
584
|
|
|
|
585
|
|
|
// before - in |
586
|
|
|
$beforeIn = [ |
587
|
|
|
$query->lessThan('start_date', $arguments['startTime']), |
588
|
|
|
$query->greaterThanOrEqual('end_date', $arguments['startTime']), |
589
|
|
|
$query->lessThan('end_date', $arguments['endTime']), |
590
|
|
|
]; |
591
|
|
|
$orConstraint[] = $query->logicalAnd($beforeIn); |
592
|
|
|
|
593
|
|
|
// in - in |
594
|
|
|
$inIn = [ |
595
|
|
|
$query->greaterThanOrEqual('start_date', $arguments['startTime']), |
596
|
|
|
$query->lessThan('end_date', $arguments['endTime']), |
597
|
|
|
]; |
598
|
|
|
$orConstraint[] = $query->logicalAnd($inIn); |
599
|
|
|
|
600
|
|
|
// in - after |
601
|
|
|
$inAfter = [ |
602
|
|
|
$query->greaterThanOrEqual('start_date', $arguments['startTime']), |
603
|
|
|
$query->lessThan('start_date', $arguments['endTime']), |
604
|
|
|
$query->greaterThanOrEqual('end_date', $arguments['endTime']), |
605
|
|
|
]; |
606
|
|
|
$orConstraint[] = $query->logicalAnd($inAfter); |
607
|
|
|
|
608
|
|
|
// before - after |
609
|
|
|
$beforeAfter = [ |
610
|
|
|
$query->lessThan('start_date', $arguments['startTime']), |
611
|
|
|
$query->greaterThan('end_date', $arguments['endTime']), |
612
|
|
|
]; |
613
|
|
|
$orConstraint[] = $query->logicalAnd($beforeAfter); |
614
|
|
|
|
615
|
|
|
// finish |
616
|
|
|
$constraints[] = $query->logicalOr($orConstraint); |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* Get the sorting. |
621
|
|
|
* |
622
|
|
|
* @param string $direction |
623
|
|
|
* @param string $field |
624
|
|
|
* |
625
|
|
|
* @return array |
626
|
|
|
*/ |
627
|
|
|
protected function getSorting($direction, $field = '') |
628
|
|
|
{ |
629
|
|
|
if ($field === 'withrangelast') { |
630
|
|
|
return [ |
631
|
|
|
'end_date' => $direction, |
632
|
|
|
'start_date' => $direction, |
633
|
|
|
'start_time' => $direction, |
634
|
|
|
]; |
635
|
|
|
} |
636
|
|
|
if ('end' !== $field) { |
637
|
|
|
$field = 'start'; |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
return [ |
641
|
|
|
$field . '_date' => $direction, |
642
|
|
|
$field . '_time' => $direction, |
643
|
|
|
]; |
644
|
|
|
} |
645
|
|
|
} |
646
|
|
|
|