Passed
Push — 6.x ( 32235c...0713bf )
by Torben
08:10
created

Event::setAllowRegistrationUntilEnddate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 bool $allowRegistrationUntilEnddate = false;
52
    protected ?Location $location = null;
53
    protected string $room = '';
54
    protected bool $enableRegistration = false;
55
    protected bool $enableWaitlist = false;
56
    protected bool $enableWaitlistMoveup = false;
57
    protected string $link = '';
58
    protected bool $topEvent = false;
59
    protected ?Organisator $organisator = null;
60
    protected bool $notifyAdmin = true;
61
    protected bool $notifyOrganisator = false;
62
    protected bool $enableCancel = false;
63
    protected ?DateTime $cancelDeadline = null;
64
    protected bool $enableAutoconfirm = false;
65
    protected bool $uniqueEmailCheck = false;
66
    protected string $metaKeywords = '';
67
    protected string $metaDescription = '';
68
    protected string $alternativeTitle = '';
69
70
    /**
71
     * @var ObjectStorage<Category>
72
     * @Extbase\ORM\Lazy
73
     */
74
    protected ObjectStorage $category;
75
76
    /**
77
     * @var ObjectStorage<Event>
78
     * @Extbase\ORM\Lazy
79
     */
80
    protected ObjectStorage $related;
81
82
    /**
83
     * @var ObjectStorage<Registration>
84
     * @Extbase\ORM\Cascade("remove")
85
     * @Extbase\ORM\Lazy
86
     */
87
    protected ObjectStorage $registration;
88
89
    /**
90
     * @var ObjectStorage<Registration>
91
     * @Extbase\ORM\Lazy
92
     */
93
    protected ObjectStorage $registrationWaitlist;
94
95
    /**
96
     * @var ObjectStorage<Field>
97
     * @Extbase\ORM\Lazy
98
     */
99
    protected ObjectStorage $registrationFields;
100
101
    /**
102
     * @var ObjectStorage<FileReference>
103
     * @Extbase\ORM\Lazy
104
     */
105
    protected ObjectStorage $image;
106
107
    /**
108
     * @var ObjectStorage<FileReference>
109
     * @Extbase\ORM\Lazy
110
     */
111
    protected ObjectStorage $files;
112
113
    /**
114
     * @var ObjectStorage<FileReference>
115
     * @Extbase\ORM\Lazy
116
     */
117
    protected ObjectStorage $additionalImage;
118
119
    /**
120
     * @var ObjectStorage<PriceOption>
121
     * @Extbase\ORM\Cascade("remove")
122
     * @Extbase\ORM\Lazy
123
     */
124
    protected ObjectStorage $priceOptions;
125
126
    /**
127
     * @var ObjectStorage<Speaker>
128
     * @Extbase\ORM\Lazy
129
     */
130
    protected ObjectStorage $speaker;
131
132
    public function __construct()
133
    {
134
        $this->initializeObject();
135
    }
136
137
    /**
138
     * Initialize all ObjectStorages as fetching an entity from the DB does not use the constructor
139
     */
140
    public function initializeObject(): void
141
    {
142
        $this->category = new ObjectStorage();
143
        $this->related = new ObjectStorage();
144
        $this->registration = new ObjectStorage();
145
        $this->registrationWaitlist = new ObjectStorage();
146
        $this->registrationFields = new ObjectStorage();
147
        $this->image = new ObjectStorage();
148
        $this->files = new ObjectStorage();
149
        $this->additionalImage = new ObjectStorage();
150
        $this->priceOptions = new ObjectStorage();
151
        $this->speaker = new ObjectStorage();
152
    }
153
154
    public function getTstamp(): ?DateTime
155
    {
156
        return $this->tstamp;
157
    }
158
159
    public function setTstamp(?DateTime $tstamp): void
160
    {
161
        $this->tstamp = $tstamp;
162
    }
163
164
    public function getHidden(): bool
165
    {
166
        return $this->hidden;
167
    }
168
169
    public function setHidden(bool $hidden): void
