Completed
Push — task/630-registration ( 4ac8a7 )
by Torben
04:27
created

Event::getRegistrations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
namespace DERHANSEN\SfEventMgt\Domain\Model;
3
4
/*
5
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.txt file that was distributed with this source code.
9
 */
10
11
use DERHANSEN\SfEventMgt\Domain\Model\Registration\Field;
12
use DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
use TYPO3\CMS\Extbase\Object\ObjectManager;
15
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
16
17
/**
18
 * Event
19
 *
20
 * @author Torben Hansen <[email protected]>
21
 */
22
class Event extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
23
{
24
    /**
25
     * @var \DateTime
26
     */
27
    protected $tstamp;
28
29
    /**
30
     * Title
31
     *
32
     * @var string
33
     * @validate NotEmpty
34
     */
35
    protected $title = '';
36
37
    /**
38
     * Teaser
39
     *
40
     * @var string
41
     */
42
    protected $teaser = '';
43
44
    /**
45
     * Description
46
     *
47
     * @var string
48
     */
49
    protected $description = '';
50
51
    /**
52
     * Program/Schedule
53
     *
54
     * @var string
55
     */
56
    protected $program = '';
57
58
    /**
59
     * Startdate and time
60
     *
61
     * @var \DateTime
62
     */
63
    protected $startdate = null;
64
65
    /**
66
     * Enddate and time
67
     *
68
     * @var \DateTime
69
     */
70
    protected $enddate = null;
71
72
    /**
73
     * Max participants
74
     *
75
     * @var int
76
     */
77
    protected $maxParticipants = 0;
78
79
    /**
80
     * Max registrations per user
81
     *
82
     * @var int
83
     */
84
    protected $maxRegistrationsPerUser = 1;
85
86
    /**
87
     * Price
88
     *
89
     * @var float
90
     */
91
    protected $price = 0.0;
92
93
    /**
94
     * Currency
95
     *
96
     * @var string
97
     */
98
    protected $currency = '';
99
100
    /**
101
     * Enable payment
102
     *
103
     * @var bool
104
     */
105
    protected $enablePayment = false;
106
107
    /**
108
     * Restrict payment methods
109
     *
110
     * @var bool
111
     */
112
    protected $restrictPaymentMethods = false;
113
114
    /**
115
     * Selected payment methods
116
     *
117
     * @var string
118
     */
119
    protected $selectedPaymentMethods = '';
120
121
    /**
122
     * Category
123
     *
124
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfEventMgt\Domain\Model\Category>
125
     * @lazy
126
     */
127
    protected $category = null;
128
129
    /**
130
     * Related
131
     *
132
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfEventMgt\Domain\Model\Event>
133
     * @lazy
134
     */
135
    protected $related;
136
137
    /**
138
     * Registration
139
     *
140
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfEventMgt\Domain\Model\Registration>
141
     * @cascade remove
142
     * @lazy
143
     */
144
    protected $registration = null;
145
146
    /**
147
     * Registration waitlist
148
     *
149
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfEventMgt\Domain\Model\Registration>
150
     * @lazy
151
     */
152
    protected $registrationWaitlist;
153
154
    /**
155
     * Registration fields
156
     *
157
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfEventMgt\Domain\Model\Registration\Field>
158
     * @lazy
159
     */
160
    protected $registrationFields;
161
162
    /**
163
     * Registration deadline date
164
     *
165
     * @var \DateTime
166
     */
167
    protected $registrationDeadline = null;
168
169
    /**
170
     * The image
171
     *
172
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
173
     * @lazy
174
     */
175
    protected $image = null;
176
177
    /**
178
     * Additional files
179
     *
180
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
181
     * @lazy
182
     */
183
    protected $files = null;
184
185
    /**
186
     * The Location
187
     *
188
     * @var \DERHANSEN\SfEventMgt\Domain\Model\Location
189
     */
190
    protected $location = null;
191
192
    /**
193
     * Enable registration
194
     *
195
     * @var bool
196
     */
197
    protected $enableRegistration = false;
198
199
    /**
200
     * Enable waitlist
201
     *
202
     * @var bool
203
     */
204
    protected $enableWaitlist = false;
205
206
    /**
207
     * Link
208
     *
209
     * @var string
210
     */
211
    protected $link;
212
213
    /**
214
     * Top event
215
     *
216
     * @var bool
217
     */
218
    protected $topEvent = false;
219
220
    /**
221
     * The additionalImage
222
     *
223
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
224
     * @lazy
225
     */
226
    protected $additionalImage = null;
227
228
    /**
229
     * The organisator
230
     *
231
     * @var \DERHANSEN\SfEventMgt\Domain\Model\Organisator
232
     */
233
    protected $organisator = null;
234
235
    /**
236
     * Notify admin
237
     *
238
     * @var bool
239
     */
240
    protected $notifyAdmin = true;
241
242
    /**
243
     * Notify organisator
244
     *
245
     * @var bool
246
     */
247
    protected $notifyOrganisator = false;
248
249
    /**
250
     * Enable cancel of registration
251
     *
252
     * @var bool
253
     */
254
    protected $enableCancel = false;
255
256
    /**
257
     * Deadline for cancel
258
     *
259
     * @var \DateTime
260
     */
261
    protected $cancelDeadline = null;
262
263
    /**
264
     * Enable auto confirmation
265
     *
266
     * @var bool
267
     */
268
    protected $enableAutoconfirm = false;
269
270
    /**
271
     * Unique e-mail check
272
     *
273
     * @var bool
274
     */
275
    protected $uniqueEmailCheck = false;
276
277
    /**
278
     * Price options
279
     *
280
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfEventMgt\Domain\Model\PriceOption>
281
     * @cascade remove
282
     * @lazy
283
     */
284
    protected $priceOptions = null;
285
286
    /**
287
     * Speaker
288
     *
289
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\DERHANSEN\SfEventMgt\Domain\Model\Speaker>
290
     * @lazy
291
     */
292
    protected $speaker = null;
293
294
    /**
295
     * Constructor
296
     */
297
    public function __construct()
298
    {
299
        $this->category = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
300
        $this->related = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
301
        $this->registration = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
302
        $this->registrationWaitlist = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
303
        $this->registrationFields = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
304
        $this->image = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
305
        $this->files = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
306
        $this->additionalImage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
307
        $this->priceOptions = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
308
        $this->speaker = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
309
    }
310
311
    /**
312
     * Get timestamp
313
     *
314
     * @return \DateTime
315
     */
316
    public function getTstamp()
317
    {
318
        return $this->tstamp;
319
    }
320
321
    /**
322
     * Set time stamp
323
     *
324
     * @param \DateTime $tstamp time stamp
325
     */
326
    public function setTstamp($tstamp)
327
    {
328
        $this->tstamp = $tstamp;
329
    }
330
331
    /**
332
     * Returns the title
333
     *
334
     * @return string $title
335
     */
336
    public function getTitle()
337
    {
338
        return $this->title;
339
    }
340
341
    /**
342
     * Sets the title
343
     *
344
     * @param string $title Title
345
     *
346
     * @return void
347
     */
348
    public function setTitle($title)
349
    {
350
        $this->title = $title;
351
    }
352
353
    /**
354
     * Returns the teaser
355
     *
356
     * @return string
357
     */
358
    public function getTeaser()
359
    {
360
        return $this->teaser;
361
    }
362
363
    /**
364
     * Sets the teaser
365
     *
366
     * @param string $teaser Teaser
367
     *
368
     * @return void
369
     */
370
    public function setTeaser($teaser)
371
    {
372
        $this->teaser = $teaser;
373
    }
374
375
    /**
376
     * Returns the description
377
     *
378
     * @return string $description
379
     */
380
    public function getDescription()
381
    {
382
        return $this->description;
383
    }
384
385
    /**
386
     * Sets the description
387
     *
388
     * @param string $description Description
389
     *
390
     * @return void
391
     */
392
    public function setDescription($description)
393
    {
394
        $this->description = $description;
395
    }
396
397
    /**
398
     * Returns the program
399
     *
400
     * @return string $program
401
     */
402
    public function getProgram()
403
    {
404
        return $this->program;
405
    }
406
407
    /**
408
     * Sets the program
409
     *
410
     * @param string $program The program
411
     *
412
     * @return void
413
     */
414
    public function setProgram($program)
415
    {
416
        $this->program = $program;
417
    }
418
419
    /**
420
     * Returns the startdate
421
     *
422
     * @return \DateTime $startdate
423
     */
424
    public function getStartdate()
425
    {
426
        return $this->startdate;
427
    }
428
429
    /**
430
     * Sets the startdate
431
     *
432
     * @param \DateTime $startdate Startdate
433
     *
434
     * @return void
435
     */
436
    public function setStartdate(\DateTime $startdate)
437
    {
438
        $this->startdate = $startdate;
439
    }
440
441
    /**
442
     * Returns the enddate
443
     *
444
     * @return \DateTime $enddate
445
     */
446
    public function getEnddate()
447
    {
448
        return $this->enddate;
449
    }
450
451
    /**
452
     * Sets the enddate
453
     *
454
     * @param \DateTime $enddate Enddate
455
     *
456
     * @return void
457
     */
458
    public function setEnddate(\DateTime $enddate)
459
    {
460
        $this->enddate = $enddate;
461
    }
462
463
    /**
464
     * Returns the participants
465
     *
466
     * @return int $participants
467
     */
468
    public function getMaxParticipants()
469
    {
470
        return $this->maxParticipants;
471
    }
472
473
    /**
474
     * Sets the participants
475
     *
476
     * @param int $participants Participants
477
     *
478
     * @return void
479
     */
480
    public function setMaxParticipants($participants)
481
    {
482
        $this->maxParticipants = $participants;
483
    }
484
485
    /**
486
     * Returns the price
487
     *
488
     * @return float $price
489
     */
490
    public function getPrice()
491
    {
492
        return $this->price;
493
    }
494
495
    /**
496
     * Sets the price
497
     *
498
     * @param float $price Price
499
     *
500
     * @return void
501
     */
502
    public function setPrice($price)
503
    {
504
        $this->price = $price;
505
    }
506
507
    /**
508
     * Returns the currency
509
     *
510
     * @return string $currency
511
     */
512
    public function getCurrency()
513
    {
514
        return $this->currency;
515
    }
516
517
    /**
518
     * Sets the currency
519
     *
520
     * @param string $currency Currency
521
     *
522
     * @return void
523
     */
524
    public function setCurrency($currency)
525
    {
526
        $this->currency = $currency;
527
    }
528
529
    /**
530
     * Returns if payment is enabled
531
     *
532
     * @return bool
533
     */
534
    public function getEnablePayment()
535
    {
536
        return $this->enablePayment;
537
    }
538
539
    /**
540
     * Sets enablePayment
541
     *
542
     * @param bool $enablePayment
543
     * @return void
544
     */
545
    public function setEnablePayment($enablePayment)
546
    {
547
        $this->enablePayment = $enablePayment;
548
    }
549
550
    /**
551
     * Returns if payment methods should be restricted
552
     *
553
     * @return bool
554
     */
555
    public function getRestrictPaymentMethods()
556
    {
557
        return $this->restrictPaymentMethods;
558
    }
559
560
    /**
561
     * Sets if payment methods should be restricted
562
     *
563
     * @param bool $restrictPaymentMethods
564
     * @return void
565
     */
566
    public function setRestrictPaymentMethods($restrictPaymentMethods)
567
    {
568
        $this->restrictPaymentMethods = $restrictPaymentMethods;
569
    }
570
571
    /**
572
     * Returns selected payment methods
573
     *
574
     * @return string
575
     */
576
    public function getSelectedPaymentMethods()
577
    {
578
        return $this->selectedPaymentMethods;
579
    }
580
581
    /**
582
     * Sets selected payment methods
583
     *
584
     * @param string $selectedPaymentMethods
585
     * @return void
586
     */
587
    public function setSelectedPaymentMethods($selectedPaymentMethods)
588
    {
589
        $this->selectedPaymentMethods = $selectedPaymentMethods;
590
    }
591
592
    /**
593
     * Adds a Category
594
     *
595
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Category $category Category
596
     *
597
     * @return void
598
     */
599
    public function addCategory(\DERHANSEN\SfEventMgt\Domain\Model\Category $category)
600
    {
601
        $this->category->attach($category);
602
    }
603
604
    /**
605
     * Removes a Category
606
     *
607
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Category $categoryToRemove The Category to be removed
608
     *
609
     * @return void
610
     */
611
    public function removeCategory(\DERHANSEN\SfEventMgt\Domain\Model\Category $categoryToRemove)
612
    {
613
        $this->category->detach($categoryToRemove);
614
    }
615
616
    /**
617
     * Returns the category
618
     *
619
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
620
     */
621
    public function getCategory()
622
    {
623
        return $this->category;
624
    }
625
626
    /**
627
     * Sets the category
628
     *
629
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $category Category
630
     *
631
     * @return void
632
     */
633
    public function setCategory(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $category)
634
    {
635
        $this->category = $category;
636
    }
637
638
    /**
639
     * Returns related events
640
     *
641
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
642
     */
643
    public function getRelated()
644
    {
645
        return $this->related;
646
    }
647
648
    /**
649
     * Sets related events
650
     *
651
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $related
652
     * @return void
653
     */
654
    public function setRelated($related)
655
    {
656
        $this->related = $related;
657
    }
658
659
    /**
660
     * Adds a related event
661
     *
662
     * @param Event $event
663
     * @return void
664
     */
665
    public function addRelated(\DERHANSEN\SfEventMgt\Domain\Model\Event $event)
666
    {
667
        $this->related->attach($event);
668
    }
669
670
    /**
671
     * Removes a related event
672
     *
673
     * @param Event $event
674
     * @return void
675
     */
676
    public function removeRelated(\DERHANSEN\SfEventMgt\Domain\Model\Event $event)
677
    {
678
        $this->related->detach($event);
679
    }
680
681
    /**
682
     * Adds a Registration
683
     *
684
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
685
     *
686
     * @return void
687
     */
688
    public function addRegistration(\DERHANSEN\SfEventMgt\Domain\Model\Registration $registration)
689
    {
690
        $this->registration->attach($registration);
691
    }
692
693
    /**
694
     * Removes a Registration
695
     *
696
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registrationToRemove Registration
697
     *
698
     * @return void
699
     */
700
    public function removeRegistration(\DERHANSEN\SfEventMgt\Domain\Model\Registration $registrationToRemove)
701
    {
702
        $this->registration->detach($registrationToRemove);
703
    }
704
705
    /**
706
     * Returns the Registration
707
     *
708
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $registration
709
     */
710
    public function getRegistration()
711
    {
712
        // Since TYPO3 9.5 (#82363)
713
        if ($GLOBALS['TSFE']->sys_language_uid > 0) {
714
            return $this->getRegistrations(false);
715
        }
716
717
        return $this->registration;
718
    }
719
720
    /**
721
     * Sets the Registration
722
     *
723
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $registration Registration
724
     *
725
     * @return void
726
     */
727
    public function setRegistration(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $registration)
728
    {
729
        $this->registration = $registration;
730
    }
731
732
    /**
733
     * Adds an image
734
     *
735
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image Image
736
     *
737
     * @return void
738
     */
739
    public function addImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image)
