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\Core\Annotation\ApiFilter; |
10
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
11
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter; |
12
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; |
13
|
|
|
use Chamilo\CoreBundle\Controller\Api\CreateCCalendarEventAction; |
14
|
|
|
use Chamilo\CoreBundle\Entity\AbstractResource; |
15
|
|
|
use Chamilo\CoreBundle\Entity\ResourceInterface; |
16
|
|
|
use Chamilo\CoreBundle\Entity\Room; |
17
|
|
|
use DateTime; |
18
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
19
|
|
|
use Doctrine\Common\Collections\Collection; |
20
|
|
|
use Doctrine\ORM\Mapping as ORM; |
21
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
22
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Calendar events. |
26
|
|
|
* |
27
|
|
|
* @ORM\Table( |
28
|
|
|
* name="c_calendar_event", |
29
|
|
|
* indexes={ |
30
|
|
|
* } |
31
|
|
|
* ) |
32
|
|
|
* @ORM\Entity |
33
|
|
|
*/ |
34
|
|
|
#[ApiResource( |
35
|
|
|
collectionOperations: [ |
36
|
|
|
'get' => [ |
37
|
|
|
//'security' => "is_granted('VIEW', object)", // the get collection is also filtered by MessageExtension.php |
38
|
|
|
'security' => "is_granted('ROLE_USER')", |
39
|
|
|
], |
40
|
|
|
'post' => [ |
41
|
|
|
'controller' => CreateCCalendarEventAction::class, |
42
|
|
|
'security_post_denormalize' => "is_granted('CREATE', object)", |
43
|
|
|
], |
44
|
|
|
], |
45
|
|
|
itemOperations: [ |
46
|
|
|
'get' => [ |
47
|
|
|
'security' => "is_granted('VIEW', object)", |
48
|
|
|
], |
49
|
|
|
'put' => [ |
50
|
|
|
'security' => "is_granted('EDIT', object)", |
51
|
|
|
], |
52
|
|
|
'delete' => [ |
53
|
|
|
'security' => "is_granted('DELETE', object)", |
54
|
|
|
], |
55
|
|
|
], |
56
|
|
|
attributes: [ |
57
|
|
|
'security' => "is_granted('ROLE_USER')", |
58
|
|
|
], |
59
|
|
|
denormalizationContext: [ |
60
|
|
|
'groups' => ['calendar_event:write'], |
61
|
|
|
], |
62
|
|
|
normalizationContext: [ |
63
|
|
|
'groups' => ['calendar_event:read'], |
64
|
|
|
], |
65
|
|
|
)] |
66
|
|
|
|
67
|
|
|
#[ApiFilter(SearchFilter::class, properties: [ |
68
|
|
|
'startDate' => 'exact', |
69
|
|
|
'endDate' => 'exact', |
70
|
|
|
'allDay' => 'boolean', |
71
|
|
|
])] |
72
|
|
|
|
73
|
|
|
#[ApiFilter(DateFilter::class, strategy: DateFilter::EXCLUDE_NULL)] |
74
|
|
|
|
75
|
|
|
class CCalendarEvent extends AbstractResource implements ResourceInterface |
76
|
|
|
{ |
77
|
|
|
/** |
78
|
|
|
* @ORM\Column(name="iid", type="integer") |
79
|
|
|
* @ORM\Id |
80
|
|
|
* @ORM\GeneratedValue |
81
|
|
|
*/ |
82
|
|
|
#[Groups(['calendar_event:read', 'calendar_event:write'])] |
83
|
|
|
protected int $iid; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @ORM\Column(name="title", type="string", length=255, nullable=false) |
87
|
|
|
*/ |
88
|
|
|
#[Assert\NotBlank] |
89
|
|
|
#[Groups(['calendar_event:read', 'calendar_event:write'])] |
90
|
|
|
protected string $title; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @ORM\Column(name="content", type="text", nullable=true) |
94
|
|
|
*/ |
95
|
|
|
#[Assert\NotBlank] |
96
|
|
|
#[Groups(['calendar_event:read', 'calendar_event:write'])] |
97
|
|
|
protected ?string $content = null; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @ORM\Column(name="start_date", type="datetime", nullable=true) |
101
|
|
|
*/ |
102
|
|
|
#[Groups(['calendar_event:read', 'calendar_event:write'])] |
103
|
|
|
protected ?DateTime $startDate = null; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @ORM\Column(name="end_date", type="datetime", nullable=true) |
107
|
|
|
*/ |
108
|
|
|
#[Groups(['calendar_event:read', 'calendar_event:write'])] |
109
|
|
|
protected ?DateTime $endDate = null; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CCalendarEvent", inversedBy="children") |
113
|
|
|
* @ORM\JoinColumn(name="parent_event_id", referencedColumnName="iid") |
114
|
|
|
*/ |
115
|
|
|
protected ?CCalendarEvent $parentEvent = null; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @var Collection|CCalendarEvent[] |
119
|
|
|
* @ORM\OneToMany(targetEntity="CCalendarEvent", mappedBy="parentEvent") |
120
|
|
|
*/ |
121
|
|
|
protected Collection $children; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @var Collection|CCalendarEventRepeat[] |
125
|
|
|
* |
126
|
|
|
* @ORM\OneToMany(targetEntity="CCalendarEventRepeat", mappedBy="event", cascade={"persist"}, orphanRemoval=true) |
127
|
|
|
*/ |
128
|
|
|
protected Collection $repeatEvents; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @ORM\Column(name="all_day", type="boolean", nullable=false) |
132
|
|
|
*/ |
133
|
|
|
#[Groups(['calendar_event:read', 'calendar_event:write'])] |
134
|
|
|
protected bool $allDay; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @ORM\Column(name="comment", type="text", nullable=true) |
138
|
|
|
*/ |
139
|
|
|
protected ?string $comment = null; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @ORM\Column(name="color", type="string", length=100, nullable=true) |
143
|
|
|
*/ |
144
|
|
|
#[Groups(['calendar_event:read', 'calendar_event:write'])] |
145
|
|
|
protected ?string $color = null; |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Room") |
149
|
|
|
* @ORM\JoinColumn(name="room_id", referencedColumnName="id") |
150
|
|
|
*/ |
151
|
|
|
protected ?Room $room = null; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @var Collection|CCalendarEventAttachment[] |
155
|
|
|
* |
156
|
|
|
* @ORM\OneToMany( |
157
|
|
|
* targetEntity="CCalendarEventAttachment", mappedBy="event", cascade={"persist", "remove"} |
158
|
|
|
* ) |
159
|
|
|
*/ |
160
|
|
|
protected Collection $attachments; |
161
|
|
|
|
162
|
|
|
public function __construct() |
163
|
|
|
{ |
164
|
|
|
$this->children = new ArrayCollection(); |
165
|
|
|
$this->attachments = new ArrayCollection(); |
166
|
|
|
$this->repeatEvents = new ArrayCollection(); |
167
|
|
|
$this->allDay = false; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function __toString(): string |
171
|
|
|
{ |
172
|
|
|
return $this->getTitle(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function setTitle(string $title): self |
176
|
|
|
{ |
177
|
|
|
$this->title = $title; |
178
|
|
|
|
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public function getTitle(): string |
183
|
|
|
{ |
184
|
|
|
return $this->title; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function setContent(string $content): self |
188
|
|
|
{ |
189
|
|
|
$this->content = $content; |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function getContent(): ?string |
195
|
|
|
{ |
196
|
|
|
return $this->content; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function setStartDate(?DateTime $startDate): self |
200
|
|
|
{ |
201
|
|
|
$this->startDate = $startDate; |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Get startDate. |
208
|
|
|
* |
209
|
|
|
* @return DateTime |
210
|
|
|
*/ |
211
|
|
|
public function getStartDate() |
212
|
|
|
{ |
213
|
|
|
return $this->startDate; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function setEndDate(?DateTime $endDate): self |
217
|
|
|
{ |
218
|
|
|
$this->endDate = $endDate; |
219
|
|
|
|
220
|
|
|
return $this; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Get endDate. |
225
|
|
|
* |
226
|
|
|
* @return DateTime |
227
|
|
|
*/ |
228
|
|
|
public function getEndDate() |
229
|
|
|
{ |
230
|
|
|
return $this->endDate; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
public function setParentEvent(self $parent): self |
234
|
|
|
{ |
235
|
|
|
$this->parentEvent = $parent; |
236
|
|
|
|
237
|
|
|
return $this; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
public function getParentEvent(): ?self |
241
|
|
|
{ |
242
|
|
|
return $this->parentEvent; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @return Collection|CCalendarEvent[] |
247
|
|
|
*/ |
248
|
|
|
public function getChildren() |
249
|
|
|
{ |
250
|
|
|
return $this->children; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
public function addChild(self $event): self |
254
|
|
|
{ |
255
|
|
|
if (!$this->getChildren()->contains($event)) { |
256
|
|
|
$this->getChildren()->add($event); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
return $this; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @param Collection|CCalendarEvent[] $children |
264
|
|
|
*/ |
265
|
|
|
public function setChildren(Collection $children): self |
266
|
|
|
{ |
267
|
|
|
$this->children = $children; |
268
|
|
|
|
269
|
|
|
return $this; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
public function isAllDay(): bool |
273
|
|
|
{ |
274
|
|
|
return $this->allDay; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function setAllDay(bool $allDay): self |
278
|
|
|
{ |
279
|
|
|
$this->allDay = $allDay; |
280
|
|
|
|
281
|
|
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @return string |
286
|
|
|
*/ |
287
|
|
|
public function getComment() |
288
|
|
|
{ |
289
|
|
|
return $this->comment; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
public function setComment(string $comment): self |
293
|
|
|
{ |
294
|
|
|
$this->comment = $comment; |
295
|
|
|
|
296
|
|
|
return $this; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
public function getRoom(): ?Room |
300
|
|
|
{ |
301
|
|
|
return $this->room; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public function setRoom(Room $room): self |
305
|
|
|
{ |
306
|
|
|
$this->room = $room; |
307
|
|
|
|
308
|
|
|
return $this; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @return string |
313
|
|
|
*/ |
314
|
|
|
public function getColor() |
315
|
|
|
{ |
316
|
|
|
return $this->color; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
public function setColor(string $color): self |
320
|
|
|
{ |
321
|
|
|
$this->color = $color; |
322
|
|
|
|
323
|
|
|
return $this; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @return int |
328
|
|
|
*/ |
329
|
|
|
public function getIid() |
330
|
|
|
{ |
331
|
|
|
return $this->iid; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
/** |
335
|
|
|
* @return Collection |
336
|
|
|
*/ |
337
|
|
|
public function getAttachments() |
338
|
|
|
{ |
339
|
|
|
return $this->attachments; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
public function setAttachments(Collection $attachments): self |
343
|
|
|
{ |
344
|
|
|
$this->attachments = $attachments; |
345
|
|
|
|
346
|
|
|
return $this; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
public function addAttachment(CCalendarEventAttachment $attachment): self |
350
|
|
|
{ |
351
|
|
|
$this->attachments->add($attachment); |
352
|
|
|
|
353
|
|
|
return $this; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @return Collection|CCalendarEventRepeat[] |
358
|
|
|
*/ |
359
|
|
|
public function getRepeatEvents() |
360
|
|
|
{ |
361
|
|
|
return $this->repeatEvents; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @param Collection|CCalendarEventRepeat[] $repeatEvents |
366
|
|
|
* |
367
|
|
|
* @return CCalendarEvent |
368
|
|
|
*/ |
369
|
|
|
public function setRepeatEvents(Collection $repeatEvents) |
370
|
|
|
{ |
371
|
|
|
$this->repeatEvents = $repeatEvents; |
372
|
|
|
|
373
|
|
|
return $this; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
public function getResourceIdentifier(): int |
377
|
|
|
{ |
378
|
|
|
return $this->getIid(); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
public function getResourceName(): string |
382
|
|
|
{ |
383
|
|
|
return $this->getTitle(); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
public function setResourceName(string $name): self |
387
|
|
|
{ |
388
|
|
|
return $this->setTitle($name); |
389
|
|
|
} |
390
|
|
|
} |
391
|
|
|
|