Completed
Push — 4.x ( d7e831...9f31fb )
by Torben
42:10
created

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