|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the TheAlternativeZurich/events project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Florian Moser <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace App\Entity; |
|
13
|
|
|
|
|
14
|
|
|
use App\Entity\Base\BaseEntity; |
|
15
|
|
|
use App\Entity\Traits\ContactInformationTrait; |
|
16
|
|
|
use App\Entity\Traits\IdTrait; |
|
17
|
|
|
use App\Entity\Traits\TimeTrait; |
|
18
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
19
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\RegistrationRepository") |
|
23
|
|
|
* @ORM\HasLifecycleCallbacks |
|
24
|
|
|
*/ |
|
25
|
|
|
class Registration extends BaseEntity |
|
26
|
|
|
{ |
|
27
|
|
|
use IdTrait; |
|
28
|
|
|
use TimeTrait; |
|
29
|
|
|
use ContactInformationTrait; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var bool |
|
33
|
|
|
* |
|
34
|
|
|
* @ORM\Column(type="boolean") |
|
35
|
|
|
*/ |
|
36
|
|
|
private $isOrganizer = false; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var int |
|
40
|
|
|
* |
|
41
|
|
|
* @ORM\Column(type="integer") |
|
42
|
|
|
*/ |
|
43
|
|
|
private $number; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var Event |
|
47
|
|
|
* |
|
48
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Event", inversedBy="registrations") |
|
49
|
|
|
*/ |
|
50
|
|
|
private $event; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var User |
|
54
|
|
|
* |
|
55
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="registrations") |
|
56
|
|
|
*/ |
|
57
|
|
|
private $user; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var Attendance[]|ArrayCollection |
|
61
|
|
|
* |
|
62
|
|
|
* @ORM\OneToMany (targetEntity="Attendance", mappedBy="registration") |
|
63
|
|
|
*/ |
|
64
|
|
|
private $attendances; |
|
65
|
|
|
|
|
66
|
|
|
public function __construct() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->attendances = new ArrayCollection(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public static function createFromUser(Event $event, User $user, bool $isOrganizer = false) |
|
72
|
|
|
{ |
|
73
|
|
|
$registration = new Registration(); |
|
74
|
|
|
$registration->event = $event; |
|
75
|
|
|
$registration->user = $user; |
|
76
|
|
|
$registration->isOrganizer = $isOrganizer; |
|
77
|
|
|
$registration->fromOtherContactInformation($user); |
|
78
|
|
|
|
|
79
|
|
|
return $registration; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function setRelations(Event $event, User $user) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->event = $event; |
|
85
|
|
|
$this->user = $user; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function setNumber(int $number) |
|
89
|
|
|
{ |
|
90
|
|
|
$this->number = $number; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getIsOrganizer(): bool |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->isOrganizer; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function setIsOrganizer(bool $isOrganizer): void |
|
99
|
|
|
{ |
|
100
|
|
|
$this->isOrganizer = $isOrganizer; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return Event |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getEvent() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->event; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return User |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getUser() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->user; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function getNumber(): int |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->number; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function canDeregister(): bool |
|
125
|
|
|
{ |
|
126
|
|
|
if ($this->attendances->count() > 0) { |
|
127
|
|
|
return false; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return $this->event->isRegistrationOpen(); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return Attendance[]|ArrayCollection |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getAttendances() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->attendances; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getActiveAttendance(): ?Attendance |
|
142
|
|
|
{ |
|
143
|
|
|
foreach ($this->attendances as $attendance) { |
|
144
|
|
|
if (!$attendance->getLeaveDate()) { |
|
145
|
|
|
return $attendance; |
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
return null; |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|