Event::getRegistrationFieldsUids()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
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;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Annotation was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Domain\Model\FileReference was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\DomainObject\AbstractEntity was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persistence\ObjectStorage was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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

970
            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...
971
        }
972
973
        return true;
974
    }
975
976
    public function getSpamCheckChallenge(): string
977
    {
978
        return MiscUtility::getSpamCheckChallenge($this->getUid());
979
    }
980
981
    /**
982
     * Returns a string to be used as overlay value for the <core:icon> ViewHelper in the Backend Modules
983
     */
984
    public function getBackendIconOverlay(): string
985
    {
986
        $date = new DateTime();
987
        $overlay = '';
988
        if ($this->getHidden()) {
989
            $overlay = 'overlay-hidden';
990
        } elseif ($this->getEndtime() && $this->getEndtime() < $date) {
991
            $overlay = 'overlay-endtime';
992
        } elseif (($this->getStarttime() && $this->getStarttime() > $date) ||
993
            ($this->getEndtime() && $this->getEndtime() > $date)
994
        ) {
995
            $overlay = 'overlay-scheduled';
996
        }
997
998
        return $overlay;
999
    }
1000
1001
    /**
1002
     * Calculates and returns the cache tag lifetime for the event based on several date fields
1003
     */
1004
    public function getCacheTagLifetime(DateTime $dateNow): int
1005
    {
1006
        if (!$this->getEnableRegistration() ||
1007
            !$this->getStartdate() ||
1008
            $this->getStartdate() < $dateNow
1009
        ) {
1010
            return PHP_INT_MAX;
1011
        }
1012
1013
        // If registration startdate is not reached, consider it for cache lifetime
1014
        if ($this->getRegistrationStartdate() &&
1015
            $this->getRegistrationStartdate() > $dateNow
1016
        ) {
1017
            return $this->getRegistrationStartdate()->getTimestamp() - $dateNow->getTimestamp() + 1;
1018
        }
1019
1020
        // If registration deadline is not reached, consider it for cache lifetime
1021
        if ($this->getRegistrationDeadline() &&
1022
            $this->getRegistrationDeadline() > $dateNow
1023
        ) {
1024
            return $this->getRegistrationDeadline()->getTimestamp() - $dateNow->getTimestamp() + 1;
1025
        }
1026
1027
        // If event has not started yet, consider startdate for cache lifetime
1028
        if ($this->getStartdate() > $dateNow) {
1029
            return $this->getStartdate()->getTimestamp() - $dateNow->getTimestamp() + 1;
1030
        }
1031
1032
        return PHP_INT_MAX;
1033
    }
1034
}
1035