|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable; |
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
8
|
|
|
use Doctrine\Common\Collections\Collection; |
|
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
10
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
11
|
|
|
use Ramsey\Uuid\Uuid; |
|
12
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
|
13
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
14
|
|
|
|
|
15
|
|
|
#[Auditable] |
|
16
|
|
|
#[UniqueEntity(fields: ['externalId'])] |
|
17
|
|
|
#[ORM\Entity] |
|
18
|
|
|
class Substitution { |
|
19
|
|
|
|
|
20
|
|
|
use IdTrait; |
|
21
|
|
|
use UuidTrait; |
|
22
|
|
|
|
|
23
|
|
|
#[ORM\Column(type: 'string', unique: true)] |
|
24
|
|
|
private ?string $externalId = null; |
|
25
|
|
|
|
|
26
|
|
|
#[Assert\NotNull] |
|
27
|
|
|
#[ORM\Column(type: 'date')] |
|
28
|
|
|
private ?DateTime $date = null; |
|
29
|
|
|
|
|
30
|
|
|
#[Assert\GreaterThan(0)] |
|
31
|
|
|
#[ORM\Column(type: 'integer')] |
|
32
|
|
|
private int $lessonStart = 0; |
|
33
|
|
|
|
|
34
|
|
|
#[Assert\GreaterThan(0)] |
|
35
|
|
|
#[Assert\GreaterThanOrEqual(propertyPath: 'lessonStart')] |
|
36
|
|
|
#[ORM\Column(type: 'integer')] |
|
37
|
|
|
private int $lessonEnd = 0; |
|
38
|
|
|
|
|
39
|
|
|
#[ORM\Column(type: 'boolean')] |
|
40
|
|
|
private bool $startsBefore = false; |
|
41
|
|
|
|
|
42
|
|
|
#[ORM\Column(type: 'string', nullable: true)] |
|
43
|
|
|
private ?string $type = null; |
|
44
|
|
|
|
|
45
|
|
|
#[ORM\Column(type: 'string', nullable: true)] |
|
46
|
|
|
private ?string $subject = null; |
|
47
|
|
|
|
|
48
|
|
|
#[ORM\Column(type: 'string', nullable: true)] |
|
49
|
|
|
private ?string $replacementSubject = null; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var Collection<Teacher> |
|
53
|
|
|
*/ |
|
54
|
|
|
#[ORM\JoinTable(name: 'substitution_teachers')] |
|
55
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
56
|
|
|
#[ORM\InverseJoinColumn(onDelete: 'CASCADE')] |
|
57
|
|
|
#[ORM\ManyToMany(targetEntity: Teacher::class)] |
|
58
|
|
|
private $teachers; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var Collection<Teacher> |
|
62
|
|
|
*/ |
|
63
|
|
|
#[ORM\JoinTable(name: 'substitution_replacement_teachers')] |
|
64
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
65
|
|
|
#[ORM\InverseJoinColumn(onDelete: 'CASCADE')] |
|
66
|
|
|
#[ORM\ManyToMany(targetEntity: Teacher::class)] |
|
67
|
|
|
private $replacementTeachers; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var Collection<Room> |
|
71
|
|
|
*/ |
|
72
|
|
|
#[ORM\JoinTable(name: 'substitution_rooms')] |
|
73
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
74
|
|
|
#[ORM\InverseJoinColumn(onDelete: 'CASCADE')] |
|
75
|
|
|
#[ORM\ManyToMany(targetEntity: Room::class)] |
|
76
|
|
|
#[ORM\OrderBy(['name' => 'asc'])] |
|
77
|
|
|
private $rooms; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var Collection<Room> |
|
81
|
|
|
*/ |
|
82
|
|
|
#[ORM\JoinTable(name: 'substitution_replacement_rooms')] |
|
83
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
84
|
|
|
#[ORM\InverseJoinColumn(onDelete: 'CASCADE')] |
|
85
|
|
|
#[ORM\ManyToMany(targetEntity: Room::class)] |
|
86
|
|
|
#[ORM\OrderBy(['name' => 'asc'])] |
|
87
|
|
|
private $replacementRooms; |
|
88
|
|
|
|
|
89
|
|
|
#[ORM\Column(type: 'string', nullable: true, options: ['comment' => 'Plain room name in case room resolve is not possible when importing substitutions.'])] |
|
90
|
|
|
private ?string $roomName = null; |
|
91
|
|
|
|
|
92
|
|
|
#[ORM\Column(type: 'string', nullable: true, options: ['comment' => 'Plain room name in case room resolve is not possible when importing substitutions.'])] |
|
93
|
|
|
private ?string $replacementRoomName = null; |
|
94
|
|
|
|
|
95
|
|
|
#[ORM\Column(type: 'string', nullable: true)] |
|
96
|
|
|
private ?string $remark = null; |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @var ArrayCollection<StudyGroup> |
|
100
|
|
|
*/ |
|
101
|
|
|
#[ORM\JoinTable(name: 'substitution_studygroups')] |
|
102
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
103
|
|
|
#[ORM\InverseJoinColumn(onDelete: 'CASCADE')] |
|
104
|
|
|
#[ORM\ManyToMany(targetEntity: StudyGroup::class)] |
|
105
|
|
|
private $studyGroups; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @var ArrayCollection<StudyGroup> |
|
109
|
|
|
*/ |
|
110
|
|
|
#[ORM\JoinTable(name: 'substitution_replacement_studygroups')] |
|
111
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
112
|
|
|
#[ORM\InverseJoinColumn(onDelete: 'CASCADE')] |
|
113
|
|
|
#[ORM\ManyToMany(targetEntity: StudyGroup::class)] |
|
114
|
|
|
private $replacementStudyGroups; |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @var ArrayCollection<Grade> |
|
118
|
|
|
*/ |
|
119
|
|
|
#[ORM\JoinTable(name: 'substitution_replacement_grades')] |
|
120
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
121
|
|
|
#[ORM\InverseJoinColumn(onDelete: 'CASCADE')] |
|
122
|
|
|
#[ORM\ManyToMany(targetEntity: Grade::class)] |
|
123
|
|
|
private $replacementGrades; |
|
124
|
|
|
|
|
125
|
|
|
#[Gedmo\Timestampable(on: 'create')] |
|
126
|
|
|
#[ORM\Column(type: 'datetime')] |
|
127
|
|
|
private DateTime $createdAt; |
|
128
|
|
|
|
|
129
|
|
|
public function __construct() { |
|
130
|
|
|
$this->uuid = Uuid::uuid4(); |
|
131
|
|
|
|
|
132
|
|
|
$this->teachers = new ArrayCollection(); |
|
133
|
|
|
$this->replacementTeachers = new ArrayCollection(); |
|
134
|
|
|
$this->rooms = new ArrayCollection(); |
|
135
|
|
|
$this->replacementRooms = new ArrayCollection(); |
|
136
|
|
|
$this->studyGroups = new ArrayCollection(); |
|
137
|
|
|
$this->replacementStudyGroups = new ArrayCollection(); |
|
138
|
|
|
$this->replacementGrades = new ArrayCollection(); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getExternalId(): ?string { |
|
142
|
|
|
return $this->externalId; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function setExternalId(?string $externalId): Substitution { |
|
146
|
|
|
$this->externalId = $externalId; |
|
147
|
|
|
return $this; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
public function getDate(): ?DateTime { |
|
151
|
|
|
return $this->date; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function setDate(?DateTime $date): Substitution { |
|
155
|
|
|
$this->date = $date; |
|
156
|
|
|
return $this; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
public function getLessonStart(): int { |
|
160
|
|
|
return $this->lessonStart; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function setLessonStart(int $lessonStart): Substitution { |
|
164
|
|
|
$this->lessonStart = $lessonStart; |
|
165
|
|
|
return $this; |
|
166
|
|
|
} |
|
167
|
2 |
|
|
|
168
|
2 |
|
public function getLessonEnd(): int { |
|
169
|
|
|
return $this->lessonEnd; |
|
170
|
2 |
|
} |
|
171
|
2 |
|
|
|
172
|
2 |
|
public function setLessonEnd(int $lessonEnd): Substitution { |
|
173
|
2 |
|
$this->lessonEnd = $lessonEnd; |
|
174
|
2 |
|
return $this; |
|
175
|
2 |
|
} |
|
176
|
2 |
|
|
|
177
|
2 |
|
public function startsBefore(): bool { |
|
178
|
|
|
return $this->startsBefore; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function setStartsBefore(bool $startsBefore): Substitution { |
|
182
|
|
|
$this->startsBefore = $startsBefore; |
|
183
|
|
|
return $this; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
public function getType(): ?string { |
|
187
|
|
|
return $this->type; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
1 |
|
public function setType(?string $type): Substitution { |
|
191
|
1 |
|
$this->type = $type; |
|
192
|
1 |
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function getSubject(): ?string { |
|
196
|
|
|
return $this->subject; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public function setSubject(?string $subject): Substitution { |
|
200
|
|
|
$this->subject = $subject; |
|
201
|
|
|
return $this; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function getReplacementSubject(): ?string { |
|
205
|
|
|
return $this->replacementSubject; |
|
206
|
1 |
|
} |
|
207
|
1 |
|
|
|
208
|
1 |
|
public function setReplacementSubject(?string $replacementSubject): Substitution { |
|
209
|
|
|
$this->replacementSubject = $replacementSubject; |
|
210
|
|
|
return $this; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
1 |
|
* @return Collection<Teacher>s |
|
215
|
1 |
|
*/ |
|
216
|
|
|
public function getTeachers(): Collection { |
|
217
|
|
|
return $this->teachers; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
public function addTeacher(Teacher $teacher): void { |
|
221
|
|
|
$this->teachers->add($teacher); |
|
222
|
2 |
|
} |
|
223
|
2 |
|
|
|
224
|
2 |
|
public function removeTeacher(Teacher $teacher): void { |
|
225
|
|
|
$this->teachers->removeElement($teacher); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* @return Collection<Teacher> |
|
230
|
|
|
*/ |
|
231
|
|
|
public function getReplacementTeachers(): Collection { |
|
232
|
|
|
return $this->replacementTeachers; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function addReplacementTeacher(Teacher $teacher): void { |
|
236
|
|
|
$this->replacementTeachers->add($teacher); |
|
237
|
|
|
} |
|
238
|
2 |
|
|
|
239
|
2 |
|
public function removeReplacementTeacher(Teacher $teacher): void { |
|
240
|
2 |
|
$this->replacementTeachers->removeElement($teacher); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
public function addRoom(Room $room): void { |
|
244
|
|
|
$this->rooms->add($room); |
|
245
|
|
|
} |
|
246
|
1 |
|
|
|
247
|
1 |
|
public function removeRoom(Room $room): void { |
|
248
|
|
|
$this->rooms->removeElement($room); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
public function getRooms(): Collection { |
|
252
|
|
|
return $this->rooms; |
|
253
|
|
|
} |
|
254
|
1 |
|
|
|
255
|
1 |
|
public function addReplacementRoom(Room $room): void { |
|
256
|
1 |
|
$this->replacementRooms->add($room); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
public function removeReplacementRoom(Room $room): void { |
|
260
|
|
|
$this->replacementRooms->removeElement($room); |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
public function getReplacementRooms(): Collection { |
|
264
|
|
|
return $this->replacementRooms; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
public function getRoomsAsString(): ?string { |
|
269
|
|
|
if($this->getRooms()->count() > 0) { |
|
270
|
|
|
return implode(', ', $this->getRooms()->map(fn(Room $room) => $room->getName())->toArray()); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
return $this->getRoomName(); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
public function getReplacementRoomsAsString(): ?string { |
|
277
|
|
|
if($this->getReplacementRooms()->count() > 0) { |
|
278
|
1 |
|
return implode(', ', $this->getReplacementRooms()->map(fn(Room $room) => $room->getName())->toArray()); |
|
279
|
1 |
|
} |
|
280
|
|
|
|
|
281
|
|
|
return $this->getReplacementRoomName(); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
public function getRoomName(): ?string { |
|
285
|
|
|
return $this->roomName; |
|
286
|
1 |
|
} |
|
287
|
1 |
|
|
|
288
|
1 |
|
public function setRoomName(?string $roomName): Substitution { |
|
289
|
|
|
$this->roomName = $roomName; |
|
290
|
|
|
return $this; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
public function getReplacementRoomName(): ?string { |
|
294
|
|
|
return $this->replacementRoomName; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
public function setReplacementRoomName(?string $replacementRoomName): Substitution { |
|
298
|
|
|
$this->replacementRoomName = $replacementRoomName; |
|
299
|
|
|
return $this; |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
public function getRemark(): ?string { |
|
303
|
|
|
return $this->remark; |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
public function setRemark(?string $remark): Substitution { |
|
307
|
|
|
$this->remark = $remark; |
|
308
|
|
|
return $this; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
public function addStudyGroup(StudyGroup $studyGroup) { |
|
312
|
|
|
$this->studyGroups->add($studyGroup); |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
public function removeStudyGroup(StudyGroup $studyGroup) { |
|
316
|
|
|
$this->studyGroups->removeElement($studyGroup); |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* @return Collection<StudyGroup> |
|
321
|
|
|
*/ |
|
322
|
|
|
public function getStudyGroups(): Collection { |
|
323
|
|
|
return $this->studyGroups; |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
public function addReplacementStudyGroup(StudyGroup $studyGroup) { |
|
327
|
|
|
$this->replacementStudyGroups->add($studyGroup); |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
public function removeReplacementStudyGroup(StudyGroup $studyGroup) { |
|
331
|
|
|
$this->replacementStudyGroups->removeElement($studyGroup); |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
/** |
|
335
|
|
|
* @return Collection<StudyGroup> |
|
336
|
|
|
*/ |
|
337
|
|
|
public function getReplacementStudyGroups(): Collection { |
|
338
|
|
|
return $this->replacementStudyGroups; |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
public function addReplacementGrade(Grade $grade): void { |
|
342
|
|
|
$this->replacementGrades->add($grade); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
public function removeReplacementGrade(Grade $grade): void { |
|
346
|
|
|
$this->replacementGrades->removeElement($grade); |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
public function getReplacementGrades(): Collection { |
|
350
|
|
|
return $this->replacementGrades; |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* @return Grade[] |
|
355
|
|
|
*/ |
|
356
|
|
|
public function getGrades(): array { |
|
357
|
|
|
$grades = [ ]; |
|
358
|
|
|
|
|
359
|
|
|
if($this->getReplacementGrades()->count() > 0) { |
|
360
|
|
|
return $this->getReplacementGrades()->toArray(); |
|
361
|
|
|
} |
|
362
|
|
|
|
|
363
|
|
|
/** @var StudyGroup $studyGroup */ |
|
364
|
|
|
foreach($this->getStudyGroups() as $studyGroup) { |
|
365
|
|
|
/** @var Grade $grade */ |
|
366
|
|
|
foreach($studyGroup->getGrades() as $grade) { |
|
367
|
|
|
if(!in_array($grade, $grades)) { |
|
368
|
|
|
$grades[] = $grade; |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
/** @var StudyGroup $studyGroup */ |
|
374
|
|
|
foreach($this->getReplacementStudyGroups() as $studyGroup) { |
|
375
|
|
|
/** @var Grade $grade */ |
|
376
|
|
|
foreach($studyGroup->getGrades() as $grade) { |
|
377
|
|
|
if(!in_array($grade, $grades)) { |
|
378
|
|
|
$grades[] = $grade; |
|
379
|
|
|
} |
|
380
|
|
|
} |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
return $grades; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
public function clone() { |
|
387
|
|
|
$clone = new self(); |
|
388
|
|
|
|
|
389
|
|
|
$clone->setDate($this->getDate()); |
|
390
|
|
|
$clone->setType($this->getType()); |
|
391
|
|
|
$clone->setExternalId($this->getExternalId()); |
|
392
|
|
|
$clone->setSubject($this->getSubject()); |
|
393
|
|
|
$clone->setReplacementSubject($this->getReplacementSubject()); |
|
394
|
|
|
$clone->setRoomName($this->getRoomName()); |
|
395
|
|
|
$clone->setReplacementRoomName($this->getReplacementRoomName()); |
|
396
|
|
|
$clone->setLessonStart($this->getLessonStart()); |
|
397
|
|
|
$clone->setLessonEnd($this->getLessonEnd()); |
|
398
|
|
|
$clone->setStartsBefore($this->startsBefore()); |
|
399
|
|
|
$clone->setRemark($this->getRemark()); |
|
400
|
|
|
|
|
401
|
|
|
foreach($this->getTeachers() as $teacher) { |
|
402
|
|
|
$clone->addTeacher($teacher); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
foreach($this->getReplacementTeachers() as $teacher) { |
|
406
|
|
|
$clone->addReplacementTeacher($teacher); |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
foreach($this->getStudyGroups() as $studyGroup) { |
|
410
|
|
|
$clone->addStudyGroup($studyGroup); |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
foreach($this->getReplacementStudyGroups() as $studyGroup) { |
|
414
|
|
|
$clone->addReplacementStudyGroup($studyGroup); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
foreach($this->getRooms() as $room) { |
|
418
|
|
|
$clone->addRoom($room); |
|
419
|
1 |
|
} |
|
420
|
1 |
|
|
|
421
|
|
|
foreach($this->getReplacementRooms() as $room) { |
|
422
|
|
|
$clone->addReplacementRoom($room); |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
foreach($this->getReplacementGrades() as $grade) { |
|
426
|
|
|
$clone->addReplacementGrade($grade); |
|
427
|
1 |
|
} |
|
428
|
1 |
|
|
|
429
|
1 |
|
return $clone; |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
public function getCreatedAt(): DateTime { |
|
433
|
|
|
return $this->createdAt; |
|
434
|
|
|
} |
|
435
|
|
|
} |