Passed
Push — develop ( 9207e4...1aca68 )
by Torben
02:26
created

Event::getIsEnded()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

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