Completed
Push — feature/spam-protection ( be04ad )
by Torben
02:50
created

Event::getSpamCheckChallenge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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