Passed
Push — master ( 2ae1cd...0d18d8 )
by Torben
03:56
created

Event::getRegistrationPossible()   C

Complexity

Conditions 12
Paths 48

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 12

Importance

Changes 0
Metric Value
cc 12
eloc 12
nc 48
nop 0
dl 0
loc 18
ccs 4
cts 4
cp 1
crap 12
rs 6.9666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Model;
13
14
use DateTime;
15
use DERHANSEN\SfEventMgt\Domain\Model\Registration\Field;
16
use DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository;
17
use DERHANSEN\SfEventMgt\Utility\MiscUtility;
18
use DERHANSEN\SfEventMgt\Utility\ShowInPreviews;
19
use TYPO3\CMS\Core\Context\Context;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
use TYPO3\CMS\Extbase\Annotation as Extbase;
22
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
23
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
24
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
25
26
/**
27
 * Event
28
 */
29
class Event extends AbstractEntity
30
{
31
    protected ?DateTime $tstamp = null;
32
    protected bool $hidden = false;
33
    protected ?DateTime $starttime = null;
34
    protected ?DateTime $endtime = null;
35
    protected string $title = '';
36
    protected string $teaser = '';
37
    protected string $description = '';
38
    protected string $program = '';
39
    protected string $customText = '';
40
    protected ?DateTime $startdate = null;
41
    protected ?DateTime $enddate = null;
42
    protected int $maxParticipants = 0;
43
    protected int $maxRegistrationsPerUser = 1;
44
    protected float $price = 0.0;
45
    protected string $currency = '';
46
    protected bool $enablePayment = false;
47
    protected bool $restrictPaymentMethods = false;
48
    protected string $selectedPaymentMethods = '';
49
    protected ?DateTime $registrationStartdate = null;
50
    protected ?DateTime $registrationDeadline = null;
51
    protected ?Location $location = null;
52
    protected string $room = '';
53
    protected bool $enableRegistration = false;
54
    protected bool $enableWaitlist = false;
55
    protected bool $enableWaitlistMoveup = false;
56
    protected string $link = '';
57
    protected bool $topEvent = false;
58
    protected ?Organisator $organisator = null;
59
    protected bool $notifyAdmin = true;
60
    protected bool $notifyOrganisator = false;
61
    protected bool $enableCancel = false;
62
    protected ?DateTime $cancelDeadline = null;
63
    protected bool $enableAutoconfirm = false;
64
    protected bool $uniqueEmailCheck = false;
65
66
    /**
67
     * @var ObjectStorage<Category>
68
     * @Extbase\ORM\Lazy
69
     */
70
    protected ObjectStorage $category;
71
72
    /**
73
     * @var ObjectStorage<Event>
74
     * @Extbase\ORM\Lazy
75
     */
76
    protected ObjectStorage $related;
77
78
    /**
79
     * @var ObjectStorage<Registration>
80
     * @Extbase\ORM\Cascade("remove")
81
     * @Extbase\ORM\Lazy
82
     */
83
    protected ObjectStorage $registration;
84
85
    /**
86
     * @var ObjectStorage<Registration>
87
     * @Extbase\ORM\Lazy
88
     */
89
    protected ObjectStorage $registrationWaitlist;
90
91
    /**
92
     * @var ObjectStorage<Field>
93
     * @Extbase\ORM\Lazy
94
     */
95
    protected ObjectStorage $registrationFields;
96
97
    /**
98
     * @var ObjectStorage<FileReference>
99
     * @Extbase\ORM\Lazy
100
     */
101
    protected ObjectStorage $image;
102
103
    /**
104
     * @var ObjectStorage<FileReference>
105
     * @Extbase\ORM\Lazy
106
     */
107
    protected ObjectStorage $files;
108
109
    /**
110
     * @var ObjectStorage<FileReference>
111
     * @Extbase\ORM\Lazy
112
     */
113
    protected ObjectStorage $additionalImage;
114
115
    /**
116
     * @var ObjectStorage<PriceOption>
117
     * @Extbase\ORM\Cascade("remove")
118
     * @Extbase\ORM\Lazy
119
     */
120
    protected ObjectStorage $priceOptions;
121
122
    /**
123
     * @var ObjectStorage<Speaker>
124
     * @Extbase\ORM\Lazy
125
     */
126
    protected ObjectStorage $speaker;
127
128
    public function __construct()
129
    {
130
        $this->initializeObject();
131
    }
132
133
    /**
134
     * Initialize all ObjectStorages as fetching an entity from the DB does not use the constructor
135
     */
136
    public function initializeObject()
137
    {
138
        $this->category = new ObjectStorage();
139
        $this->related = new ObjectStorage();
140
        $this->registration = new ObjectStorage();
141
        $this->registrationWaitlist = new ObjectStorage();
142
        $this->registrationFields = new ObjectStorage();
143
        $this->image = new ObjectStorage();
144
        $this->files = new ObjectStorage();
145
        $this->additionalImage = new ObjectStorage();
146
        $this->priceOptions = new ObjectStorage();
147
        $this->speaker = new ObjectStorage();
148
    }
149
150
    public function getTstamp(): ?DateTime
151
    {
152
        return $this->tstamp;
153
    }
154
155
    public function setTstamp(?DateTime $tstamp)
156
    {
157
        $this->tstamp = $tstamp;
158
    }
159
160
    public function getHidden(): bool
161
    {
162
        return $this->hidden;
163
    }
164
165
    public function setHidden(bool $hidden)
166
    {
167
        $this->hidden = $hidden;
168
    }
169
170
    public function getStarttime(): ?DateTime
171
    {
172
        return $this->starttime;
173
    }
174
175
    public function setStarttime(?DateTime $starttime)
176
    {
177
        $this->starttime = $starttime;
178
    }
179
180
    public function getEndtime(): ?DateTime
181
    {
182
        return $this->endtime;
183
    }
184
185
    public function setEndtime(?DateTime $endtime)
186
    {
187
        $this->endtime = $endtime;
188
    }
189
190
    public function getTitle(): string
191
    {
192
        return $this->title;
193
    }
194
195
    public function setTitle(string $title)
196
    {
197
        $this->title = $title;
198
    }
199
200
    public function getTeaser(): string
201
    {
202
        return $this->teaser;
203
    }
204
205
    public function setTeaser(string $teaser)
206
    {
207
        $this->teaser = $teaser;
208
    }
209
210
    public function getDescription(): string
211
    {
212
        return $this->description;
213
    }
214
215
    public function setDescription(string $description)
216
    {
217
        $this->description = $description;
218
    }
219
220
    public function getProgram(): string
221
    {
222
        return $this->program;
223
    }
224
225
    public function setProgram(string $program)
226
    {
227
        $this->program = $program;
228
    }
229
230
    public function getCustomText(): string
231
    {
232
        return $this->customText;
233
    }
234
235
    public function setCustomText(string $customText): void
236
    {
237
        $this->customText = $customText;
238
    }
239
240
    public function getStartdate(): ?DateTime
241
    {
242
        return $this->startdate;
243
    }
244
245
    public function setStartdate(?DateTime $startdate)
246
    {
247
        $this->startdate = $startdate;
248
    }
249
250
    public function getEnddate(): ?DateTime
251
    {
252
        return $this->enddate;
253
    }
254
255
    public function setEnddate(?DateTime $enddate)
256
    {
257
        $this->enddate = $enddate;
258
    }
259
260
    public function getMaxParticipants(): int
261
    {
262
        return $this->maxParticipants;
263
    }
264
265
    public function setMaxParticipants(int $participants)
266
    {
267
        $this->maxParticipants = $participants;
268
    }
269
270
    public function getPrice(): float
271
    {
272
        return $this->price;
273
    }
274
275
    public function setPrice(float $price)
276
    {
277 362
        $this->price = $price;
278
    }
279 362
280 362
    public function getCurrency(): string
281 362
    {
282 362
        return $this->currency;
283 362
    }
284 362
285 362
    public function setCurrency(string $currency)
286 362
    {
287 362
        $this->currency = $currency;
288
    }
289
290
    public function getEnablePayment(): bool
291
    {
292
        return $this->enablePayment;
293
    }
294 10
295
    public function setEnablePayment(bool $enablePayment)
296 10
    {
297
        $this->enablePayment = $enablePayment;
298
    }
299
300
    public function getRestrictPaymentMethods(): bool
301
    {
302
        return $this->restrictPaymentMethods;
303
    }
304
305
    public function setRestrictPaymentMethods(bool $restrictPaymentMethods)
306 2
    {
307
        $this->restrictPaymentMethods = $restrictPaymentMethods;
308 2
    }
309 2
310
    public function getSelectedPaymentMethods(): string
311
    {
312
        return $this->selectedPaymentMethods;
313
    }
314
315
    public function setSelectedPaymentMethods(string $selectedPaymentMethods)
316 2
    {
317
        $this->selectedPaymentMethods = $selectedPaymentMethods;
318 2
    }
319
320
    public function addCategory(Category $category)
321
    {
322
        $this->category->attach($category);
323
    }
324
325
    public function removeCategory(Category $categoryToRemove)
326
    {
327
        $this->category->detach($categoryToRemove);
328 2
    }
329
330 2
    public function getCategory(): ?ObjectStorage
331 2
    {
332
        return $this->category;
333
    }
334
335
    public function getCategories(): ?ObjectStorage
336
    {
337
        return $this->category;
338 2
    }
339
340 2
    public function setCategory(?ObjectStorage $category)
341
    {
342
        $this->category = $category;
343
    }
344
345
    public function getRelated(): ?ObjectStorage
346
    {
347
        return $this->related;
348
    }
349
350 2
    public function setRelated(?ObjectStorage $related)
351
    {
352 2
        $this->related = $related;
353 2
    }
354
355
    public function addRelated(Event $event)
356
    {
357
        $this->related->attach($event);
358
    }
359
360 2
    public function removeRelated(Event $event)
361
    {
362 2
        $this->related->detach($event);
363
    }
364
365
    public function addRegistration(Registration $registration)
366
    {
367
        $this->registration->attach($registration);
368
    }
369
370
    public function removeRegistration(Registration $registrationToRemove)
371
    {
372 2
        $this->registration->detach($registrationToRemove);
373
    }
374 2
375 2
    public function getRegistration(): ?ObjectStorage
376
    {
377
        return $this->registration;
378
    }
379
380
    public function setRegistration(?ObjectStorage $registration)
381
    {
382 22
        $this->registration = $registration;
383
    }
384 22
385
    public function addImage(FileReference $image)
386
    {
387
        $this->image->attach($image);
388
    }
389
390
    public function removeImage(FileReference $imageToRemove)
391
    {
392
        $this->image->detach($imageToRemove);
393
    }
394 22
395
    public function getImage(): ?ObjectStorage
396 22
    {
397 22
        return $this->image;
398
    }
399
400
    public function getImages(): ?ObjectStorage
401
    {
402
        return $this->image;
403
    }
404 2
405
    public function getListViewImages(): ?ObjectStorage
406 2
    {
407
        return $this->getImagesByType(ShowInPreviews::LIST_VIEWS);
408
    }
409
410
    public function getFirstListViewImage(): ?FileReference
411
    {
412
        $images = $this->getImagesByType(ShowInPreviews::LIST_VIEWS);
413
        $image = $images->current();
414
415
        if (is_a($image, FileReference::class)) {
416 2
            return $image;
417
        }
418 2
        return null;
419 2
    }
420
421
    public function getDetailViewImages(): ?ObjectStorage
422
    {
423
        return $this->getImagesByType(ShowInPreviews::DETAIL_VIEWS);
424
    }
425
426 28
    public function getFirstDetailViewImage(): ?FileReference
427
    {
428 28
        $images = $this->getImagesByType(ShowInPreviews::DETAIL_VIEWS);
429
        $image = $images->current();
430
431
        if (is_a($image, FileReference::class)) {
432
            return $image;
433
        }
434
        return null;
435
    }
436
437
    protected function getImagesByType(int $type): ?ObjectStorage
438 26
    {
439
        $result = new ObjectStorage();
440 26
441 26
        foreach ($this->image as $image) {
442
            /** @var \TYPO3\CMS\Core\Resource\FileReference $fileReference */
443
            $fileReference = $image->getOriginalResource();
444
            if ($fileReference !== null && $fileReference->hasProperty('show_in_views') &&
445
                in_array($fileReference->getProperty('show_in_views'), [$type, ShowInPreviews::ALL_VIEWS])
446
            ) {
447
                $result->attach($image);
448 2
            }
449
        }
450 2
451
        return $result;
452
    }
453
454
    public function setImage(?ObjectStorage $image)
455
    {
456
        $this->image = $image;
457
    }
458
459
    public function addFiles(FileReference $file)
460 6
    {
461
        $this->files->attach($file);
462 6
    }
463 6
464
    public function removeFiles(FileReference $fileToRemove)
465
    {
466
        $this->files->detach($fileToRemove);
467
    }
468
469
    public function getFiles(): ?ObjectStorage
470 2
    {
471
        return $this->files;
472 2
    }
473
474
    public function setFiles(?ObjectStorage $files)
475
    {
476
        $this->files = $files;
477
    }
478
479
    /**
480
     * Returns if the registration for this event is logically possible
481
     *
482 2
     * @return bool
483
     */
484 2
    public function getRegistrationPossible(): bool
485 2
    {
486
        $maxParticipantsNotReached = true;
487
        if ($this->getMaxParticipants() > 0 && $this->getRegistrations()->count() >= $this->maxParticipants) {
488
            $maxParticipantsNotReached = false;
489
        }
490
        $deadlineNotReached = true;
491
        if ($this->getRegistrationDeadline() != null && $this->getRegistrationDeadline() <= new DateTime()) {
492 8
            $deadlineNotReached = false;
493
        }
494 8
        $registrationStartReached = true;
495
        if ($this->getRegistrationStartdate() != null && $this->getRegistrationStartdate() > new DateTime()) {
496
            $registrationStartReached = false;
497
        }
498
499
        return ($this->getStartdate() > new DateTime()) &&
500
        ($maxParticipantsNotReached || $this->enableWaitlist) &&
501
        $this->getEnableRegistration() && $deadlineNotReached && $registrationStartReached;
502
    }
503 6
504
    /**
505 6
     * Returns the amount of free places
506 6
     *
507
     * @return int
508
     */
509
    public function getFreePlaces(): int
510
    {
511
        return $this->maxParticipants - $this->getRegistrations()->count();
512
    }
513 6
514
    public function setLocation(?Location $location)
515 6
    {
516
        $this->location = $location;
517
    }
518
519
    public function getLocation(): ?Location
520
    {
521
        return $this->location;
522
    }
523
524 2
    public function getRoom(): string
525
    {
526 2
        return $this->room;
527 2
    }
528
529
    public function setRoom(string $room)
530
    {
531
        $this->room = $room;
532
    }
533
534 4
    public function setEnableRegistration(bool $enableRegistration)
535
    {
536 4
        $this->enableRegistration = $enableRegistration;
537
    }
538
539
    public function getEnableRegistration(): bool
540
    {
541
        return $this->enableRegistration;
542
    }
543
544
    public function getEnableWaitlist(): bool
545 2
    {
546
        return $this->enableWaitlist;
547 2
    }
548 2
549
    public function setEnableWaitlist(bool $enableWaitlist)
550
    {
551
        $this->enableWaitlist = $enableWaitlist;
552
    }
553
554
    public function getEnableWaitlistMoveup(): bool
555
    {
556
        return $this->enableWaitlistMoveup;
557 2
    }
558
559 2
    public function setEnableWaitlistMoveup(bool $enableWaitlistMoveup): void
560 2
    {
561
        $this->enableWaitlistMoveup = $enableWaitlistMoveup;
562
    }
563
564
    public function setRegistrationStartdate(?DateTime $registrationStartdate)
565
    {
566
        $this->registrationStartdate = $registrationStartdate;
567
    }
568
569 2
    public function getRegistrationStartdate(): ?DateTime
570
    {
571 2
        return $this->registrationStartdate;
572 2
    }
573
574
    public function setRegistrationDeadline(?DateTime $registrationDeadline)
575
    {
576
        $this->registrationDeadline = $registrationDeadline;
577
    }
578
579 2
    public function getRegistrationDeadline(): ?DateTime
580
    {
581 2
        return $this->registrationDeadline;
582
    }
583
584
    public function setLink(string $link)
585
    {
586
        $this->link = $link;
587
    }
588
589
    public function getLink(): string
590
    {
591 6
        return $this->link;
592
    }
593 6
594 6
    public function setTopEvent(bool $topEvent)
595
    {
596
        $this->topEvent = $topEvent;
597
    }
598
599
    public function getTopEvent(): bool
600
    {
601 4
        return $this->topEvent;
602
    }
603 4
604
    public function getMaxRegistrationsPerUser(): int
605
    {
606
        return $this->maxRegistrationsPerUser;
607
    }
608
609
    public function setMaxRegistrationsPerUser(int $maxRegistrationsPerUser)
610
    {
611
        $this->maxRegistrationsPerUser = $maxRegistrationsPerUser;
612 6
    }
613
614 6
    public function addAdditionalImage(FileReference $additionalImage)
615 6
    {
616
        $this->additionalImage->attach($additionalImage);
617
    }
618
619
    public function removeAdditionalImage(FileReference $additionalImageToRemove)
620
    {
621
        $this->additionalImage->detach($additionalImageToRemove);
622
    }
623 2
624
    public function getAdditionalImage(): ?ObjectStorage
625 2
    {
626 2
        return $this->additionalImage;
627
    }
628
629
    public function setAdditionalImage(?ObjectStorage $additionalImage)
630
    {
631
        $this->additionalImage = $additionalImage;
632
    }
633
634 2
    public function getOrganisator(): ?Organisator
635
    {
636 2
        return $this->organisator;
637 2
    }
638
639
    public function setOrganisator(Organisator $organisator)
640
    {
641
        $this->organisator = $organisator;
642
    }
643
644
    public function getNotifyAdmin(): bool
645
    {
646 4
        return $this->notifyAdmin;
647
    }
648 4
649 4
    public function setNotifyAdmin(bool $notifyAdmin)
650
    {
651
        $this->notifyAdmin = $notifyAdmin;
652
    }
653
654
    public function getNotifyOrganisator(): bool
655
    {
656
        return $this->notifyOrganisator;
657
    }
658 2
659
    public function setNotifyOrganisator(bool $notifyOrganisator)
660 2
    {
661 2
        $this->notifyOrganisator = $notifyOrganisator;
662
    }
663
664
    public function setEnableCancel(bool $enableCancel)
665
    {
666
        $this->enableCancel = $enableCancel;
667
    }
668 24
669
    public function getEnableCancel(): bool
670 24
    {
671
        return $this->enableCancel;
672
    }
673
674
    public function setCancelDeadline(?DateTime $cancelDeadline)
675
    {
676
        $this->cancelDeadline = $cancelDeadline;
677
    }
678
679
    public function getCancelDeadline(): ?DateTime
680 18
    {
681
        return $this->cancelDeadline;
682 18
    }
683 18
684
    public function getEnableAutoconfirm(): bool
685
    {
686
        return $this->enableAutoconfirm;
687
    }
688
689
    public function setEnableAutoconfirm(bool $enableAutoconfirm)
690
    {
691
        $this->enableAutoconfirm = $enableAutoconfirm;
692 2
    }
693
694 2
    public function getUniqueEmailCheck(): bool
695 2
    {
696
        return $this->uniqueEmailCheck;
697
    }
698
699
    public function setUniqueEmailCheck(bool $uniqueEmailCheck)
700
    {
701
        $this->uniqueEmailCheck = $uniqueEmailCheck;
702
    }
703
704 2
    public function getPriceOptions(): ?ObjectStorage
705
    {
706 2
        return $this->priceOptions;
707 2
    }
708
709
    public function setPriceOptions(?ObjectStorage $priceOptions)
710
    {
711
        $this->priceOptions = $priceOptions;
712
    }
713
714 2
    public function addPriceOptions(PriceOption $priceOption)
715
    {
716 2
        $this->priceOptions->attach($priceOption);
717
    }
718
719
    public function removePriceOptions(PriceOption $priceOption)
720
    {
721
        $this->priceOptions->detach($priceOption);
722
    }
723
724
    /**
725
     * Returns all active price options sorted by date ASC
726 6
     *
727
     * @return array
728 6
     */
729 6
    public function getActivePriceOptions(): array
730
    {
731
        $activePriceOptions = [];
732
        if ($this->getPriceOptions()) {
733
            $compareDate = new DateTime('today midnight');
734
            foreach ($this->getPriceOptions() as $priceOption) {
735
                if ($priceOption->getValidUntil() >= $compareDate) {
736
                    $activePriceOptions[$priceOption->getValidUntil()->getTimestamp()] = $priceOption;
737
                }
738 4
            }
739
        }
740 4
        ksort($activePriceOptions);
741 4
742
        return $activePriceOptions;
743
    }
744
745
    /**
746
     * Returns the current price of the event respecting possible price options
747
     *
748
     * @return float
749
     */
750 2
    public function getCurrentPrice(): float
751
    {
752 2
        $activePriceOptions = $this->getActivePriceOptions();
753 2
        if (count($activePriceOptions) >= 1) {
754
            // Sort active price options and return first element
755
            return reset($activePriceOptions)->getPrice();
756
        }
757
        // Just return the price field
758
        return $this->price;
759
    }
760 2
761
    public function getRegistrationWaitlist(): ?ObjectStorage
762 2
    {
763
        return $this->registrationWaitlist;
764
    }
765
766
    public function setRegistrationWaitlist(?ObjectStorage $registration)
767
    {
768
        $this->registrationWaitlist = $registration;
769
    }
770
771
    public function addRegistrationWaitlist(Registration $registration)
772 6
    {
773
        $this->registrationWaitlist->attach($registration);
774 6
    }
775 6
776
    public function removeRegistrationWaitlist(Registration $registrationToRemove)
777
    {
778
        $this->registrationWaitlist->detach($registrationToRemove);
779
    }
780
781
    /**
782 4
     * Returns, if cancellation for registrations of the event is possible
783
     *
784 4
     * @return bool
785
     */
786
    public function getCancellationPossible(): bool
787
    {
788
        $today = new DateTime('today');
789
790
        return ($this->getEnableCancel() && $this->getCancelDeadline() > $today) ||
791
            ($this->getEnableCancel() && $this->getCancelDeadline() === null && $this->getStartdate() > $today);
792
    }
793
794 2
    public function getSpeaker(): ?ObjectStorage
795
    {
796 2
        return $this->speaker;
797 2
    }
798
799
    public function setSpeaker(?ObjectStorage $speaker)
800
    {
801
        $this->speaker = $speaker;
802
    }
803
804 20
    public function addSpeaker(Speaker $speaker)
805
    {
806 20
        $this->speaker->attach($speaker);
807 20
    }
808 6
809 6
    public function removeSpeaker(Speaker $speaker)
810 20
    {
811 20
        $this->speaker->detach($speaker);
812 2
    }
813 2
814 20
    public function getRegistrationFields(): ?ObjectStorage
815 20
    {
816 20
        return $this->registrationFields;
817
    }
818
819
    public function setRegistrationFields(?ObjectStorage $registrationFields)
820
    {
821
        $this->registrationFields = $registrationFields;
822
    }
823
824 10
    public function addRegistrationFields(Field $registrationField)
825
    {
826 10
        $this->registrationFields->attach($registrationField);
827
    }
828
829
    public function removeRegistrationFields(Field $registrationField)
830
    {
831
        $this->registrationFields->detach($registrationField);
832
    }
833
834
    public function getRegistrationFieldsUids(): array
835
    {
836 2
        $result = [];
837
        foreach ($this->registrationFields as $registrationField) {
838 2
            $result[] = $registrationField->getUid();
839 2
        }
840
841
        return $result;
842
    }
843
844
    /**
845
     * Returns an array with registration field uids and titles
846 2
     * [uid => title]
847
     *
848 2
     * @return array
849
     */
850
    public function getRegistrationFieldUidsWithTitle(): array
851
    {
852
        $result = [];
853
        foreach ($this->registrationFields as $registrationField) {
854
            $result[$registrationField->getUid()] = $registrationField->getTitle();
855
        }
856
857
        return $result;
858 20
    }
859
860 20
    /**
861 20
     * Special getter to return the amount of registrations that are saved to default language
862
     * Required since TYPO3 9.5 (#82363)
863
     *
864
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
865
     */
866
    public function getRegistrations(): ?ObjectStorage
867
    {
868 16
        $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
869
        if ($languageAspect->getId() > 0) {
870 16
            return $this->getRegistrationsDefaultLanguage(false);
871
        }
872
873
        return $this->registration;
874
    }
875
876
    /**
877
     * Special getter to return the amount of waitlist registrations that are saved to default language
878 8
     * Required since TYPO3 9.5 (#82363)
879
     *
880 8
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
881
     */
882
    public function getRegistrationsWaitlist(): ?ObjectStorage
883
    {
884
        $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
885
        if ($languageAspect->getId() > 0) {
886
            return $this->getRegistrationsDefaultLanguage(true);
887
        }
888
889 10
        return $this->registrationWaitlist;
890
    }
891 10
892 10
    /**
893
     * Returns an objectStorage object holding all registrations in the default language.
894
     * Ensures expected behavior of getRegistration() and getRegistrationWaitlist() since TYPO3 issue #82363
895
     *
896
     * @param bool $waitlist
897
     * @return ObjectStorage
898
     */
899
    protected function getRegistrationsDefaultLanguage(bool $waitlist = false): ObjectStorage
900
    {
901 6
        $result = GeneralUtility::makeInstance(ObjectStorage::class);
902
        $registrationRepository = GeneralUtility::makeInstance(RegistrationRepository::class);
903 6
        $registrations = $registrationRepository->findByEventAndWaitlist($this, $waitlist);
904 6
        foreach ($registrations as $registration) {
905
            $result->attach($registration);
906
        }
907
908
        return $result;
909
    }
910
911 22
    public function getEndsSameDay(): bool
912
    {
913 22
        if ($this->enddate !== null) {
914
            return $this->startdate->format('d.m.Y') === $this->enddate->format('d.m.Y');
0 ignored issues
show
Bug introduced by
The method format() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

914
            return $this->startdate->/** @scrutinizer ignore-call */ format('d.m.Y') === $this->enddate->format('d.m.Y');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
915
        }
916
917
        return true;
918
    }
919
920
    public function getSpamCheckChallenge(): string
921
    {
922
        return MiscUtility::getSpamCheckChallenge($this->getUid());
0 ignored issues
show
Bug introduced by
It seems like $this->getUid() can also be of type null; however, parameter $eventUid of DERHANSEN\SfEventMgt\Uti...getSpamCheckChallenge() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

922
        return MiscUtility::getSpamCheckChallenge(/** @scrutinizer ignore-type */ $this->getUid());
Loading history...
923 24
    }
924
925 24
    /**
926 24
     * Returns a string to be used as overlay value for the <core:icon> ViewHelper in the Backend Modules
927
     *
928
     * @return string
929
     */
930
    public function getBackendIconOverlay(): string
931
    {
932
        $date = new DateTime();
933 2
        $overlay = '';
934
        if ($this->getHidden()) {
935 2
            $overlay = 'overlay-hidden';
936
        } elseif ($this->getEndtime() && $this->getEndtime() < $date) {
937
            $overlay = 'overlay-endtime';
938
        } elseif (($this->getStarttime() && $this->getStarttime() > $date) ||
939
            ($this->getEndtime() && $this->getEndtime() > $date)
940
        ) {
941
            $overlay = 'overlay-scheduled';
942
        }
943 2
944
        return $overlay;
945 2
    }
946
}
947