Passed
Push — master ( cc68cc...50453a )
by Julito
09:11
created

CCalendarEvent::setRepeatEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CourseBundle\Entity;
6
7
use Chamilo\CoreBundle\Entity\AbstractResource;
8
use Chamilo\CoreBundle\Entity\ResourceInterface;
9
use Chamilo\CoreBundle\Entity\Room;
10
use Doctrine\Common\Collections\ArrayCollection;
11
use Doctrine\ORM\Mapping as ORM;
12
use Symfony\Component\Validator\Constraints as Assert;
13
14
/**
15
 * CCalendarEvent.
16
 *
17
 * @ORM\Table(
18
 *  name="c_calendar_event",
19
 *  indexes={
20
 *  }
21
 * )
22
 * @ORM\Entity
23
 */
24
class CCalendarEvent extends AbstractResource implements ResourceInterface
25
{
26
    /**
27
     * @var int
28
     *
29
     * @ORM\Column(name="iid", type="integer")
30
     * @ORM\Id
31
     * @ORM\GeneratedValue
32
     */
33
    protected $iid;
34
35
    /**
36
     * @var string
37
     * @Assert\NotBlank()
38
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
39
     */
40
    protected $title;
41
42
    /**
43
     * @var string
44
     *
45
     * @ORM\Column(name="content", type="text", nullable=true)
46
     */
47
    protected $content;
48
49
    /**
50
     * @var \DateTime
51
     *
52
     * @ORM\Column(name="start_date", type="datetime", nullable=true)
53
     */
54
    protected $startDate;
55
56
    /**
57
     * @var \DateTime
58
     *
59
     * @ORM\Column(name="end_date", type="datetime", nullable=true)
60
     */
61
    protected $endDate;
62
63
    /**
64
     * @var ArrayCollection|CCalendarEvent[]
65
     * @ORM\OneToMany(targetEntity="CCalendarEvent", mappedBy="parentEvent")
66
     */
67
    protected $children;
68
69
    /**
70
     * @var CCalendarEvent
71
     *
72
     * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CCalendarEvent", inversedBy="children")
73
     * @ORM\JoinColumn(name="parent_event_id", referencedColumnName="iid")
74
     */
75
    protected $parentEvent;
76
77
    /**
78
     * @var ArrayCollection|CCalendarEventRepeat[]
79
     *
80
     * @ORM\OneToMany(targetEntity="CCalendarEventRepeat", mappedBy="event", cascade={"persist"}, orphanRemoval=true)
81
     */
82
    protected $repeatEvents;
83
84
    /**
85
     * @var int
86
     *
87
     * @ORM\Column(name="all_day", type="integer", nullable=false)
88
     */
89
    protected $allDay;
90
91
    /**
92
     * @var string
93
     *
94
     * @ORM\Column(name="comment", type="text", nullable=true)
95
     */
96
    protected $comment;
97
98
    /**
99
     * @var string
100
     *
101
     * @ORM\Column(name="color", type="string", length=100, nullable=true)
102
     */
103
    protected $color;
104
105
    /**
106
     * @var Room
107
     *
108
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Room")
109
     * @ORM\JoinColumn(name="room_id", referencedColumnName="id")
110
     */
111
    protected $room;
112
113
    /**
114
     * @var ArrayCollection|CCalendarEventAttachment[]
115
     *
116
     * @ORM\OneToMany(
117
     *   targetEntity="CCalendarEventAttachment", mappedBy="event", cascade={"persist", "remove"}, orphanRemoval=true
118
     * )
119
     */
120
    protected $attachments;
121
122
    public function __construct()
123
    {
124
        $this->children = new ArrayCollection();
125
    }
126
127
    public function __toString(): string
128
    {
129
        return $this->getTitle();
130
    }
131
132
    /**
133
     * Set title.
134
     *
135
     * @param string $title
136
     */
137
    public function setTitle($title): self
138
    {
139
        $this->title = $title;
140
141
        return $this;
142
    }
143
144
    /**
145
     * Get title.
146
     *
147
     * @return string
148
     */
149
    public function getTitle()
150
    {
151
        return $this->title;
152
    }
153
154
    /**
155
     * Set content.
156
     *
157
     * @param string $content
158
     */
159
    public function setContent($content): self
160
    {
161
        $this->content = $content;
162
163
        return $this;
164
    }
165
166
    /**
167
     * Get content.
168
     *
169
     * @return string
170
     */
171
    public function getContent()
172
    {
173
        return $this->content;
174
    }
175
176
    /**
177
     * Set startDate.
178
     *
179
     * @param \DateTime $startDate
180
     */
181
    public function setStartDate($startDate): self
182
    {
183
        $this->startDate = $startDate;
184
185
        return $this;
186
    }
187
188
    /**
189
     * Get startDate.
190
     *
191
     * @return \DateTime
192
     */
193
    public function getStartDate()
194
    {
195
        return $this->startDate;
196
    }
197
198
    /**
199
     * Set endDate.
200
     *
201
     * @param \DateTime $endDate
202
     */
203
    public function setEndDate($endDate): self
204
    {
205
        $this->endDate = $endDate;
206
207
        return $this;
208
    }
209
210
    /**
211
     * Get endDate.
212
     *
213
     * @return \DateTime
214
     */
215
    public function getEndDate()
216
    {
217
        return $this->endDate;
218
    }
219
220
    public function setParentEvent(CCalendarEvent $parent): self
221
    {
222
        $this->parentEvent = $parent;
223
224
        return $this;
225
    }
226
227
    public function getParentEvent(): ?CCalendarEvent
228
    {
229
        return $this->parentEvent;
230
    }
231
232
    /**
233
     * @return CCalendarEvent[]|ArrayCollection
234
     */
235
    public function getChildren()
236
    {
237
        return $this->children;
238
    }
239
240
    public function addChild($event): self
241
    {
242
        if (!$this->getChildren()->contains($event)) {
243
            $this->getChildren()->add($event);
244
        }
245
246
        return $this;
247
    }
248
249
    /**
250
     * @param CCalendarEvent[]|ArrayCollection $children
251
     */
252
    public function setChildren($children): self
253
    {
254
        $this->children = $children;
255
256
        return $this;
257
    }
258
259
    /**
260
     * Set allDay.
261
     *
262
     * @param int $allDay
263
     */
264
    public function setAllDay($allDay): self
265
    {
266
        $this->allDay = $allDay;
267
268
        return $this;
269
    }
270
271
    /**
272
     * Get allDay.
273
     *
274
     * @return int
275
     */
276
    public function getAllDay()
277
    {
278
        return (int) $this->allDay;
279
    }
280
281
    /**
282
     * @return string
283
     */
284
    public function getComment()
285
    {
286
        return $this->comment;
287
    }
288
289
    /**
290
     * @param string $comment
291
     */
292
    public function setComment($comment): self
293
    {
294
        $this->comment = $comment;
295
296
        return $this;
297
    }
298
299
    /**
300
     * @return Room
301
     */
302
    public function getRoom()
303
    {
304
        return $this->room;
305
    }
306
307
    /**
308
     * @param Room $room
309
     */
310
    public function setRoom($room): self
311
    {
312
        $this->room = $room;
313
314
        return $this;
315
    }
316
317
    /**
318
     * @return string
319
     */
320
    public function getColor()
321
    {
322
        return $this->color;
323
    }
324
325
    /**
326
     * @param string $color
327
     */
328
    public function setColor($color): self
329
    {
330
        $this->color = $color;
331
332
        return $this;
333
    }
334
335
    /**
336
     * @return int
337
     */
338
    public function getIid()
339
    {
340
        return $this->iid;
341
    }
342
343
    /**
344
     * @return CCalendarEventAttachment[]|ArrayCollection
345
     */
346
    public function getAttachments()
347
    {
348
        return $this->attachments;
349
    }
350
351
    /**
352
     * @param CCalendarEventAttachment[]|ArrayCollection $attachments
353
     */
354
    public function setAttachments($attachments): self
355
    {
356
        $this->attachments = $attachments;
357
358
        return $this;
359
    }
360
361
    public function addAttachment(CCalendarEventAttachment $attachment): self
362
    {
363
        $this->attachments->add($attachment);
364
365
        return $this;
366
    }
367
368
    /**
369
     * @return CCalendarEventRepeat[]|ArrayCollection
370
     */
371
    public function getRepeatEvents()
372
    {
373
        return $this->repeatEvents;
374
    }
375
376
    /**
377
     * @param CCalendarEventRepeat[]|ArrayCollection $repeatEvents
378
     *
379
     * @return CCalendarEvent
380
     */
381
    public function setRepeatEvents($repeatEvents)
382
    {
383
        $this->repeatEvents = $repeatEvents;
384
385
        return $this;
386
    }
387
388
    public function getUsersAndGroupSubscribedToEvent(): array
389
    {
390
        $users = [];
391
        $groups = [];
392
        $everyone = false;
393
        $links = $this->getResourceNode()->getResourceLinks();
394
        foreach ($links as $link) {
395
            if ($link->getUser()) {
396
                $users[] = $link->getUser()->getId();
397
            }
398
            if ($link->getGroup()) {
399
                $groups[] = $link->getGroup()->getIid();
400
            }
401
        }
402
403
        if (empty($users) && empty($groups)) {
404
            $everyone = true;
405
        }
406
407
        return [
408
            'everyone' => $everyone,
409
            'users' => $users,
410
            'groups' => $groups,
411
        ];
412
    }
413
414
    /**
415
     * Resource identifier.
416
     */
417
    public function getResourceIdentifier(): int
418
    {
419
        return $this->getIid();
420
    }
421
422
    public function getResourceName(): string
423
    {
424
        return $this->getTitle();
425
    }
426
427
    public function setResourceName(string $name): self
428
    {
429
        return $this->setTitle($name);
430
    }
431
}
432