1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DERHANSEN\SfEventMgt\Domain\Repository; |
13
|
|
|
|
14
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Dto\CustomNotification; |
15
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Dto\UserRegistrationDemand; |
16
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Event; |
17
|
|
|
use InvalidArgumentException; |
18
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
19
|
|
|
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings; |
|
|
|
|
20
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryInterface; |
|
|
|
|
21
|
|
|
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; |
|
|
|
|
22
|
|
|
use TYPO3\CMS\Extbase\Persistence\Repository; |
|
|
|
|
23
|
|
|
|
24
|
|
|
class RegistrationRepository extends Repository |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Disable the use of storage records, because the StoragePage can be set |
28
|
|
|
* in the plugin |
29
|
|
|
*/ |
30
|
|
|
public function initializeObject(): void |
31
|
|
|
{ |
32
|
|
|
$this->defaultQuerySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class); |
|
|
|
|
33
|
|
|
$this->defaultQuerySettings->setRespectStoragePage(false); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Returns all registrations for the given event with the given constraints |
38
|
|
|
* Constraints are combined with a logical AND |
39
|
|
|
*/ |
40
|
|
|
public function findNotificationRegistrations( |
41
|
|
|
Event $event, |
42
|
|
|
CustomNotification $customNotification, |
43
|
|
|
array $findConstraints = [] |
44
|
|
|
): QueryResultInterface { |
45
|
|
|
$constraints = []; |
46
|
|
|
$query = $this->createQuery(); |
47
|
|
|
$constraints[] = $query->equals('event', $event); |
48
|
|
|
$constraints[] = $query->equals('ignoreNotifications', false); |
49
|
|
|
|
50
|
|
|
switch ($customNotification->getRecipients()) { |
51
|
|
|
case CustomNotification::RECIPIENTS_CONFIRMED: |
52
|
|
|
$constraints[] = $query->equals('confirmed', true); |
53
|
|
|
$constraints[] = $query->equals('waitlist', false); |
54
|
|
|
break; |
55
|
|
|
case CustomNotification::RECIPIENTS_UNCONFIRMED: |
56
|
|
|
$constraints[] = $query->equals('confirmed', false); |
57
|
|
|
$constraints[] = $query->equals('waitlist', false); |
58
|
|
|
break; |
59
|
|
|
case CustomNotification::RECIPIENTS_WAITLIST_CONFIRMED: |
60
|
|
|
$constraints[] = $query->equals('confirmed', true); |
61
|
|
|
$constraints[] = $query->equals('waitlist', true); |
62
|
|
|
break; |
63
|
|
|
case CustomNotification::RECIPIENTS_WAITLIST_UNCONFIRMED: |
64
|
|
|
$constraints[] = $query->equals('confirmed', false); |
65
|
|
|
$constraints[] = $query->equals('waitlist', true); |
66
|
|
|
break; |
67
|
|
|
default: |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if (!is_array($findConstraints) || count($findConstraints) === 0) { |
|
|
|
|
71
|
|
|
return $query->matching($query->logicalAnd(...$constraints))->execute(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
foreach ($findConstraints as $findConstraint => $value) { |
75
|
|
|
$condition = key($value); |
76
|
|
|
switch ($condition) { |
77
|
|
|
case 'equals': |
78
|
|
|
$constraints[] = $query->equals($findConstraint, $value[$condition]); |
79
|
|
|
break; |
80
|
|
|
case 'lessThan': |
81
|
|
|
$constraints[] = $query->lessThan($findConstraint, $value[$condition]); |
82
|
|
|
break; |
83
|
|
|
case 'lessThanOrEqual': |
84
|
|
|
$constraints[] = $query->lessThanOrEqual($findConstraint, $value[$condition]); |
85
|
|
|
break; |
86
|
|
|
case 'greaterThan': |
87
|
|
|
$constraints[] = $query->greaterThan($findConstraint, $value[$condition]); |
88
|
|
|
break; |
89
|
|
|
case 'greaterThanOrEqual': |
90
|
|
|
$constraints[] = $query->greaterThanOrEqual($findConstraint, $value[$condition]); |
91
|
|
|
break; |
92
|
|
|
default: |
93
|
|
|
throw new InvalidArgumentException('An error occured - Unknown condition: ' . $condition); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $query->matching($query->logicalAnd(...$constraints))->execute(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns registrations for the given UserRegistrationDemand demand |
102
|
|
|
* |
103
|
|
|
* @return array|QueryResultInterface |
104
|
|
|
*/ |
105
|
|
|
public function findRegistrationsByUserRegistrationDemand(UserRegistrationDemand $demand) |
106
|
|
|
{ |
107
|
|
|
if (!$demand->getUser()) { |
108
|
|
|
return []; |
109
|
|
|
} |
110
|
|
|
$constraints = []; |
111
|
|
|
$query = $this->createQuery(); |
112
|
|
|
$this->setStoragePageConstraint($query, $demand, $constraints); |
113
|
|
|
$this->setDisplayModeConstraint($query, $demand, $constraints); |
114
|
|
|
$this->setUserConstraint($query, $demand, $constraints); |
115
|
|
|
$this->setOrderingsFromDemand($query, $demand); |
116
|
|
|
|
117
|
|
|
return $query->matching($query->logicalAnd(...$constraints))->execute(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns all registrations for the given event and where the waitlist flag is as given |
122
|
|
|
*/ |
123
|
|
|
public function findByEventAndWaitlist(Event $event, bool $waitlist = false): QueryResultInterface |
124
|
|
|
{ |
125
|
|
|
$constraints = []; |
126
|
|
|
$query = $this->createQuery(); |
127
|
|
|
$constraints[] = $query->equals('event', $event->getUid()); |
128
|
|
|
$constraints[] = $query->equals('waitlist', $waitlist); |
129
|
|
|
|
130
|
|
|
return $query->matching($query->logicalAnd(...$constraints))->execute(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Returns all potential move up registrations for the given event ordered by "registration_date" |
135
|
|
|
*/ |
136
|
|
|
public function findWaitlistMoveUpRegistrations(Event $event): QueryResultInterface |
137
|
|
|
{ |
138
|
|
|
$constraints = []; |
139
|
|
|
$query = $this->createQuery(); |
140
|
|
|
$constraints[] = $query->equals('event', $event->getUid()); |
141
|
|
|
$constraints[] = $query->equals('waitlist', true); |
142
|
|
|
$constraints[] = $query->equals('confirmed', true); |
143
|
|
|
$constraints[] = $query->greaterThan('registrationDate', 0); |
144
|
|
|
$query->setOrderings(['registration_date' => QueryInterface::ORDER_ASCENDING]); |
145
|
|
|
|
146
|
|
|
return $query->matching($query->logicalAnd(...$constraints))->execute(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Sets the displayMode constraint to the given constraints array |
151
|
|
|
*/ |
152
|
|
|
protected function setDisplayModeConstraint( |
153
|
|
|
QueryInterface $query, |
154
|
|
|
UserRegistrationDemand $demand, |
155
|
|
|
array &$constraints |
156
|
|
|
): void { |
157
|
|
|
switch ($demand->getDisplayMode()) { |
158
|
|
|
case 'future': |
159
|
|
|
$constraints[] = $query->greaterThan('event.startdate', $demand->getCurrentDateTime()); |
160
|
|
|
break; |
161
|
|
|
case 'current_future': |
162
|
|
|
$constraints[] = $query->logicalOr( |
163
|
|
|
$query->greaterThan('event.startdate', $demand->getCurrentDateTime()), |
164
|
|
|
$query->logicalAnd( |
165
|
|
|
$query->greaterThanOrEqual('event.enddate', $demand->getCurrentDateTime()), |
166
|
|
|
$query->lessThanOrEqual('event.startdate', $demand->getCurrentDateTime()), |
167
|
|
|
), |
168
|
|
|
); |
169
|
|
|
break; |
170
|
|
|
case 'past': |
171
|
|
|
$constraints[] = $query->lessThanOrEqual('event.enddate', $demand->getCurrentDateTime()); |
172
|
|
|
break; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Sets the storagePage constraint to the given constraints array |
178
|
|
|
*/ |
179
|
|
|
protected function setStoragePageConstraint( |
180
|
|
|
QueryInterface $query, |
181
|
|
|
UserRegistrationDemand $demand, |
182
|
|
|
array &$constraints |
183
|
|
|
): void { |
184
|
|
|
if ($demand->getStoragePage() !== '') { |
185
|
|
|
$pidList = GeneralUtility::intExplode(',', $demand->getStoragePage(), true); |
186
|
|
|
$constraints[] = $query->in('pid', $pidList); |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Sets the user constraint to the given constraints array |
192
|
|
|
* |
193
|
|
|
* @param QueryInterface $query Query |
194
|
|
|
* @param UserRegistrationDemand $demand |
195
|
|
|
* @param array $constraints Constraints |
196
|
|
|
*/ |
197
|
|
|
protected function setUserConstraint( |
198
|
|
|
QueryInterface $query, |
199
|
|
|
UserRegistrationDemand $demand, |
200
|
|
|
array &$constraints |
201
|
|
|
): void { |
202
|
|
|
if ($demand->getUser()) { |
203
|
|
|
$constraints[] = $query->equals('feUser', $demand->getUser()); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Sets the ordering to the given query for the given demand |
209
|
|
|
*/ |
210
|
|
|
protected function setOrderingsFromDemand(QueryInterface $query, UserRegistrationDemand $demand): void |
211
|
|
|
{ |
212
|
|
|
$orderings = []; |
213
|
|
|
if ($demand->getOrderField() !== '' && $demand->getOrderDirection() !== '') { |
214
|
|
|
$orderings[$demand->getOrderField()] = ((strtolower($demand->getOrderDirection()) === 'desc') ? |
215
|
|
|
QueryInterface::ORDER_DESCENDING : |
216
|
|
|
QueryInterface::ORDER_ASCENDING); |
217
|
|
|
$query->setOrderings($orderings); |
218
|
|
|
} |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths