|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use App\Validator\DateLessonGreaterThan; |
|
6
|
|
|
use App\Validator\DateLessonInSection; |
|
7
|
|
|
use App\Validator\DateLessonNotInPast; |
|
8
|
|
|
use DateTime; |
|
9
|
|
|
use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable; |
|
10
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
11
|
|
|
use Doctrine\Common\Collections\Collection; |
|
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
13
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
14
|
|
|
use Ramsey\Uuid\Uuid; |
|
15
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
16
|
|
|
|
|
17
|
|
|
#[Auditable] |
|
18
|
|
|
#[ORM\Entity] |
|
19
|
|
|
class StudentAbsence { |
|
20
|
|
|
|
|
21
|
|
|
use IdTrait; |
|
22
|
|
|
use UuidTrait; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var Student|null |
|
26
|
|
|
*/ |
|
27
|
|
|
#[Assert\NotNull] |
|
28
|
|
|
#[ORM\ManyToOne(targetEntity: Student::class)] |
|
29
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
30
|
|
|
private ?Student $student = null; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var DateLesson|null |
|
34
|
|
|
*/ |
|
35
|
|
|
#[DateLessonNotInPast(exceptions: ['ROLE_STUDENT_ABSENCE_CREATOR'], propertyName: 'from')] |
|
36
|
|
|
#[DateLessonInSection] |
|
37
|
|
|
#[Assert\NotNull] |
|
38
|
|
|
#[ORM\Embedded(class: DateLesson::class)] |
|
39
|
|
|
private ?DateLesson $from = null; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var DateLesson|null |
|
43
|
|
|
*/ |
|
44
|
|
|
#[DateLessonGreaterThan(propertyPath: 'from')] |
|
45
|
|
|
#[DateLessonInSection] |
|
46
|
|
|
#[Assert\NotNull] |
|
47
|
|
|
#[ORM\Embedded(class: DateLesson::class)] |
|
48
|
|
|
private ?DateLesson $until = null; |
|
49
|
|
|
|
|
50
|
|
|
#[Assert\NotNull] |
|
51
|
|
|
#[ORM\ManyToOne(targetEntity: StudentAbsenceType::class)] |
|
52
|
|
|
#[ORM\JoinColumn] |
|
53
|
|
|
private ?StudentAbsenceType $type = null; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string|null |
|
57
|
|
|
*/ |
|
58
|
|
|
#[Assert\NotBlank(allowNull: true)] |
|
59
|
|
|
#[Assert\Email] |
|
60
|
|
|
#[ORM\Column(type: 'string', nullable: true)] |
|
61
|
|
|
private ?string $email = null; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var string|null |
|
65
|
|
|
*/ |
|
66
|
|
|
#[Assert\NotBlank(allowNull: true)] |
|
67
|
|
|
#[ORM\Column(type: 'string', nullable: true)] |
|
68
|
|
|
private ?string $phone = null; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var string|null |
|
72
|
|
|
*/ |
|
73
|
|
|
#[Assert\NotBlank] |
|
74
|
|
|
#[ORM\Column(type: 'text')] |
|
75
|
|
|
private ?string $message = null; |
|
76
|
|
|
|
|
77
|
|
|
#[Gedmo\Blameable(on: 'create')] |
|
78
|
|
|
#[ORM\ManyToOne(targetEntity: User::class)] |
|
79
|
|
|
#[ORM\JoinColumn(onDelete: 'CASCADE')] |
|
80
|
|
|
private ?User $createdBy = null; |
|
81
|
|
|
|
|
82
|
|
|
#[Gedmo\Timestampable(on: 'create')] |
|
83
|
|
|
#[ORM\Column(type: 'datetime')] |
|
84
|
|
|
private ?DateTime $createdAt = null; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @var User|null |
|
88
|
|
|
*/ |
|
89
|
|
|
#[ORM\ManyToOne(targetEntity: User::class)] |
|
90
|
|
|
#[ORM\JoinColumn(onDelete: 'SET NULL')] |
|
91
|
|
|
private ?User $approvedBy = null; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @var DateTime|null |
|
95
|
|
|
*/ |
|
96
|
|
|
#[ORM\Column(type: 'datetime', nullable: true)] |
|
97
|
|
|
private ?DateTime $approvedAt = null; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @var bool |
|
101
|
|
|
*/ |
|
102
|
|
|
#[ORM\Column(type: 'boolean')] |
|
103
|
|
|
private bool $isApproved = false; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @var Collection<StudentAbsenceAttachment> |
|
107
|
|
|
*/ |
|
108
|
|
|
#[ORM\OneToMany(mappedBy: 'absence', targetEntity: StudentAbsenceAttachment::class, cascade: ['persist'])] |
|
109
|
|
|
#[ORM\OrderBy(['filename' => 'asc'])] |
|
110
|
|
|
private Collection $attachments; |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @var Collection<StudentAbsenceMessage> |
|
114
|
|
|
*/ |
|
115
|
|
|
#[ORM\OneToMany(mappedBy: 'absence', targetEntity: StudentAbsenceMessage::class, cascade: ['persist'])] |
|
116
|
|
|
private Collection $messages; |
|
117
|
|
|
|
|
118
|
|
|
public function __construct() { |
|
119
|
|
|
$this->uuid = Uuid::uuid4(); |
|
120
|
|
|
|
|
121
|
|
|
$this->attachments = new ArrayCollection(); |
|
122
|
|
|
$this->messages = new ArrayCollection(); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function getStudent(): ?Student { |
|
126
|
|
|
return $this->student; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function setStudent(?Student $student): StudentAbsence { |
|
130
|
|
|
$this->student = $student; |
|
131
|
|
|
return $this; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function getFrom(): ?DateLesson { |
|
135
|
|
|
return $this->from; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function setFrom(?DateLesson $from): StudentAbsence { |
|
139
|
|
|
$this->from = $from; |
|
140
|
|
|
return $this; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function getUntil(): ?DateLesson { |
|
144
|
|
|
return $this->until; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function setUntil(?DateLesson $until): StudentAbsence { |
|
148
|
|
|
$this->until = $until; |
|
149
|
|
|
return $this; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function getCreatedBy(): User { |
|
153
|
|
|
return $this->createdBy; |
|
|
|
|
|
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function getCreatedAt(): ?DateTime { |
|
157
|
|
|
return $this->createdAt; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function addAttachment(StudentAbsenceAttachment $attachment): void { |
|
161
|
|
|
if($attachment->getAbsence() === $this) { |
|
162
|
|
|
// Do not read already existing attachments (seems to fix a bug with VichUploaderBundle https://github.com/dustin10/VichUploaderBundle/issues/842) |
|
163
|
|
|
return; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
$attachment->setAbsence($this); |
|
167
|
|
|
$this->attachments->add($attachment); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function removeAttachment(StudentAbsenceAttachment $attachment): void { |
|
171
|
|
|
$this->attachments->removeElement($attachment); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return Collection<StudentAbsenceAttachment> |
|
176
|
|
|
*/ |
|
177
|
|
|
public function getAttachments(): Collection { |
|
178
|
|
|
return $this->attachments; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function getEmail(): ?string { |
|
182
|
|
|
return $this->email; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function setEmail(?string $email): StudentAbsence { |
|
186
|
|
|
$this->email = $email; |
|
187
|
|
|
return $this; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function getPhone(): ?string { |
|
191
|
|
|
return $this->phone; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function setPhone(?string $phone): StudentAbsence { |
|
195
|
|
|
$this->phone = $phone; |
|
196
|
|
|
return $this; |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public function getMessage(): ?string { |
|
200
|
|
|
return $this->message; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function setMessage(?string $message): StudentAbsence { |
|
204
|
|
|
$this->message = $message; |
|
205
|
|
|
return $this; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function getType(): ?StudentAbsenceType { |
|
209
|
|
|
return $this->type; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
public function setType(?StudentAbsenceType $type): StudentAbsence { |
|
213
|
|
|
$this->type = $type; |
|
214
|
|
|
return $this; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
public function getApprovedBy(): ?User { |
|
218
|
|
|
return $this->approvedBy; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
public function setApprovedBy(?User $approvedBy): StudentAbsence { |
|
222
|
|
|
$this->approvedBy = $approvedBy; |
|
223
|
|
|
return $this; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
public function getApprovedAt(): ?DateTime { |
|
227
|
|
|
return $this->approvedAt; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
public function setApprovedAt(?DateTime $approvedAt): StudentAbsence { |
|
231
|
|
|
$this->approvedAt = $approvedAt; |
|
232
|
|
|
return $this; |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
public function isApproved(): bool { |
|
236
|
|
|
return $this->isApproved; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
public function setIsApproved(bool $isApproved): StudentAbsence { |
|
240
|
|
|
$this->isApproved = $isApproved; |
|
241
|
|
|
return $this; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
public function getMessages(): Collection { |
|
245
|
|
|
return $this->messages; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
public function addMessage(StudentAbsenceMessage $message): void { |
|
249
|
|
|
$this->messages->add($message); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
public function removeMessage(StudentAbsenceMessage $message): void { |
|
253
|
|
|
$this->messages->removeElement($message); |
|
254
|
|
|
} |
|
255
|
|
|
} |