170
    {
171
        $this->hidden = $hidden;
172
    }
173
174
    public function getStarttime(): ?DateTime
175
    {
176
        return $this->starttime;
177
    }
178
179
    public function setStarttime(?DateTime $starttime): void
180
    {
181
        $this->starttime = $starttime;
182
    }
183
184
    public function getEndtime(): ?DateTime
185
    {
186
        return $this->endtime;
187
    }
188
189
    public function setEndtime(?DateTime $endtime): void
190
    {
191
        $this->endtime = $endtime;
192
    }
193
194
    public function getTitle(): string
195
    {
196
        return $this->title;
197
    }
198
199
    public function setTitle(string $title): void
200
    {
201
        $this->title = $title;
202
    }
203
204
    public function getTeaser(): string
205
    {
206
        return $this->teaser;
207
    }
208
209
    public function setTeaser(string $teaser): void
210
    {
211
        $this->teaser = $teaser;
212
    }
213
214
    public function getDescription(): string
215
    {
216
        return $this->description;
217
    }
218
219
    public function setDescription(string $description): void
220
    {
221
        $this->description = $description;
222
    }
223
224
    public function getProgram(): string
225
    {
226
        return $this->program;
227
    }
228
229
    public function setProgram(string $program): void
230
    {
231
        $this->program = $program;
232
    }
233
234
    public function getCustomText(): string
235
    {
236
        return $this->customText;
237
    }
238
239
    public function setCustomText(string $customText): void
240
    {
241
        $this->customText = $customText;
242
    }
243
244
    public function getStartdate(): ?DateTime
245
    {
246
        return $this->startdate;
247
    }
248
249
    public function setStartdate(?DateTime $startdate): void
250
    {
251
        $this->startdate = $startdate;
252
    }
253
254
    public function getEnddate(): ?DateTime
255
    {
256
        return $this->enddate;
257
    }
258
259
    public function setEnddate(?DateTime $enddate): void
260
    {
261
        $this->enddate = $enddate;
262
    }
263
264
    public function getMaxParticipants(): int
265
    {
266
        return $this->maxParticipants;
267
    }
268
269
    public function setMaxParticipants(int $participants): void
270
    {
271
        $this->maxParticipants = $participants;
272
    }
273
274
    public function getPrice(): float
275
    {
276
        return $this->price;
277
    }
278
279
    public function setPrice(float $price): void
280
    {
281
        $this->price = $price;
282
    }
283
284
    public function getCurrency(): string
285
    {
286
        return $this->currency;
287
    }
288
289
    public function setCurrency(string $currency): void
290
    {
291
        $this->currency = $currency;
292
    }
293
294
    public function getEnablePayment(): bool
295
    {
296
        return $this->enablePayment;
297
    }
298
299
    public function setEnablePayment(bool $enablePayment): void
300
    {
301
        $this->enablePayment = $enablePayment;
302
    }
303
304
    public function getRestrictPaymentMethods(): bool
305
    {
306
        return $this->restrictPaymentMethods;
307
    }
308
309
    public function setRestrictPaymentMethods(bool $restrictPaymentMethods): void
310
    {
311
        $this->restrictPaymentMethods = $restrictPaymentMethods;
312
    }
313
314
    public function getSelectedPaymentMethods(): string
315
    {
316
        return $this->selectedPaymentMethods;
317
    }
318
319
    public function setSelectedPaymentMethods(string $selectedPaymentMethods): void
320
    {
321
        $this->selectedPaymentMethods = $selectedPaymentMethods;
322
    }
323
324
    public function addCategory(Category $category): void
325
    {
326
        $this->category->attach($category);
327
    }
328
329
    public function removeCategory(Category $categoryToRemove): void
330
    {
331
        $this->category->detach($categoryToRemove);
332
    }
333
334
    public function getCategory(): ?ObjectStorage
335
    {
336
        return $this->category;
337
    }
338
339
    public function getCategories(): ?ObjectStorage
340
    {
341
        return $this->category;
342
    }
