Completed
Push — 4.x ( 9c8315...ff2948 )
by Torben
74:50 queued 74:47
created

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