Completed
Push — master ( c18e86...b01b7f )
by Torben
04:02
created

Event::getEndsSameDay()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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