343
344
    public function setCategory(?ObjectStorage $category): void
345
    {
346
        $this->category = $category;
347
    }
348
349
    public function getRelated(): ?ObjectStorage
350
    {
351
        return $this->related;
352
    }
353
354
    public function setRelated(?ObjectStorage $related): void
355
    {
356
        $this->related = $related;
357
    }
358
359
    public function addRelated(Event $event): void
360
    {
361
        $this->related->attach($event);
362
    }
363
364
    public function removeRelated(Event $event): void
365
    {
366
        $this->related->detach($event);
367
    }
368
369
    public function addRegistration(Registration $registration): void
370
    {
371
        $this->registration->attach($registration);
372
    }
373
374
    public function removeRegistration(Registration $registrationToRemove): void
375
    {
376
        $this->registration->detach($registrationToRemove);
377
    }
378
379
    public function getRegistration(): ?ObjectStorage
380
    {
381
        return $this->registration;
382
    }
383
384
    public function setRegistration(?ObjectStorage $registration): void
385
    {
386
        $this->registration = $registration;
387
    }
388
389
    public function addImage(FileReference $image): void
390
    {
391
        $this->image->attach($image);
392
    }
393
394
    public function removeImage(FileReference $imageToRemove): void
395
    {
396
        $this->image->detach($imageToRemove);
397
    }
398
399
    public function getImage(): ?ObjectStorage
400
    {
401
        return $this->image;
402
    }
403
404
    public function getImages(): ?ObjectStorage
405
    {
406
        return $this->image;
407
    }
408
409
    public function getListViewImages(): ?ObjectStorage
410
    {
411
        return $this->getImagesByType(ShowInPreviews::LIST_VIEWS);
412
    }
413
414
    public function getFirstListViewImage(): ?FileReference
415
    {
416
        $images = $this->getImagesByType(ShowInPreviews::LIST_VIEWS);
417
        $image = $images->current();
418
419
        if (is_a($image, FileReference::class)) {
420
            return $image;
421
        }
422
        return null;
423
    }
424
425
    public function getDetailViewImages(): ?ObjectStorage
426
    {
427
        return $this->getImagesByType(ShowInPreviews::DETAIL_VIEWS);
428
    }
429
430
    public function getFirstDetailViewImage(): ?FileReference
431
    {
432
        $images = $this->getImagesByType(ShowInPreviews::DETAIL_VIEWS);
433
        $image = $images->current();
434
435
        if (is_a($image, FileReference::class)) {
436
            return $image;
437
        }
438
        return null;
439
    }
440
441
    protected function getImagesByType(int $type): ?ObjectStorage
442
    {
443
        $result = new ObjectStorage();
444
445
        foreach ($this->image as $image) {
446
            /** @var \TYPO3\CMS\Core\Resource\FileReference $fileReference */
447
            $fileReference = $image->getOriginalResource();
0 ignored issues
show
Bug introduced by
The method getOriginalResource() 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

447
            /** @scrutinizer ignore-call */ 
448
            $fileReference = $image->getOriginalResource();

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...
448
            if ($fileReference !== null && $fileReference->hasProperty('show_in_views') &&
449
                in_array($fileReference->getProperty('show_in_views'), [$type, ShowInPreviews::ALL_VIEWS])
450
            ) {
451
                $result->attach($image);
452
            }
453
        }
454
455
        return $result;
456
    }
457
458
    public function setImage(?ObjectStorage $image): void
459
    {
460
        $this->image = $image;
461
    }
462
463
    public function addFiles(FileReference $file): void
464
    {
465
        $this->files->attach($file);
466
    }
467
468
    public function removeFiles(FileReference $fileToRemove): void
469
    {
470
        $this->files->detach($fileToRemove);
471
    }
472
473
    public function getFiles(): ?ObjectStorage
474
    {
475
        return $this->files;
476
    }
477
478
    public function setFiles(?ObjectStorage $files): void
479
    {
480
        $this->files = $files;
481
    }