740
    {
741
        $this->image->attach($image);
742
    }
743
744
    /**
745
     * Removes an image
746
     *
747
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $imageToRemove Image
748
     *
749
     * @return void
750
     */
751
    public function removeImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $imageToRemove)
752
    {
753
        $this->image->detach($imageToRemove);
754
    }
755
756
    /**
757
     * Returns the image
758
     *
759
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $image
760
     */
761
    public function getImage()
762
    {
763
        return $this->image;
764
    }
765
766
    /**
767
     * Sets the image
768
     *
769
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $image Image
770
     *
771
     * @return void
772
     */
773
    public function setImage(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $image)
774
    {
775
        $this->image = $image;
776
    }
777
778
    /**
779
     * Adds a file
780
     *
781
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $file File
782
     *
783
     * @return void
784
     */
785
    public function addFiles(\TYPO3\CMS\Extbase\Domain\Model\FileReference $file)
786
    {
787
        $this->files->attach($file);
788
    }
789
790
    /**
791
     * Removes a file
792
     *
793
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $fileToRemove File
794
     *
795
     * @return void
796
     */
797
    public function removeFiles(\TYPO3\CMS\Extbase\Domain\Model\FileReference $fileToRemove)
798
    {
799
        $this->files->detach($fileToRemove);
800
    }
