Passed
Push — master ( c62d0d...73098b )
by Julito
10:41
created

CGroup::setSecretDirectory()   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 ApiPlatform\Core\Annotation\ApiResource;
8
use Chamilo\CoreBundle\Entity\AbstractResource;
9
use Chamilo\CoreBundle\Entity\ResourceInterface;
10
use Chamilo\CoreBundle\Entity\User;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\Common\Collections\Criteria;
13
use Doctrine\ORM\Mapping as ORM;
14
use Symfony\Component\Validator\Constraints as Assert;
15
16
/**
17
 * @ORM\Table(
18
 *  name="c_group_info",
19
 *  indexes={
20
 *  }
21
 * )
22
 *
23
 * @ApiResource()
24
 * @ORM\Entity
25
 */
26
class CGroup 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 string
39
     * @Assert\NotBlank()
40
     * @ORM\Column(name="name", type="string", length=100, nullable=true)
41
     */
42
    protected $name;
43
44
    /**
45
     * @var bool
46
     *
47
     * @ORM\Column(name="status", type="boolean", nullable=true)
48
     */
49
    protected $status;
50
51
    /**
52
     * @var CGroupCategory
53
     *
54
     * @ORM\ManyToOne(targetEntity="CGroupCategory", cascade={"persist"})
55
     * @ORM\JoinColumn(name="category_id", referencedColumnName="iid", onDelete="CASCADE")
56
     */
57
    protected $category;
58
59
    /**
60
     * @var string
61
     *
62
     * @ORM\Column(name="description", type="text", nullable=true)
63
     */
64
    protected $description;
65
66
    /**
67
     * @var int
68
     *
69
     * @ORM\Column(name="max_student", type="integer", nullable=false)
70
     */
71
    protected $maxStudent;
72
73
    /**
74
     * @var bool
75
     *
76
     * @ORM\Column(name="doc_state", type="boolean", nullable=false)
77
     */
78
    protected $docState;
79
80
    /**
81
     * @var bool
82
     *
83
     * @ORM\Column(name="calendar_state", type="boolean", nullable=false)
84
     */
85
    protected $calendarState;
86
87
    /**
88
     * @var bool
89
     *
90
     * @ORM\Column(name="work_state", type="boolean", nullable=false)
91
     */
92
    protected $workState;
93
94
    /**
95
     * @var bool
96
     *
97
     * @ORM\Column(name="announcements_state", type="boolean", nullable=false)
98
     */
99
    protected $announcementsState;
100
101
    /**
102
     * @var bool
103
     *
104
     * @ORM\Column(name="forum_state", type="boolean", nullable=false)
105
     */
106
    protected $forumState;
107
108
    /**
109
     * @var bool
110
     *
111
     * @ORM\Column(name="wiki_state", type="boolean", nullable=false)
112
     */
113
    protected $wikiState;
114
115
    /**
116
     * @var bool
117
     *
118
     * @ORM\Column(name="chat_state", type="boolean", nullable=false)
119
     */
120
    protected $chatState;
121
122
    /**
123
     * @var string
124
     *
125
     * @ORM\Column(name="secret_directory", type="string", length=255, nullable=true)
126
     */
127
    protected $secretDirectory;
128
129
    /**
130
     * @var bool
131
     *
132
     * @ORM\Column(name="self_registration_allowed", type="boolean", nullable=false)
133
     */
134
    protected $selfRegistrationAllowed;
135
136
    /**
137
     * @var bool
138
     *
139
     * @ORM\Column(name="self_unregistration_allowed", type="boolean", nullable=false)
140
     */
141
    protected $selfUnregistrationAllowed;
142
143
    /**
144
     * @var int
145
     *
146
     * @ORM\Column(name="document_access", type="integer", nullable=false, options={"default":0})
147
     */
148
    protected $documentAccess;
149
150
    /**
151
     * @var ArrayCollection|CGroupRelUser[]
152
     *
153
     * @ORM\OneToMany(targetEntity="CGroupRelUser", mappedBy="group")
154
     */
155
    protected $members;
156
157
    /**
158
     * @var ArrayCollection|CGroupRelTutor[]
159
     *
160
     * @ORM\OneToMany(targetEntity="CGroupRelTutor", mappedBy="group")
161
     */
162
    protected $tutors;
163
164
    public function __construct()
