|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CourseBundle\Entity; |
|
8
|
|
|
|
|
9
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; |
|
10
|
|
|
use ApiPlatform\Metadata\ApiFilter; |
|
11
|
|
|
use ApiPlatform\Metadata\ApiResource; |
|
12
|
|
|
use ApiPlatform\Metadata\Delete; |
|
13
|
|
|
use ApiPlatform\Metadata\Get; |
|
14
|
|
|
use ApiPlatform\Metadata\GetCollection; |
|
15
|
|
|
use ApiPlatform\Metadata\Post; |
|
16
|
|
|
use ApiPlatform\Metadata\Put; |
|
17
|
|
|
use ApiPlatform\OpenApi\Model\Operation; |
|
18
|
|
|
use ApiPlatform\OpenApi\Model\Parameter; |
|
19
|
|
|
use Chamilo\CoreBundle\Entity\AbstractResource; |
|
20
|
|
|
use Chamilo\CoreBundle\Entity\ResourceInterface; |
|
21
|
|
|
use Chamilo\CoreBundle\Filter\SidFilter; |
|
22
|
|
|
use Chamilo\CoreBundle\State\CAttendanceStateProcessor; |
|
23
|
|
|
use Chamilo\CourseBundle\Repository\CAttendanceRepository; |
|
24
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
25
|
|
|
use Doctrine\Common\Collections\Collection; |
|
26
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
27
|
|
|
use Stringable; |
|
28
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
|
29
|
|
|
use Symfony\Component\Serializer\Annotation\MaxDepth; |
|
30
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
31
|
|
|
|
|
32
|
|
|
#[ApiResource( |
|
33
|
|
|
shortName: 'Attendance', |
|
34
|
|
|
operations: [ |
|
35
|
|
|
new Put( |
|
36
|
|
|
uriTemplate: '/attendances/{iid}/toggle_visibility', |
|
37
|
|
|
openapi: new Operation( |
|
38
|
|
|
summary: 'Toggle visibility of the attendance\'s associated ResourceLink' |
|
39
|
|
|
), |
|
40
|
|
|
security: "is_granted('EDIT', object.resourceNode)", |
|
41
|
|
|
name: 'toggle_visibility', |
|
42
|
|
|
processor: CAttendanceStateProcessor::class |
|
43
|
|
|
), |
|
44
|
|
|
new Put( |
|
45
|
|
|
uriTemplate: '/attendances/{iid}/soft_delete', |
|
46
|
|
|
openapi: new Operation( |
|
47
|
|
|
summary: 'Soft delete the attendance' |
|
48
|
|
|
), |
|
49
|
|
|
security: "is_granted('EDIT', object.resourceNode)", |
|
50
|
|
|
name: 'soft_delete', |
|
51
|
|
|
processor: CAttendanceStateProcessor::class |
|
52
|
|
|
), |
|
53
|
|
|
new Delete(security: "is_granted('ROLE_TEACHER')"), |
|
54
|
|
|
new Post( |
|
55
|
|
|
uriTemplate: '/attendances/{iid}/calendars', |
|
56
|
|
|
openapi: new Operation( |
|
57
|
|
|
summary: 'Add a calendar to an attendance.' |
|
58
|
|
|
), |
|
59
|
|
|
denormalizationContext: ['groups' => ['attendance:write']], |
|
60
|
|
|
name: 'calendar_add', |
|
61
|
|
|
processor: CAttendanceStateProcessor::class |
|
62
|
|
|
), |
|
63
|
|
|
new GetCollection( |
|
64
|
|
|
openapi: new Operation( |
|
65
|
|
|
parameters: [ |
|
66
|
|
|
new Parameter( |
|
67
|
|
|
name: 'resourceNode.parent', |
|
68
|
|
|
in: 'query', |
|
69
|
|
|
description: 'Resource node Parent', |
|
70
|
|
|
required: true, |
|
71
|
|
|
schema: ['type' => 'integer'], |
|
72
|
|
|
), |
|
73
|
|
|
], |
|
74
|
|
|
), |
|
75
|
|
|
), |
|
76
|
|
|
new Get(security: "is_granted('ROLE_USER')"), |
|
77
|
|
|
new Post( |
|
78
|
|
|
denormalizationContext: ['groups' => ['attendance:write']], |
|
79
|
|
|
security: "is_granted('ROLE_TEACHER')", |
|
80
|
|
|
validationContext: ['groups' => ['Default']] |
|
81
|
|
|
), |
|
82
|
|
|
new Put( |
|
83
|
|
|
denormalizationContext: ['groups' => ['attendance:write']], |
|
84
|
|
|
security: "is_granted('ROLE_TEACHER')" |
|
85
|
|
|
), |
|
86
|
|
|
], |
|
87
|
|
|
normalizationContext: [ |
|
88
|
|
|
'groups' => ['attendance:read', 'resource_node:read', 'resource_link:read'], |
|
89
|
|
|
'enable_max_depth' => true, |
|
90
|
|
|
], |
|
91
|
|
|
denormalizationContext: ['groups' => ['attendance:write']], |
|
92
|
|
|
paginationEnabled: true, |
|
93
|
|
|
)] |
|
94
|
|
|
#[ApiFilter(SearchFilter::class, properties: ['active' => 'exact', 'title' => 'partial', 'resourceNode.parent' => 'exact'])] |
|
95
|
|
|
#[ApiFilter(filterClass: SidFilter::class)] |
|
96
|
|
|
#[ORM\Table(name: 'c_attendance')] |
|
97
|
|
|
#[ORM\Index(columns: ['active'], name: 'active')] |
|
98
|
|
|
#[ORM\Entity(repositoryClass: CAttendanceRepository::class)] |
|
99
|
|
|
class CAttendance extends AbstractResource implements ResourceInterface, Stringable |
|
100
|
|
|
{ |
|
101
|
|
|
#[ORM\Column(name: 'iid', type: 'integer')] |
|
102
|
|
|
#[ORM\Id] |
|
103
|
|
|
#[ORM\GeneratedValue] |
|
104
|
|
|
#[Groups(['attendance:read'])] |
|
105
|
|
|
protected ?int $iid = null; |
|
106
|
|
|
|
|
107
|
|
|
#[Assert\NotBlank] |
|
108
|
|
|
#[ORM\Column(name: 'title', type: 'text', nullable: false)] |
|
109
|
|
|
#[Groups(['attendance:read', 'attendance:write'])] |
|
110
|
|
|
protected string $title; |
|
111
|
|
|
|
|
112
|
|
|
#[ORM\Column(name: 'description', type: 'text', nullable: true)] |
|
113
|
|
|
#[Groups(['attendance:read', 'attendance:write'])] |
|
114
|
|
|
protected ?string $description = null; |
|
115
|
|
|
|
|
116
|
|
|
#[Assert\NotBlank] |
|
117
|
|
|
#[ORM\Column(name: 'active', type: 'integer', nullable: false)] |
|
118
|
|
|
#[Groups(['attendance:read', 'attendance:write'])] |
|
119
|
|
|
protected int $active = 1; |
|
120
|
|
|
|
|
121
|
|
|
#[ORM\Column(name: 'attendance_qualify_title', type: 'string', length: 255, nullable: true)] |
|
122
|
|
|
#[Groups(['attendance:read', 'attendance:write'])] |
|
123
|
|
|
protected ?string $attendanceQualifyTitle = null; |
|
124
|
|
|
|
|
125
|
|
|
#[Assert\NotNull] |
|
126
|
|
|
#[ORM\Column(name: 'attendance_qualify_max', type: 'integer', nullable: false)] |
|
127
|
|
|
protected int $attendanceQualifyMax; |
|
128
|
|
|
|
|
129
|
|
|
#[Assert\NotNull] |
|
130
|
|
|
#[ORM\Column(name: 'attendance_weight', type: 'float', precision: 6, scale: 2, nullable: false)] |
|
131
|
|
|
#[Groups(['attendance:read', 'attendance:write'])] |
|
132
|
|
|
protected float $attendanceWeight = 0.0; |
|
133
|
|
|
|
|
134
|
|
|
#[Assert\NotNull] |
|
135
|
|
|
#[ORM\Column(name: 'locked', type: 'integer', nullable: false)] |
|
136
|
|
|
protected int $locked; |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @var Collection|CAttendanceCalendar[] |
|
140
|
|
|
*/ |
|
141
|
|
|
#[ORM\OneToMany(mappedBy: 'attendance', targetEntity: CAttendanceCalendar::class, cascade: ['persist', 'remove'])] |
|
142
|
|
|
#[Groups(['attendance:read'])] |
|
143
|
|
|
#[MaxDepth(1)] |
|
144
|
|
|
protected Collection $calendars; |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @var Collection|CAttendanceResult[] |
|
148
|
|
|
*/ |
|
149
|
|
|
#[ORM\OneToMany(mappedBy: 'attendance', targetEntity: CAttendanceResult::class, cascade: ['persist', 'remove'])] |
|
150
|
|
|
protected Collection $results; |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @var Collection|CAttendanceSheetLog[] |
|
154
|
|
|
*/ |
|
155
|
|
|
#[ORM\OneToMany(mappedBy: 'attendance', targetEntity: CAttendanceSheetLog::class, cascade: ['persist', 'remove'])] |
|
156
|
|
|
protected Collection $logs; |
|
157
|
|
|
|
|
158
|
|
|
#[Groups(['attendance:read'])] |
|
159
|
|
|
private ?int $doneCalendars = null; |
|
160
|
|
|
|
|
161
|
|
|
public function __construct() |
|
162
|
|
|
{ |
|
163
|
|
|
$this->description = ''; |
|
164
|
|
|
$this->active = 1; |
|
165
|
|
|
$this->attendanceQualifyMax = 0; |
|
166
|
|
|
$this->locked = 0; |
|
167
|
|
|
$this->calendars = new ArrayCollection(); |
|
168
|
|
|
$this->results = new ArrayCollection(); |
|
169
|
|
|
$this->logs = new ArrayCollection(); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function __toString(): string |
|
173
|
|
|
{ |
|
174
|
|
|
return $this->getTitle(); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function setTitle(string $title): self |
|
178
|
|
|
{ |
|
179
|
|
|
$this->title = $title; |
|
180
|
|
|
|
|
181
|
|
|
return $this; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
public function getTitle(): string |
|
185
|
|
|
{ |
|
186
|
|
|
return $this->title; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function setDescription(string $description): self |
|
190
|
|
|
{ |
|
191
|
|
|
$this->description = $description; |
|
192
|
|
|
|
|
193
|
|
|
return $this; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
public function getDescription(): ?string |
|
197
|
|
|
{ |
|
198
|
|
|
return $this->description; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function setActive(int $active): self |
|
202
|
|
|
{ |
|
203
|
|
|
$this->active = $active; |
|
204
|
|
|
|
|
205
|
|
|
return $this; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
public function getActive(): int |
|
209
|
|
|
{ |
|
210
|
|
|
return $this->active; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function setAttendanceQualifyTitle(string $attendanceQualifyTitle): self |
|
214
|
|
|
{ |
|
215
|
|
|
$this->attendanceQualifyTitle = $attendanceQualifyTitle; |
|
216
|
|
|
|
|
217
|
|
|
return $this; |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
public function getAttendanceQualifyTitle(): ?string |
|
221
|
|
|
{ |
|
222
|
|
|
return $this->attendanceQualifyTitle; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
public function setAttendanceQualifyMax(int $attendanceQualifyMax): self |
|
226
|
|
|
{ |
|
227
|
|
|
$this->attendanceQualifyMax = $attendanceQualifyMax; |
|
228
|
|
|
|
|
229
|
|
|
return $this; |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* Get attendanceQualifyMax. |
|
234
|
|
|
*/ |
|
235
|
|
|
public function getAttendanceQualifyMax(): int |
|
236
|
|
|
{ |
|
237
|
|
|
return $this->attendanceQualifyMax; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
public function setAttendanceWeight(float $attendanceWeight): self |
|
241
|
|
|
{ |
|
242
|
|
|
$this->attendanceWeight = $attendanceWeight; |
|
243
|
|
|
|
|
244
|
|
|
return $this; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Get attendanceWeight. |
|
249
|
|
|
*/ |
|
250
|
|
|
public function getAttendanceWeight(): float |
|
251
|
|
|
{ |
|
252
|
|
|
return $this->attendanceWeight; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
public function setLocked(int $locked): self |
|
256
|
|
|
{ |
|
257
|
|
|
$this->locked = $locked; |
|
258
|
|
|
|
|
259
|
|
|
return $this; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Get locked. |
|
264
|
|
|
*/ |
|
265
|
|
|
public function getLocked(): int |
|
266
|
|
|
{ |
|
267
|
|
|
return $this->locked; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
public function getIid(): ?int |
|
271
|
|
|
{ |
|
272
|
|
|
return $this->iid; |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
public function getCalendars(): Collection |
|
276
|
|
|
{ |
|
277
|
|
|
return $this->calendars; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
public function setCalendars(Collection $calendars): self |
|
281
|
|
|
{ |
|
282
|
|
|
$this->calendars = $calendars; |
|
283
|
|
|
|
|
284
|
|
|
return $this; |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
public function addCalendar(CAttendanceCalendar $calendar): self |
|
288
|
|
|
{ |
|
289
|
|
|
if (!$this->calendars->contains($calendar)) { |
|
290
|
|
|
$this->calendars->add($calendar); |
|
291
|
|
|
$calendar->setAttendance($this); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
return $this; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* @return CAttendanceSheetLog[]|Collection |
|
299
|
|
|
*/ |
|
300
|
|
|
public function getLogs(): array|Collection |
|
301
|
|
|
{ |
|
302
|
|
|
return $this->logs; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
public function getDoneCalendars(): int |
|
306
|
|
|
{ |
|
307
|
|
|
return $this->calendars |
|
308
|
|
|
->filter(fn (CAttendanceCalendar $calendar) => $calendar->getDoneAttendance()) |
|
309
|
|
|
->count() |
|
310
|
|
|
; |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
public function setDoneCalendars(?int $count): self |
|
314
|
|
|
{ |
|
315
|
|
|
$this->doneCalendars = $count; |
|
316
|
|
|
|
|
317
|
|
|
return $this; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* @param CAttendanceSheetLog[]|Collection $logs |
|
322
|
|
|
*/ |
|
323
|
|
|
public function setLogs(array|Collection $logs): self |
|
324
|
|
|
{ |
|
325
|
|
|
$this->logs = $logs; |
|
326
|
|
|
|
|
327
|
|
|
return $this; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* @return CAttendanceResult[]|Collection |
|
332
|
|
|
*/ |
|
333
|
|
|
public function getResults(): array|Collection |
|
334
|
|
|
{ |
|
335
|
|
|
return $this->results; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
public function setResults(Collection $results): self |
|
339
|
|
|
{ |
|
340
|
|
|
$this->results = $results; |
|
341
|
|
|
|
|
342
|
|
|
return $this; |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
public function getResourceIdentifier(): int |
|
346
|
|
|
{ |
|
347
|
|
|
return $this->getIid(); |
|
|
|
|
|
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
public function getResourceName(): string |
|
351
|
|
|
{ |
|
352
|
|
|
return $this->getTitle(); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
public function setResourceName(string $name): self |
|
356
|
|
|
{ |
|
357
|
|
|
return $this->setTitle($name); |
|
358
|
|
|
} |
|
359
|
|
|
} |
|
360
|
|
|
|