801
802
    /**
803
     * Returns the files
804
     *
805
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $files
806
     */
807
    public function getFiles()
808
    {
809
        return $this->files;
810
    }
811
812
    /**
813
     * Sets the files
814
     *
815
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $files Files
816
     *
817
     * @return void
818
     */
819
    public function setFiles(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $files)
820
    {
821
        $this->files = $files;
822
    }
823
824
    /**
825
     * Returns if the registration for this event is logically possible
826
     *
827
     * @return bool
828
     */
829
    public function getRegistrationPossible()
830
    {
831
        $maxParticipantsNotReached = true;
832
        if ($this->getMaxParticipants() > 0 && $this->getRegistration()->count() >= $this->maxParticipants) {
833
            $maxParticipantsNotReached = false;
834
        }
835
        $deadlineNotReached = true;
836
        if ($this->getRegistrationDeadline() != null && $this->getRegistrationDeadline() <= new \DateTime()) {
837
            $deadlineNotReached = false;
838
        }
839
840
        return ($this->getStartdate() > new \DateTime()) &&
841
        ($maxParticipantsNotReached || !$maxParticipantsNotReached && $this->enableWaitlist) &&
842
        $this->getEnableRegistration() && $deadlineNotReached;
843
    }
844
845
    /**
846
     * Returns the amount of free places
847
     *
848
     * @return int
849
     */