482
483
    /**
484
     * Returns if the registration for this event is logically possible
485
     *
486
     * @return bool
487
     */
488
    public function getRegistrationPossible(): bool
489
    {
490
        $maxParticipantsNotReached = true;
491
        if ($this->getMaxParticipants() > 0 && $this->getRegistrations()->count() >= $this->maxParticipants) {
492
            $maxParticipantsNotReached = false;
493
        }
494
        $deadlineNotReached = true;
495
        if ($this->getRegistrationDeadline() !== null && $this->getRegistrationDeadline() <= new DateTime()) {
496
            $deadlineNotReached = false;
497
        }
498
        $registrationStartReached = true;
499
        if ($this->getRegistrationStartdate() !== null && $this->getRegistrationStartdate() > new DateTime()) {
500
            $registrationStartReached = false;
501
        }
502
503
        $allowedByEventDate = false;
504
        if ($this->getStartdate() > new DateTime()) {
505
            $allowedByEventDate = true;
506
        }
507
508
        if ($allowedByEventDate === false &&
509
            $this->getEnddate() &&
510
            $this->getAllowRegistrationUntilEnddate() &&
511
            $this->getEnddate() > new DateTime()
512
        ) {
513
            $allowedByEventDate = true;
514
        }
515
516
        return $allowedByEventDate &&
517
            ($maxParticipantsNotReached || $this->enableWaitlist) &&
518
            $this->getEnableRegistration() && $deadlineNotReached && $registrationStartReached;
519
    }
520
521
    /**
522
     * Returns the amount of free places
523
     *
524
     * @return int
525
     */
526
    public function getFreePlaces(): int
527
    {
528
        return $this->maxParticipants - $this->getRegistrations()->count();
529
    }
530
531
    public function setLocation(?Location $location): void
532
    {
533
        $this->location = $location;
534
    }
535
536
    public function getLocation(): ?Location
537
    {
538
        return $this->location;
539
    }
540
541
    public function getRoom(): string
542
    {
543
        return $this->room;
544
    }
545
546
    public function setRoom(string $room): void
547
    {
548
        $this->room = $room;
549
    }
550
551
    public function setEnableRegistration(bool $enableRegistration): void
552
    {
553
        $this->enableRegistration = $enableRegistration;
554
    }
555
556
    public function getEnableRegistration(): bool
557
    {
558
        return $this->enableRegistration;
559
    }
560
561
    public function getEnableWaitlist(): bool
562
    {
563
        return $this->enableWaitlist;
564
    }
565
566
    public function setEnableWaitlist(bool $enableWaitlist): void
567
    {
568
        $this->enableWaitlist = $enableWaitlist;
569
    }
570
571
    public function getEnableWaitlistMoveup(): bool
572
    {
573
        return $this->enableWaitlistMoveup;
574
    }
575
576
    public function setEnableWaitlistMoveup(bool $enableWaitlistMoveup): void
577
    {
578
        $this->enableWaitlistMoveup = $enableWaitlistMoveup;
579
    }
580
581
    public function setRegistrationStartdate(?DateTime $registrationStartdate): void
582
    {
583
        $this->registrationStartdate = $registrationStartdate;
584
    }
585
586
    public function getRegistrationStartdate(): ?DateTime
587
    {
588
        return $this->registrationStartdate;
589
    }
590
591
    public function setRegistrationDeadline(?DateTime $registrationDeadline): void
592
    {
593
        $this->registrationDeadline = $registrationDeadline;
594
    }
595
596
    public function getRegistrationDeadline(): ?DateTime
597
    {
598
        return $this->registrationDeadline;
599
    }
600
601
    public function getAllowRegistrationUntilEnddate(): bool
602
    {
603
        return $this->allowRegistrationUntilEnddate;
604
    }
605
606
    public function setAllowRegistrationUntilEnddate(bool $allowRegistrationUntilEnddate): void
607
    {
608
        $this->allowRegistrationUntilEnddate = $allowRegistrationUntilEnddate;
609
    }
610
611
    public function setLink(string $link): void
