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