850
    public function getFreePlaces()
851
    {
852
        return $this->maxParticipants - $this->getRegistration()->count();
853
    }
854
855
    /**
856
     * Sets the location
857
     *
858
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Location $location Location
859
     *
860
     * @return void
861
     */
862
    public function setLocation($location)
863
    {
864
        $this->location = $location;
865
    }
866
867
    /**
868
     * Returns the location
869
     *
870
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Location
871
     */
872
    public function getLocation()
873
    {
874
        return $this->location;
875
    }
876
877
    /**
878
     * Sets enableRegistration
879
     *
880
     * @param bool $enableRegistration EnableRegistration
881
     *
882
     * @return void
883
     */
884
    public function setEnableRegistration($enableRegistration)
885
    {
886
        $this->enableRegistration = $enableRegistration;
887
    }
888
889
    /**
890
     * Returns if registration is enabled
891
     *
892
     * @return bool
893
     */
894
    public function getEnableRegistration()
895
    {
896
        return $this->enableRegistration;
897
    }
898
899
    /**
900
     * Returns enableWaitlist
901
     *
902
     * @return bool
903
     */
904
    public function getEnableWaitlist()
905
    {
906
        return $this->enableWaitlist;
907
    }
908
909
    /**
910
     * Sets enableWaitlist
911
     *
912
     * @param bool $enableWaitlist
913
     * @return void
914
     */
