Passed
Push — master ( 241b61...cc68cc )
by Julito
09:18
created

getUsersAndGroupSubscribedToEvent()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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