Passed
Push — master ( 025d83...7a28b0 )
by Julito
17:18
created

CGroup::getCalendarState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\ApiResource;
10
use Chamilo\CoreBundle\Entity\AbstractResource;
11
use Chamilo\CoreBundle\Entity\ResourceInterface;
12
use Chamilo\CoreBundle\Entity\User;
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Doctrine\Common\Collections\Collection;
15
use Doctrine\Common\Collections\Criteria;
16
use Doctrine\ORM\Mapping as ORM;
17
use Symfony\Component\Serializer\Annotation\Groups;
18
use Symfony\Component\Validator\Constraints as Assert;
19
20
/**
21
 * @ApiResource(
22
 *     attributes={"security"="is_granted('ROLE_ADMIN')"},
23
 *     normalizationContext={"groups"={"group:read"}},
24
 * )
25
 *
26
 * @ORM\Table(
27
 *  name="c_group_info",
28
 *  indexes={
29
 *  }
30
 * )
31
 *
32
 * @ORM\Entity
33
 */
34
class CGroup extends AbstractResource implements ResourceInterface
35
{
36
    /**
37
     * @ORM\Column(name="iid", type="integer")
38
     * @ORM\Id
39
     * @ORM\GeneratedValue
40
     * @Groups({"group:read", "group:write"})
41
     */
42
    protected int $iid;
43
44
    /**
45
     * @Assert\NotBlank()
46
     * @ORM\Column(name="name", type="string", length=100, nullable=false)
47
     * @Groups({"group:read", "group:write"})
48
     */
49
    protected string $name;
50
51
    /**
52
     * @Assert\NotBlank()
53
     * @ORM\Column(name="status", type="boolean", nullable=false)
54
     */
55
    protected bool $status;
56
57
    /**
58
     * @ORM\ManyToOne(targetEntity="CGroupCategory", cascade={"persist"})
59
     * @ORM\JoinColumn(name="category_id", referencedColumnName="iid", onDelete="CASCADE")
60
     */
61
    protected CGroupCategory $category;
62
63
    /**
64
     * @ORM\Column(name="description", type="text", nullable=true)
65
     */
66
    protected ?string $description = null;
67
68
    /**
69
     * @ORM\Column(name="max_student", type="integer")
70
     */
71
    protected int $maxStudent;
72
73
    /**
74
     * @ORM\Column(name="doc_state", type="integer")
75
     */
76
    protected int $docState;
77
78
    /**
79
     * @ORM\Column(name="calendar_state", type="integer")
80
     */
81
    protected int $calendarState;
82
83
    /**
84
     * @ORM\Column(name="work_state", type="integer")
85
     */
86
    protected int $workState;
87
88
    /**
89
     * @ORM\Column(name="announcements_state", type="integer")
90
     */
91
    protected int $announcementsState;
92
93
    /**
94
     * @ORM\Column(name="forum_state", type="integer")
95
     */
96
    protected int $forumState;
97
98
    /**
99
     * @ORM\Column(name="wiki_state", type="integer")
100
     */
101
    protected int $wikiState;
102
103
    /**
104
     * @ORM\Column(name="chat_state", type="integer")
105
     */
106
    protected int $chatState;
107
108
    /**
109
     * @ORM\Column(name="self_registration_allowed", type="boolean")
110
     */
111
    protected bool $selfRegistrationAllowed;
112
113
    /**
114
     * @ORM\Column(name="self_unregistration_allowed", type="boolean")
115
     */
116
    protected bool $selfUnregistrationAllowed;
117
118
    /**
119
     * @ORM\Column(name="document_access", type="integer", options={"default":0})
120
     */
121
    protected int $documentAccess;
122
123
    /**
124
     * @var CGroupRelUser[]|Collection<int, CGroupRelUser>
125
     *
126
     * @ORM\OneToMany(targetEntity="CGroupRelUser", mappedBy="group")
127
     */
128
    protected Collection $members;
129
130
    /**
131
     * @var CGroupRelTutor[]|Collection<int, CGroupRelTutor>
132
     *
133
     * @ORM\OneToMany(targetEntity="CGroupRelTutor", mappedBy="group")
134
     */
135
    protected Collection $tutors;
136
137
    public function __construct()
138
    {
139
        $this->status = true;
140
        $this->members = new ArrayCollection();
141
        $this->tutors = new ArrayCollection();
142
    }
143
144
    public function __toString(): string
145
    {
146
        return $this->getName();
147
    }
148
149
    /**
150
     * Get iid.
151
     *
152
     * @return int
153
     */
154
    public function getIid()
155
    {
156
        return $this->iid;
157
    }
158
159
    /**
160
     * Set name.
161
     *
162
     * @param string $name
163
     */
164
    public function setName($name): self
165
    {
166
        $this->name = $name;
167
168
        return $this;
169
    }
170
171
    public function getName(): string
172
    {
173
        return $this->name;
174
    }
175
176
    /**
177
     * Set status.
178
     *
179
     * @param bool $status
180
     */
181
    public function setStatus($status): self
182
    {
183
        $this->status = $status;
184
185
        return $this;
186
    }
187
188
    /**
189
     * Get status.
190
     *
191
     * @return bool
192
     */
193
    public function getStatus()
194
    {
195
        return $this->status;
196
    }
197
198
    public function setDescription(string $description): self
199
    {
200
        $this->description = $description;
201
202
        return $this;
203
    }
204
205
    public function getDescription(): ?string
206
    {
207
        return $this->description;
208
    }
209
210
    public function setMaxStudent(int $maxStudent): self
211
    {
212
        $this->maxStudent = $maxStudent;
213
214
        return $this;
215
    }
216
217
    public function getMaxStudent(): int
218
    {
219
        return $this->maxStudent;
220
    }
221
222
    public function setDocState(int $docState): self
223
    {
224
        $this->docState = $docState;
225
226
        return $this;
227
    }
228
229
    /**
230
     * Get docState.
231
     *
232
     * @return int
233
     */
234
    public function getDocState()
235
    {
236
        return $this->docState;
237
    }
238
239
    /**
240
     * Set calendarState.
241
     *
242
     * @param int $calendarState
243
     */
244
    public function setCalendarState($calendarState): self
245
    {
246
        $this->calendarState = $calendarState;
247
248
        return $this;
249
    }
250
251
    /**
252
     * Get calendarState.
253
     *
254
     * @return int
255
     */
256
    public function getCalendarState()
257
    {
258
        return $this->calendarState;
259
    }
260
261
    /**
262
     * Set workState.
263
     *
264
     * @param int $workState
265
     */
266
    public function setWorkState($workState): self
267
    {
268
        $this->workState = $workState;
269
270
        return $this;
271
    }
272
273
    /**
274
     * Get workState.
275
     *
276
     * @return int
277
     */
278
    public function getWorkState()
279
    {
280
        return $this->workState;
281
    }
282
283
    /**
284
     * Set announcementsState.
285
     *
286
     * @param int $announcementsState
287
     */
288
    public function setAnnouncementsState($announcementsState): self
289
    {
290
        $this->announcementsState = $announcementsState;
291
292
        return $this;
293
    }
294
295
    /**
296
     * Get announcementsState.
297
     *
298
     * @return int
299
     */
300
    public function getAnnouncementsState()
301
    {
302
        return $this->announcementsState;
303
    }
304
305
    /**
306
     * Set forumState.
307
     *
308
     * @param int $forumState
309
     */
310
    public function setForumState($forumState): self
311
    {
312
        $this->forumState = $forumState;
313
314
        return $this;
315
    }
316
317
    public function getForumState(): int
318
    {
319
        return $this->forumState;
320
    }
321
322
    /**
323
     * Set wikiState.
324
     *
325
     * @param int $wikiState
326
     */
327
    public function setWikiState($wikiState): self
328
    {
329
        $this->wikiState = $wikiState;
330
331
        return $this;
332
    }
333
334
    /**
335
     * Get wikiState.
336
     *
337
     * @return int
338
     */
339
    public function getWikiState()
340
    {
341
        return $this->wikiState;
342
    }
343
344
    /**
345
     * Set chatState.
346
     *
347
     * @param int $chatState
348
     */
349
    public function setChatState($chatState): self
350
    {
351
        $this->chatState = $chatState;
352
353
        return $this;
354
    }
355
356
    /**
357
     * Get chatState.
358
     *
359
     * @return int
360
     */
361
    public function getChatState()
362
    {
363
        return $this->chatState;
364
    }
365
366
    /**
367
     * Set selfRegistrationAllowed.
368
     *
369
     * @param bool $selfRegistrationAllowed
370
     */
371
    public function setSelfRegistrationAllowed($selfRegistrationAllowed): self
372
    {
373
        $this->selfRegistrationAllowed = $selfRegistrationAllowed;
374
375
        return $this;
376
    }
377
378
    /**
379
     * Get selfRegistrationAllowed.
380
     *
381
     * @return bool
382
     */
383
    public function getSelfRegistrationAllowed()
384
    {
385
        return $this->selfRegistrationAllowed;
386
    }
387
388
    /**
389
     * Set selfUnregistrationAllowed.
390
     *
391
     * @param bool $selfUnregistrationAllowed
392
     */
393
    public function setSelfUnregistrationAllowed($selfUnregistrationAllowed): self
394
    {
395
        $this->selfUnregistrationAllowed = $selfUnregistrationAllowed;
396
397
        return $this;
398
    }
399
400
    /**
401
     * Get selfUnregistrationAllowed.
402
     *
403
     * @return bool
404
     */
405
    public function getSelfUnregistrationAllowed()
406
    {
407
        return $this->selfUnregistrationAllowed;
408
    }
409
410
    public function getDocumentAccess(): int
411
    {
412
        return $this->documentAccess;
413
    }
414
415
    public function setDocumentAccess(int $documentAccess): self
416
    {
417
        $this->documentAccess = $documentAccess;
418
419
        return $this;
420
    }
421
422
    public function getMembers(): Collection
423
    {
424
        return $this->members;
425
    }
426
427
    /**
428
     * @param CGroupRelUser[]|Collection<int, CGroupRelUser> $members
429
     */
430
    public function setMembers(Collection $members): self
431
    {
432
        $this->members = $members;
433
434
        return $this;
435
    }
436
437
    public function hasMembers(): bool
438
    {
439
        return $this->members->count() > 0;
440
    }
441
442
    public function hasMember(User $user): bool
443
    {
444
        $criteria = Criteria::create()->where(
445
            Criteria::expr()->eq('user', $user)
446
        );
447
448
        return $this->members->matching($criteria)->count() > 0;
449
    }
450
451
    public function hasTutor(User $user): bool
452
    {
453
        $criteria = Criteria::create()->where(
454
            Criteria::expr()->eq('user', $user)
455
        );
456
457
        return $this->tutors->matching($criteria)->count() > 0;
458
    }
459
460
    public function getTutors(): Collection
461
    {
462
        return $this->tutors;
463
    }
464
465
    /**
466
     * @param CGroupRelTutor[]|Collection<int, CGroupRelTutor> $tutors
467
     */
468
    public function setTutors(Collection $tutors): self
469
    {
470
        $this->tutors = $tutors;
471
472
        return $this;
473
    }
474
475
    public function hasTutors(): bool
476
    {
477
        return $this->tutors->count() > 0;
478
    }
479
480
    public function userIsTutor(User $user = null): bool
481
    {
482
        if (null === $user) {
483
            return false;
484
        }
485
486
        if (0 === $this->tutors->count()) {
487
            return false;
488
        }
489
490
        $criteria = Criteria::create()
491
            ->andWhere(
492
                Criteria::expr()->eq('user', $user)
493
            )
494
        ;
495
496
        $relation = $this->tutors->matching($criteria);
497
498
        return $relation->count() > 0;
499
    }
500
501
    public function getCategory(): CGroupCategory
502
    {
503
        return $this->category;
504
    }
505
506
    public function setCategory(CGroupCategory $category = null): self
507
    {
508
        $this->category = $category;
509
510
        return $this;
511
    }
512
513
    public function getResourceIdentifier(): int
514
    {
515
        return $this->iid;
516
    }
517
518
    public function getResourceName(): string
519
    {
520
        return $this->getName();
521
    }
522
523
    public function setResourceName(string $name): self
524
    {
525
        return $this->setName($name);
526
    }
527
}
528