915
    public function setEnableWaitlist($enableWaitlist)
916
    {
917
        $this->enableWaitlist = $enableWaitlist;
918
    }
919
920
    /**
921
     * Sets the registration deadline
922
     *
923
     * @param \DateTime $registrationDeadline RegistrationDeadline
924
     *
925
     * @return void
926
     */
927
    public function setRegistrationDeadline(\DateTime $registrationDeadline)
928
    {
929
        $this->registrationDeadline = $registrationDeadline;
930
    }
931
932
    /**
933
     * Returns the registration deadline
934
     *
935
     * @return \DateTime
936
     */
937
    public function getRegistrationDeadline()
938
    {
939
        return $this->registrationDeadline;
940
    }
941
942
    /**
943
     * Sets the link
944
     *
945
     * @param string $link Link
946
     *
947
     * @return void
948
     */
949
    public function setLink($link)
950
    {
951
        $this->link = $link;
952
    }
953
954
    /**
955
     * Returns the link
956
     *
957
     * @return string
958
     */
959
    public function getLink()
960
    {
961
        return $this->link;
962
    }
963
964
    /**
965
     * Sets topEvent
966
     *
967
     * @param bool $topEvent TopEvent
968
     *
969
     * @return void
970
     */
971
    public function setTopEvent($topEvent)
972
    {
973
        $this->topEvent = $topEvent;
974
    }
975
976
    /**
977
     * Returns if topEvent is checked
978
     *
979
     * @return bool
980
     */
981
    public function getTopEvent()
982
    {
983
        return $this->topEvent;
984
    }
985
986
    /**
987
     * Returns max regisrations per user
988
     *
989
     * @return int
990
     */
991
    public function getMaxRegistrationsPerUser()
992
    {
993
        return $this->maxRegistrationsPerUser;
994
    }
995
996
    /**
997
     * Sets max registrations per user
998
     *
999
     * @param int $maxRegistrationsPerUser MaxRegistrationsPerUser
1000
     *
1001
     * @return void
1002
     */
1003
    public function setMaxRegistrationsPerUser($maxRegistrationsPerUser)
1004
    {
1005
        $this->maxRegistrationsPerUser = $maxRegistrationsPerUser;
1006
    }
1007
1008
    /**
1009
     * Adds an additionalImage
1010
     *
1011
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $additionalImage The Image
1012
     *
1013
     * @return void
1014
     */
1015
    public function addAdditionalImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $additionalImage)
1016
    {
1017
        $this->additionalImage->attach($additionalImage);
1018
    }