165
    {
166
        $this->status = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $status was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
167
        $this->members = new ArrayCollection();
168
        $this->tutors = new ArrayCollection();
169
    }
170
171
    public function __toString(): string
172
    {
173
        return $this->getName();
174
    }
175
176
    /**
177
     * Get iid.
178
     *
179
     * @return int
180
     */
181
    public function getIid()
182
    {
183
        return $this->iid;
184
    }
185
186
    /**
187
     * Set name.
188
     *
189
     * @param string $name
190
     */
191
    public function setName($name): self
192
    {
193
        $this->name = $name;
194
195
        return $this;
196
    }
197
198
    /**
199
     * Get name.
200
     */
201
    public function getName(): string
202
    {
203
        return (string) $this->name;
204
    }
205
206
    /**
207
     * Set status.
208
     *
209
     * @param bool $status
210
     */
211
    public function setStatus($status): self
212
    {
213
        $this->status = $status;
214
215
        return $this;
216
    }
217
218
    /**
219
     * Get status.
220
     *
221
     * @return bool
222
     */
223
    public function getStatus()
224
    {
225
        return $this->status;
226
    }
227
228
    /**
229
     * Set description.
230
     *
231
     * @param string $description
232
     */
233
    public function setDescription($description): self
234
    {
235
        $this->description = $description;
236
237
        return $this;
238
    }
239
240
    /**
241
     * Get description.
242
     *
243
     * @return string
244
     */
245
    public function getDescription()
246
    {
247
        return $this->description;
248
    }
249
250
    public function setMaxStudent(int $maxStudent): self
251
    {
252
        $this->maxStudent = $maxStudent;
253
254
        return $this;
255
    }
256
257
    public function getMaxStudent(): int
258
    {
259
        return (int) $this->maxStudent;
260
    }
261
262
    /**
263
     * Set docState.
264
     *
265
     * @param bool $docState
266
     */
267
    public function setDocState($docState): self
268
    {
269
        $this->docState = $docState;
270
271
        return $this;
272
    }
273
274
    /**
275
     * Get docState.
276
     *
277
     * @return bool
278
     */
279
    public function getDocState()
280
    {
281
        return $this->docState;
282
    }
283
284
    /**
285
     * Set calendarState.
286
     *
287
     * @param bool $calendarState
288
     */
289
    public function setCalendarState($calendarState): self
290
    {
291
        $this->calendarState = $calendarState;
292
293
        return $this;
294
    }
295
296
    /**
297
     * Get calendarState.
298
     *
299
     * @return bool
300
     */
301
    public function getCalendarState()
302
    {
303
        return $this->calendarState;
304
    }
305
306
    /**
307
     * Set workState.
308
     *
309
     * @param bool $workState
310
     */
311
    public function setWorkState($workState): self
312
    {
313
        $this->workState = $workState;
314
315
        return $this;
316
    }
317
318
    /**
319
     * Get workState.
320
     *
321
     * @return bool
322
     */
323
    public function getWorkState()
324
    {
325
        return $this->workState;
326
    }
327
328
    /**
329
     * Set announcementsState.
330
     *
331
     * @param bool $announcementsState
332
     */
333
    public function setAnnouncementsState($announcementsState): self
334
    {
335
        $this->announcementsState = $announcementsState;
336
337
        return $this;
338
    }
339
340
    /**
341
     * Get announcementsState.
342
     *
343
     * @return bool
344
     */
345
    public function getAnnouncementsState()
346
    {
347
        return $this->announcementsState;
348
    }
349
350
    /**
351
     * Set forumState.
352
     *
353
     * @param bool $forumState
354
     */
355
    public function setForumState($forumState): self
356
    {
357
        $this->forumState = $forumState;
358
359
        return $this;
360
    }
361
362
    /**
363
     * Get forumState.
364
     *
365
     * @return bool
366
     */
367
    public function getForumState()
368
    {
369
        return $this->forumState;
370
    }
371
372
    /**
373
     * Set wikiState.
374
     *
375
     * @param bool $wikiState
376
     *
377
     * @return CGroup
378
     */
379
    public function setWikiState($wikiState)
380
    {
381
        $this->wikiState = $wikiState;
382
383
        return $this;
384
    }
385
386
    /**
387
     * Get wikiState.
388
     *
389
     * @return bool
390
     */
391
    public function getWikiState()
392
    {
393
        return $this->wikiState;
394
    }