612
    {
613
        $this->link = $link;
614
    }
615
616
    public function getLink(): string
617
    {
618
        return $this->link;
619
    }
620
621
    public function setTopEvent(bool $topEvent): void
622
    {
623
        $this->topEvent = $topEvent;
624
    }
625
626
    public function getTopEvent(): bool
627
    {
628
        return $this->topEvent;
629
    }
630
631
    public function getMaxRegistrationsPerUser(): int
632
    {
633
        return $this->maxRegistrationsPerUser;
634
    }
635
636
    public function setMaxRegistrationsPerUser(int $maxRegistrationsPerUser): void
637
    {
638
        $this->maxRegistrationsPerUser = $maxRegistrationsPerUser;
639
    }
640
641
    public function addAdditionalImage(FileReference $additionalImage): void
642
    {
643
        $this->additionalImage->attach($additionalImage);
644
    }
645
646
    public function removeAdditionalImage(FileReference $additionalImageToRemove): void
647
    {
648
        $this->additionalImage->detach($additionalImageToRemove);
649
    }
650
651
    public function getAdditionalImage(): ?ObjectStorage
652
    {
653
        return $this->additionalImage;
654
    }
655
656
    public function setAdditionalImage(?ObjectStorage $additionalImage): void
657
    {
658
        $this->additionalImage = $additionalImage;
659
    }
660
661
    public function getOrganisator(): ?Organisator
662
    {
663
        return $this->organisator;
664
    }
665
666
    public function setOrganisator(Organisator $organisator): void
667
    {
668
        $this->organisator = $organisator;
669
    }
670
671
    public function getNotifyAdmin(): bool
672
    {
673
        return $this->notifyAdmin;
674
    }
675
676
    public function setNotifyAdmin(bool $notifyAdmin): void
677
    {
678
        $this->notifyAdmin = $notifyAdmin;
679
    }
680
681
    public function getNotifyOrganisator(): bool
682
    {
683
        return $this->notifyOrganisator;
684
    }
685
686
    public function setNotifyOrganisator(bool $notifyOrganisator): void
687
    {
688
        $this->notifyOrganisator = $notifyOrganisator;
689
    }
690
691
    public function setEnableCancel(bool $enableCancel): void
692
    {
693
        $this->enableCancel = $enableCancel;
694
    }
695
696
    public function getEnableCancel(): bool
697
    {
698
        return $this->enableCancel;
699
    }
700
701
    public function setCancelDeadline(?DateTime $cancelDeadline): void
702
    {
703
        $this->cancelDeadline = $cancelDeadline;
704
    }
705
706
    public function getCancelDeadline(): ?DateTime
707
    {
708
        return $this->cancelDeadline;
709
    }
710
711
    public function getEnableAutoconfirm(): bool
712
    {
713
        return $this->enableAutoconfirm;
714
    }
715
716
    public function setEnableAutoconfirm(bool $enableAutoconfirm): void
717
    {
718
        $this->enableAutoconfirm = $enableAutoconfirm;
719
    }
720
721
    public function getUniqueEmailCheck(): bool
722
    {
723
        return $this->uniqueEmailCheck;
724
    }
725
726
    public function setUniqueEmailCheck(bool $uniqueEmailCheck): void
727
    {
728
        $this->uniqueEmailCheck = $uniqueEmailCheck;
729
    }
730
731
    public function getMetaKeywords(): string
732
    {
733
        return $this->metaKeywords;
734
    }
735
736
    public function setMetaKeywords(string $metaKeywords): void
737
    {
738
        $this->metaKeywords = $metaKeywords;
739
    }
740
741
    public function getMetaDescription(): string
742
    {
743
        return $this->metaDescription;
744
    }
745
746
    public function setMetaDescription(string $metaDescription): void
747
    {
748
        $this->metaDescription = $metaDescription;
749
    }
750
751
    public function getAlternativeTitle(): string
752
    {
753
        return $this->alternativeTitle;
754
    }
755
756
    public function setAlternativeTitle(string $alternativeTitle): void