1019
1020
    /**
1021
     * Removes an additionalImage
1022
     *
1023
     * @param \TYPO3\CMS\Extbase\Domain\Model\FileReference $additionalImageToRemove The Image
1024
     *
1025
     * @return void
1026
     */
1027
    public function removeAdditionalImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $additionalImageToRemove)
1028
    {
1029
        $this->additionalImage->detach($additionalImageToRemove);
1030
    }
1031
1032
    /**
1033
     * Returns the additionalImage
1034
     *
1035
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage $additionalImage
1036
     */
1037
    public function getAdditionalImage()
1038
    {
1039
        return $this->additionalImage;
1040
    }
1041
1042
    /**
1043
     * Sets the additionalImage
1044
     *
1045
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $additionalImage The Image
1046
     *
1047
     * @return void
1048
     */
1049
    public function setAdditionalImage(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $additionalImage)
1050
    {
1051
        $this->additionalImage = $additionalImage;
1052
    }
1053
1054
    /**
1055
     * Returns the organisator
1056
     *
1057
     * @return Organisator
1058
     */
1059
    public function getOrganisator()
1060
    {
1061
        return $this->organisator;
1062
    }
1063
1064
    /**
1065
     * Sets the organisator
1066
     *
1067
     * @param Organisator $organisator The organisator
1068
     *
1069
     * @return void
1070
     */
1071
    public function setOrganisator($organisator)
1072
    {
1073
        $this->organisator = $organisator;
1074
    }
1075
1076
    /**
1077
     * Returns notifyAdmin
1078
     *
1079
     * @return bool
1080
     */
1081
    public function getNotifyAdmin()
1082
    {
1083
        return $this->notifyAdmin;
1084
    }
1085
1086
    /**
1087
     * Sets notifyAdmin
1088
     *
1089
     * @param bool $notifyAdmin NotifyAdmin
1090
     *
1091
     * @return void
1092
     */
1093
    public function setNotifyAdmin($notifyAdmin)
1094
    {
1095
        $this->notifyAdmin = $notifyAdmin;
1096
    }
1097
1098
    /**
1099
     * Returns if notifyAdmin is set
1100
     *
1101
     * @return bool
1102
     */
1103
    public function getNotifyOrganisator()
1104
    {
1105
        return $this->notifyOrganisator;
1106
    }
1107
1108
    /**
1109
     * Sets notifyOrganisator
1110
     *
1111
     * @param bool $notifyOrganisator NotifyOrganisator
1112
     *
1113
     * @return void
1114
     */
1115
    public function setNotifyOrganisator($notifyOrganisator)
1116
    {
1117
        $this->notifyOrganisator = $notifyOrganisator;
1118
    }
1119
1120
    /**
1121
     * Sets enableCancel
1122
     *
1123
     * @param bool $enableCancel EnableCancel
1124
     *
1125
     * @return void
1126
     */
1127
    public function setEnableCancel($enableCancel)
1128
    {
1129
        $this->enableCancel = $enableCancel;
1130
    }
1131
1132
    /**
1133
     * Returns if registration can be canceled
1134
     *
1135
     * @return bool
1136
     */
1137
    public function getEnableCancel()
1138
    {
1139
        return $this->enableCancel;
1140
    }
1141
1142
    /**
1143
     * Sets the cancel deadline
1144
     *
1145
     * @param \DateTime $cancelDeadline CancelDeadline
1146
     *
1147
     * @return void
1148
     */
1149
    public function setCancelDeadline(\DateTime $cancelDeadline)
1150
    {
1151
        $this->cancelDeadline = $cancelDeadline;
1152
    }
1153
1154
    /**
1155
     * Returns the cancel deadline
1156
     *
1157
     * @return \DateTime
1158
     */
1159
    public function getCancelDeadline()
1160
    {
1161
        return $this->cancelDeadline;
1162
    }
1163
1164
    /**
1165
     * Returns if autoconfirmation is enabled
1166
     *
1167
     * @return bool
1168
     */
1169
    public function getEnableAutoconfirm()
1170
    {
1171
        return $this->enableAutoconfirm;
1172
    }
1173
1174
    /**
1175
     * Sets enable autoconfirm
1176
     *
1177
     * @param bool $enableAutoconfirm
1178
     * @return void
1179
     */
1180
    public function setEnableAutoconfirm($enableAutoconfirm)
1181
    {
1182
        $this->enableAutoconfirm = $enableAutoconfirm;
1183
    }
1184
1185
    /**
1186
     * Returns uniqueEmailCheck
1187
     *
1188
     * @return bool
1189
     */
