1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the mangel.io 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\IdTrait; |
16
|
|
|
use App\Entity\Traits\TimeTrait; |
17
|
|
|
use App\Enum\ArrivalOrDeparture; |
18
|
|
|
use App\Enum\ReviewProgress; |
19
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
20
|
|
|
use Doctrine\ORM\Mapping as ORM; |
21
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ORM\Entity() |
25
|
|
|
* @ORM\HasLifecycleCallbacks |
26
|
|
|
*/ |
27
|
|
|
class TravelGroup extends BaseEntity |
28
|
|
|
{ |
29
|
|
|
use IdTrait; |
30
|
|
|
use TimeTrait; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var int |
34
|
|
|
* |
35
|
|
|
* @Groups({"travel-group-export"}) |
36
|
|
|
* @ORM\Column(type="integer") |
37
|
|
|
*/ |
38
|
|
|
private $arrivalOrDeparture = ArrivalOrDeparture::ARRIVAL; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string|null |
42
|
|
|
* |
43
|
|
|
* @Groups({"travel-group-export"}) |
44
|
|
|
* @ORM\Column(type="string", nullable=true) |
45
|
|
|
*/ |
46
|
|
|
private $location; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var \DateTime|null |
50
|
|
|
* |
51
|
|
|
* @Groups({"travel-group-export"}) |
52
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
53
|
|
|
*/ |
54
|
|
|
private $dateTime; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string|null |
58
|
|
|
* |
59
|
|
|
* @Groups({"travel-group-export"}) |
60
|
|
|
* @ORM\Column(type="string", nullable=true) |
61
|
|
|
*/ |
62
|
|
|
private $provider; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var string|null |
66
|
|
|
* |
67
|
|
|
* @Groups({"travel-group-export"}) |
68
|
|
|
* @ORM\Column(type="string", nullable=true) |
69
|
|
|
*/ |
70
|
|
|
private $tripNumber; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string|null |
74
|
|
|
* |
75
|
|
|
* @Groups({"travel-group-export"}) |
76
|
|
|
* @ORM\Column(type="string", nullable=true) |
77
|
|
|
*/ |
78
|
|
|
private $description; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var int |
82
|
|
|
* |
83
|
|
|
* @Groups({"travel-group-export"}) |
84
|
|
|
* @ORM\Column(type="integer") |
85
|
|
|
*/ |
86
|
|
|
private $reviewProgress = ReviewProgress::NOT_EDITED; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var Delegation |
90
|
|
|
* |
91
|
|
|
* @Groups({"travel-group-export"}) |
92
|
|
|
* @ORM\ManyToOne (targetEntity="App\Entity\Delegation", inversedBy="travelGroups") |
93
|
|
|
*/ |
94
|
|
|
private $delegation; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var Participant[]|ArrayCollection |
98
|
|
|
* |
99
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Participant", mappedBy="arrivalTravelGroup") |
100
|
|
|
* @ORM\OrderBy({"role" = "ASC", "givenName" = "ASC"}) |
101
|
|
|
*/ |
102
|
|
|
private $arrivalParticipants; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var Participant[]|ArrayCollection |
106
|
|
|
* |
107
|
|
|
* @ORM\OneToMany(targetEntity="App\Entity\Participant", mappedBy="departureTravelGroup") |
108
|
|
|
* @ORM\OrderBy({"role" = "ASC", "givenName" = "ASC"}) |
109
|
|
|
*/ |
110
|
|
|
private $departureParticipants; |
111
|
|
|
|
112
|
|
|
public function __construct() |
113
|
|
|
{ |
114
|
|
|
$this->arrivalParticipants = new ArrayCollection(); |
115
|
|
|
$this->departureParticipants = new ArrayCollection(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getArrivalOrDeparture(): int |
119
|
|
|
{ |
120
|
|
|
return $this->arrivalOrDeparture; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setArrivalOrDeparture(int $arrivalOrDeparture): void |
124
|
|
|
{ |
125
|
|
|
$this->arrivalOrDeparture = $arrivalOrDeparture; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function getLocation(): ?string |
129
|
|
|
{ |
130
|
|
|
return $this->location; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function setLocation(?string $location): void |
134
|
|
|
{ |
135
|
|
|
$this->location = $location; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getDateTime(): ?\DateTime |
139
|
|
|
{ |
140
|
|
|
return $this->dateTime; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function setDateTime(?\DateTime $dateTime): void |
144
|
|
|
{ |
145
|
|
|
$this->dateTime = $dateTime; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getProvider(): ?string |
149
|
|
|
{ |
150
|
|
|
return $this->provider; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function setProvider(?string $provider): void |
154
|
|
|
{ |
155
|
|
|
$this->provider = $provider; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function getTripNumber(): ?string |
159
|
|
|
{ |
160
|
|
|
return $this->tripNumber; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function setTripNumber(?string $tripNumber): void |
164
|
|
|
{ |
165
|
|
|
$this->tripNumber = $tripNumber; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function getDescription(): ?string |
169
|
|
|
{ |
170
|
|
|
return $this->description; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function setDescription(?string $description): void |
174
|
|
|
{ |
175
|
|
|
$this->description = $description; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function getDelegation(): Delegation |
179
|
|
|
{ |
180
|
|
|
return $this->delegation; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function setDelegation(Delegation $delegation): void |
184
|
|
|
{ |
185
|
|
|
$this->delegation = $delegation; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function getParticipants() |
189
|
|
|
{ |
190
|
|
|
return ArrivalOrDeparture::ARRIVAL === $this->arrivalOrDeparture ? $this->getArrivalParticipants() : $this->getDepartureParticipants(); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function addParticipant(Participant $participant) |
194
|
|
|
{ |
195
|
|
|
if (ArrivalOrDeparture::ARRIVAL === self::getArrivalOrDeparture()) { |
|
|
|
|
196
|
|
|
$this->arrivalParticipants->add($participant); |
197
|
|
|
$participant->setArrivalTravelGroup($this); |
198
|
|
|
} else { |
199
|
|
|
$this->departureParticipants->add($participant); |
200
|
|
|
$participant->setDepartureTravelGroup($this); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function removeParticipant($participant) |
205
|
|
|
{ |
206
|
|
|
if (ArrivalOrDeparture::ARRIVAL === self::getArrivalOrDeparture()) { |
|
|
|
|
207
|
|
|
$this->arrivalParticipants->removeElement($participant); |
208
|
|
|
$participant->setArrivalTravelGroup(null); |
209
|
|
|
} else { |
210
|
|
|
$this->departureParticipants->removeElement($participant); |
211
|
|
|
$participant->setDepartureTravelGroup(null); |
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @Groups({"travel-group-export"}) |
217
|
|
|
*/ |
218
|
|
|
public function getParticipantCount() |
219
|
|
|
{ |
220
|
|
|
return count($this->getParticipants()); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function setParticipants($participants) |
224
|
|
|
{ |
225
|
|
|
if (ArrivalOrDeparture::ARRIVAL === self::getArrivalOrDeparture()) { |
|
|
|
|
226
|
|
|
$this->arrivalParticipants = $participants; |
227
|
|
|
} else { |
228
|
|
|
$this->departureParticipants = $participants; |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @return Participant[]|ArrayCollection |
234
|
|
|
*/ |
235
|
|
|
public function getArrivalParticipants() |
236
|
|
|
{ |
237
|
|
|
return $this->arrivalParticipants; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @return Participant[]|ArrayCollection |
242
|
|
|
*/ |
243
|
|
|
public function getDepartureParticipants() |
244
|
|
|
{ |
245
|
|
|
return $this->departureParticipants; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
public function getReviewProgress(): int |
249
|
|
|
{ |
250
|
|
|
return $this->reviewProgress; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
public function setReviewProgress(int $reviewProgress): void |
254
|
|
|
{ |
255
|
|
|
$this->reviewProgress = $reviewProgress; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function complete() |
259
|
|
|
{ |
260
|
|
|
return !empty($this->location) && |
261
|
|
|
!empty($this->dateTime) && |
262
|
|
|
!empty($this->provider) && |
263
|
|
|
!empty($this->tripNumber); |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|