757
    {
758
        $this->alternativeTitle = $alternativeTitle;
759
    }
760
761
    public function getMetaTitle(): string
762
    {
763
        return $this->getAlternativeTitle() !== '' ? $this->getAlternativeTitle() : $this->getTitle();
764
    }
765
766
    public function getPriceOptions(): ?ObjectStorage
767
    {
768
        return $this->priceOptions;
769
    }
770
771
    public function setPriceOptions(?ObjectStorage $priceOptions): void
772
    {
773
        $this->priceOptions = $priceOptions;
774
    }
775
776
    public function addPriceOptions(PriceOption $priceOption): void
777
    {
778
        $this->priceOptions->attach($priceOption);
779
    }
780
781
    public function removePriceOptions(PriceOption $priceOption): void
782
    {
783
        $this->priceOptions->detach($priceOption);
784
    }
785
786
    /**
787
     * Returns all active price options sorted by date ASC
788
     *
789
     * @return array
790
     */
791
    public function getActivePriceOptions(): array
792
    {
793
        $activePriceOptions = [];
794
        if ($this->getPriceOptions()) {
795
            $compareDate = new DateTime('today midnight');
796
            foreach ($this->getPriceOptions() as $priceOption) {
797
                if ($priceOption->getValidUntil() >= $compareDate) {
798
                    $activePriceOptions[$priceOption->getValidUntil()->getTimestamp()] = $priceOption;
799
                }
800
            }
801
        }
802
        ksort($activePriceOptions);
803
804
        return $activePriceOptions;
805
    }
806
807
    /**
808
     * Returns the current price of the event respecting possible price options
809
     *
810
     * @return float
811
     */
812
    public function getCurrentPrice(): float
813
    {
814
        $activePriceOptions = $this->getActivePriceOptions();
815
        if (count($activePriceOptions) >= 1) {
816
            // Sort active price options and return first element
817
            return reset($activePriceOptions)->getPrice();
818
        }
819
        // Just return the price field
820
        return $this->price;
821
    }
822
823
    public function getRegistrationWaitlist(): ?ObjectStorage
824
    {
825
        return $this->registrationWaitlist;
826
    }
827
828
    public function setRegistrationWaitlist(?ObjectStorage $registration): void
829
    {
830
        $this->registrationWaitlist = $registration;
831
    }
832
833
    public function addRegistrationWaitlist(Registration $registration): void
834
    {
835
        $this->registrationWaitlist->attach($registration);
836
    }
837
838
    public function removeRegistrationWaitlist(Registration $registrationToRemove): void
839
    {
840
        $this->registrationWaitlist->detach($registrationToRemove);
841
    }
842
843
    /**
844
     * Returns, if cancellation for registrations of the event is possible
845
     *
846
     * @return bool
847
     */
848
    public function getCancellationPossible(): bool
849
    {
850
        $today = new DateTime('today');
851
852
        return ($this->getEnableCancel() && $this->getCancelDeadline() > $today) ||
853
            ($this->getEnableCancel() && $this->getCancelDeadline() === null && $this->getStartdate() > $today);
854
    }
855
856
    public function getSpeaker(): ?ObjectStorage
857
    {
858
        return $this->speaker;
859
    }
860
861
    public function setSpeaker(?ObjectStorage $speaker): void
862
    {
863
        $this->speaker = $speaker;
864
    }
865
866
    public function addSpeaker(Speaker $speaker): void
867
    {
868
        $this->speaker->attach($speaker);
869
    }
870
871
    public function removeSpeaker(Speaker $speaker): void
872
    {
873
        $this->speaker->detach($speaker);
874
    }
875
876
    public function getRegistrationFields(): ?ObjectStorage
877
    {
878
        return $this->registrationFields;
879
    }
880
881
    public function setRegistrationFields(?ObjectStorage $registrationFields): void
882
    {
883
        $this->registrationFields = $registrationFields;
884
    }
885
886
    public function addRegistrationFields(Field $registrationField): void