1190
    public function getUniqueEmailCheck()
1191
    {
1192
        return $this->uniqueEmailCheck;
1193
    }
1194
1195
    /**
1196
     * Sets UniqueEmailCheck
1197
     *
1198
     * @param bool $uniqueEmailCheck
1199
     * @return void
1200
     */
1201
    public function setUniqueEmailCheck($uniqueEmailCheck)
1202
    {
1203
        $this->uniqueEmailCheck = $uniqueEmailCheck;
1204
    }
1205
1206
    /**
1207
     * Returns price options
1208
     *
1209
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
1210
     */
1211
    public function getPriceOptions()
1212
    {
1213
        return $this->priceOptions;
1214
    }
1215
1216
    /**
1217
     * Sets price options
1218
     *
1219
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $priceOptions
1220
     * @return void
1221
     */
1222
    public function setPriceOptions($priceOptions)
1223
    {
1224
        $this->priceOptions = $priceOptions;
1225
    }
1226
1227
    /**
1228
     * Adds a price option
1229
     *
1230
     * @param \DERHANSEN\SfEventMgt\Domain\Model\PriceOption $priceOption Price option
1231
     *
1232
     * @return void
1233
     */
1234
    public function addPriceOptions(\DERHANSEN\SfEventMgt\Domain\Model\PriceOption $priceOption)
1235
    {
1236
        $this->priceOptions->attach($priceOption);
1237
    }
1238
1239
    /**
1240
     * Removes a Registration
1241
     *
1242
     * @param \DERHANSEN\SfEventMgt\Domain\Model\PriceOption $priceOption Price option
1243
     *
1244
     * @return void
1245
     */
1246
    public function removePriceOptions(\DERHANSEN\SfEventMgt\Domain\Model\PriceOption $priceOption)
1247
    {
1248
        $this->priceOptions->detach($priceOption);
1249
    }
1250
1251
    /**
1252
     * Returns all active price options sorted by date ASC
1253
     *
1254
     * @return array
1255
     */
1256
    public function getActivePriceOptions()
1257
    {
1258
        $activePriceOptions = [];
1259
        if ($this->getPriceOptions()) {
1260
            $compareDate = new \DateTime('today midnight');
1261
            foreach ($this->getPriceOptions() as $priceOption) {
1262
                if ($priceOption->getValidUntil() >= $compareDate) {
1263
                    $activePriceOptions[$priceOption->getValidUntil()->getTimestamp()] = $priceOption;
1264
                }
1265
            }
1266
        }
1267
        ksort($activePriceOptions);
1268
1269
        return $activePriceOptions;
1270
    }
1271
1272
    /**
1273
     * Returns the current price of the event respecting possible price options
1274
     *
1275
     * @return float
1276
     */
1277
    public function getCurrentPrice()
1278
    {
1279
        $activePriceOptions = $this->getActivePriceOptions();
1280
        if (count($activePriceOptions) >= 1) {
1281
            // Sort active price options and return first element
1282
            return reset($activePriceOptions)->getPrice();
1283
        }
1284
        // Just return the price field
1285
        return $this->price;
1286
    }
1287
1288
    /**
1289
     * Returns registrationWaitlist
1290
     *
1291
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
1292
     */
1293
    public function getRegistrationWaitlist()
1294
    {
1295
        // Since TYPO3 9.5 (#82363)
1296
        if ($GLOBALS['TSFE']->sys_language_uid > 0) {
1297
            return $this->getRegistrations(true);
1298
        }
1299
1300
        return $this->registrationWaitlist;
1301
    }
1302
1303
    /**
1304
     * Sets registrationWaitlist
1305
     *
1306
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $registration Registration
1307
     *
1308
     * @return void
1309
     */
1310
    public function setRegistrationWaitlist(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $registration)
1311
    {
1312
        $this->registrationWaitlist = $registration;
1313
    }
1314
1315
    /**
1316
     * Adds a Registration to the waitlist
1317
     *
1318
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
1319
     *
1320
     * @return void
1321
     */
1322
    public function addRegistrationWaitlist(\DERHANSEN\SfEventMgt\Domain\Model\Registration $registration)
1323
    {
1324
        $this->registrationWaitlist->attach($registration);
1325
    }
1326
1327
    /**
1328
     * Removes a Registration from the waitlist
1329
     *
1330
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registrationToRemove Registration
1331
     *
1332
     * @return void
1333
     */
1334
    public function removeRegistrationWaitlist(\DERHANSEN\SfEventMgt\Domain\Model\Registration $registrationToRemove)