395
396
    /**
397
     * Set chatState.
398
     *
399
     * @param bool $chatState
400
     *
401
     * @return CGroup
402
     */
403
    public function setChatState($chatState)
404
    {
405
        $this->chatState = $chatState;
406
407
        return $this;
408
    }
409
410
    /**
411
     * Get chatState.
412
     *
413
     * @return bool
414
     */
415
    public function getChatState()
416
    {
417
        return $this->chatState;
418
    }
419
420
    /**
421
     * Set secretDirectory.
422
     *
423
     * @param string $secretDirectory
424
     *
425
     * @return CGroup
426
     */
427
    public function setSecretDirectory($secretDirectory)
428
    {
429
        $this->secretDirectory = $secretDirectory;
430
431
        return $this;
432
    }
433
434
    public function getSecretDirectory(): string
435
    {
436
        return $this->secretDirectory;
437
    }
438
439
    /**
440
     * Set selfRegistrationAllowed.
441
     *
442
     * @param bool $selfRegistrationAllowed
443
     */
444
    public function setSelfRegistrationAllowed($selfRegistrationAllowed): self
445
    {
446
        $this->selfRegistrationAllowed = $selfRegistrationAllowed;
447
448
        return $this;
449
    }
450
451
    /**
452
     * Get selfRegistrationAllowed.
453
     *
454
     * @return bool
455
     */
456
    public function getSelfRegistrationAllowed()
457
    {
458
        return $this->selfRegistrationAllowed;
459
    }
460
461
    /**
462
     * Set selfUnregistrationAllowed.
463
     *
464
     * @param bool $selfUnregistrationAllowed
465
     */
466
    public function setSelfUnregistrationAllowed($selfUnregistrationAllowed): self
467
    {
468
        $this->selfUnregistrationAllowed = $selfUnregistrationAllowed;
469
470
        return $this;
471
    }
472
473
    /**
474
     * Get selfUnregistrationAllowed.
475
     *
476
     * @return bool
477
     */
478
    public function getSelfUnregistrationAllowed()
479
    {
480
        return $this->selfUnregistrationAllowed;
481
    }
482
483
    public function getDocumentAccess(): int
484
    {
485
        return $this->documentAccess;
486
    }
487
488
    public function setDocumentAccess(int $documentAccess): self
489
    {
490
        $this->documentAccess = $documentAccess;
491
492
        return $this;
493
    }
494
495
    public function getMembers()
496
    {
497
        return $this->members;
498
    }
499
500
    public function setMembers(ArrayCollection $members): self
501
    {
502
        $this->members = $members;
503
504
        return $this;
505
    }
506
507
    public function hasMembers(): bool
508
    {
509
        return $this->members->count() > 0;
510
    }
511
512
    public function getTutors()
513
    {
514
        return $this->tutors;
515
    }
516
517
    public function setTutors(ArrayCollection $tutors): self
518
    {
519
        $this->tutors = $tutors;
520
521
        return $this;
522
    }
523
524
    public function hasTutors(): bool
525
    {
526
        return $this->tutors->count() > 0;
527
    }
528
529
    public function userIsTutor(User $user = null): bool
530
    {
531
        if (empty($user)) {
532
            return false;
533
        }
534
535
        if (0 === $this->tutors->count()) {
536
            return false;
537
        }
538
539
        $criteria = Criteria::create()
540
            ->where(
541
                Criteria::expr()->eq('cId', $this->course)
0 ignored issues
show
Bug Best Practice introduced by
The property course does not exist on Chamilo\CourseBundle\Entity\CGroup. Did you maybe forget to declare it?
Loading history...
542
            )
543
            ->andWhere(
544
                Criteria::expr()->eq('user', $user)
545
            );
546
547
        $relation = $this->tutors->matching($criteria);
548
549
        return $relation->count() > 0;
550
    }
551
552
    public function getCategory(): CGroupCategory
553
    {
554
        return $this->category;
555
    }
556
557
    public function setCategory(CGroupCategory $category = null): CGroup
558
    {
559
        $this->category = $category;
560
561
        return $this;
562
    }
563
564
    public function getResourceIdentifier(): int
565
    {
566
        return $this->iid;
567
    }
568
569
    public function getResourceName(): string
570
    {
571
        return $this->getName();
572
    }
573
574
    public function setResourceName(string $name): self
575
    {
576
        return $this->setName($name);
577
    }
578
}
579