887
    {
888
        $this->registrationFields->attach($registrationField);
889
    }
890
891
    public function removeRegistrationFields(Field $registrationField): void
892
    {
893
        $this->registrationFields->detach($registrationField);
894
    }
895
896
    public function getRegistrationFieldsUids(): array
897
    {
898
        $result = [];
899
        foreach ($this->registrationFields as $registrationField) {
900
            $result[] = $registrationField->getUid();
0 ignored issues
show
Bug introduced by
The method getUid() 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

900
            /** @scrutinizer ignore-call */ 
901
            $result[] = $registrationField->getUid();

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...
901
        }
902
903
        return $result;
904
    }
905
906
    /**
907
     * Returns an array with registration field uids and titles
908
     * [uid => title]
909
     *
910
     * @return array
911
     */
912
    public function getRegistrationFieldUidsWithTitle(): array
913
    {
914
        $result = [];
915
        foreach ($this->registrationFields as $registrationField) {
916
            $result[$registrationField->getUid()] = $registrationField->getTitle();
917
        }
918
919
        return $result;
920
    }
921
922
    /**
923
     * Special getter to return the amount of registrations that are saved to default language
924
     * Required since TYPO3 9.5 (#82363)
925
     *
926
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
927
     */
928
    public function getRegistrations(): ?ObjectStorage
929
    {
930
        $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
931
        if ($languageAspect->getId() > 0) {
932
            return $this->getRegistrationsDefaultLanguage(false);
933
        }
934
935
        return $this->registration;
936
    }
937
938
    /**
939
     * Special getter to return the amount of waitlist registrations that are saved to default language
940
     * Required since TYPO3 9.5 (#82363)
941
     *
942
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
943
     */
944
    public function getRegistrationsWaitlist(): ?ObjectStorage
945
    {
946
        $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
947
        if ($languageAspect->getId() > 0) {
948
            return $this->getRegistrationsDefaultLanguage(true);
949
        }
950
951
        return $this->registrationWaitlist;
952
    }
953
954
    /**
955
     * Returns an objectStorage object holding all registrations in the default language.
956
     * Ensures expected behavior of getRegistration() and getRegistrationWaitlist() since TYPO3 issue #82363
957
     *
958
     * @param bool $waitlist
959
     * @return ObjectStorage
960
     */
961
    protected function getRegistrationsDefaultLanguage(bool $waitlist = false): ObjectStorage
962
    {
963
        $result = GeneralUtility::makeInstance(ObjectStorage::class);
964
        $registrationRepository = GeneralUtility::makeInstance(RegistrationRepository::class);
965
        $registrations = $registrationRepository->findByEventAndWaitlist($this, $waitlist);
966
        foreach ($registrations as $registration) {
967
            $result->attach($registration);
968
        }
969
970
        return $result;
971
    }
972
973
    public function getEndsSameDay(): bool
974
    {
975
        if ($this->enddate !== null) {
976
            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

976
            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...
977
        }
978
979
        return true;
980
    }
981
982
    public function getSpamCheckChallenge(): string
983
    {
984
        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

984
        return MiscUtility::getSpamCheckChallenge(/** @scrutinizer ignore-type */ $this->getUid());
Loading history...
985
    }
986
987
    /**
988
     * Returns a string to be used as overlay value for the <core:icon> ViewHelper in the Backend Modules
989
     *
990
     * @return string
991
     */
992
    public function getBackendIconOverlay(): string
993
    {
994
        $date = new DateTime();
995
        $overlay = '';
996
        if ($this->getHidden()) {
997
            $overlay = 'overlay-hidden';
998
        } elseif ($this->getEndtime() && $this->getEndtime() < $date) {
999
            $overlay = 'overlay-endtime';
1000
        } elseif (($this->getStarttime() && $this->getStarttime() > $date) ||
1001
            ($this->getEndtime() && $this->getEndtime() > $date)
1002
        ) {
1003
            $overlay = 'overlay-scheduled';
1004
        }
1005
1006
        return $overlay;
1007
    }
1008
}
1009