1335
    {
1336
        $this->registrationWaitlist->detach($registrationToRemove);
1337
    }
1338
1339
    /**
1340
     * Returns, if cancellation for registrations of the event is possible
1341
     *
1342
     * @return bool
1343
     */
1344
    public function getCancellationPossible()
1345
    {
1346
        return ($this->getEnableCancel() && $this->getCancelDeadline() > new \DateTime()) ||
1347
            ($this->getEnableCancel() && $this->getCancelDeadline() === null);
1348
    }
1349
1350
    /**
1351
     * Returns speaker
1352
     *
1353
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
1354
     */
1355
    public function getSpeaker()
1356
    {
1357
        return $this->speaker;
1358
    }
1359
1360
    /**
1361
     * Sets speaker
1362
     *
1363
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $speaker
1364
     * @return void
1365
     */
1366
    public function setSpeaker($speaker)
1367
    {
1368
        $this->speaker = $speaker;
1369
    }
1370
1371
    /**
1372
     * Adds a speaker
1373
     *
1374
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Speaker $speaker
1375
     *
1376
     * @return void
1377
     */
1378
    public function addSpeaker(\DERHANSEN\SfEventMgt\Domain\Model\Speaker $speaker)
1379
    {
1380
        $this->speaker->attach($speaker);
1381
    }
1382
1383
    /**
1384
     * Removes a speaker
1385
     *
1386
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Speaker $speaker
1387
     *
1388
     * @return void
1389
     */
1390
    public function removeSpeaker(\DERHANSEN\SfEventMgt\Domain\Model\Speaker $speaker)
1391
    {
1392
        $this->speaker->detach($speaker);
1393
    }
1394
1395
    /**
1396
     * Returns registrationFields
1397
     *
1398
     * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
1399
     */
1400
    public function getRegistrationFields()
1401
    {
1402
        return $this->registrationFields;
1403
    }
1404
1405
    /**
1406
     * Sets registrationWaitlist
1407
     *
1408
     * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $registrationFields
1409
     *
1410
     * @return void
1411
     */
1412
    public function setRegistrationFields(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $registrationFields)
1413
    {
1414
        $this->registrationFields = $registrationFields;
1415
    }
1416
1417
    /**
1418
     * Adds a registrationField
1419
     *
1420
     * @param Field $registrationField
1421
     */
1422
    public function addRegistrationFields(Field $registrationField)
1423
    {
1424
        $this->registrationFields->attach($registrationField);
1425
    }
1426
1427
    /**
1428
     * Removed a registrationField
1429
     *
1430
     * @param Field $registrationField
1431
     */
1432
    public function removeRegistrationFields(Field $registrationField)
1433
    {
1434
        $this->registrationFields->detach($registrationField);
1435
    }
1436
1437
    /**
1438
     * Returns an array with registration field uids
1439
     *
1440
     * @return array
1441
     */
1442
    public function getRegistrationFieldsUids()
1443
    {
1444
        $result = [];
1445
        foreach ($this->registrationFields as $registrationField) {
1446
            $result[] = $registrationField->getUid();
1447
        }
1448
1449
        return $result;
1450
    }
1451
1452
    /**
1453
     * Returns an array with registration field uids and titles
1454
     * [uid => title]
1455
     *
1456
     * @return array
1457
     */
1458
    public function getRegistrationFieldUidsWithTitle()
1459
    {
1460
        $result = [];
1461
        foreach ($this->registrationFields as $registrationField) {
1462
            $result[$registrationField->getUid()] = $registrationField->getTitle();
1463
        }
1464
1465
        return $result;
1466
    }
1467
1468
    /**
1469
     * Returns an objectStorage object holding all registrations in the default language.
1470
     * Ensures expected behavior of getRegistration() and getRegistrationWaitlist() since TYPO3 issue #82363
1471
     *
1472
     * @param bool $waitlist
1473
     * @return ObjectStorage
1474
     */
1475
    protected function getRegistrations(bool $waitlist = false)
1476
    {
1477
        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
1478
        $result = $objectManager->get(ObjectStorage::class);
1479
        $registrationRepository = $objectManager->get(RegistrationRepository::class);
1480
        $registrations = $registrationRepository->findByEventAndWaitlist($this, $waitlist);
1481
        foreach ($registrations as $registration) {
1482
            $result->attach($registration);
1483
        }
1484
        return $result;
1485
    }
1486
}
1487