Passed
Push — master ( fad34a...39075e )
by Julito
16:30
created

Course::getSessionRelCourseRelUsers()   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
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use ApiPlatform\Core\Annotation\ApiFilter;
10
use ApiPlatform\Core\Annotation\ApiProperty;
11
use ApiPlatform\Core\Annotation\ApiResource;
12
use ApiPlatform\Core\Annotation\ApiSubresource;
13
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
14
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
15
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
16
use Chamilo\CourseBundle\Entity\CGroup;
17
use Chamilo\CourseBundle\Entity\CTool;
18
use DateTime;
19
use Doctrine\Common\Collections\ArrayCollection;
20
use Doctrine\Common\Collections\Collection;
21
use Doctrine\Common\Collections\Criteria;
22
use Doctrine\ORM\Mapping as ORM;
23
use Gedmo\Mapping\Annotation as Gedmo;
24
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
25
use Symfony\Component\Serializer\Annotation\Groups;
26
use Symfony\Component\Validator\Constraints as Assert;
27
28
/**
29
 * @ApiResource(
30
 *     attributes={"security"="is_granted('ROLE_ADMIN')"},
31
 *     iri="https://schema.org/Course",
32
 *     normalizationContext={"groups"={"course:read"}, "swagger_definition_name"="Read"},
33
 *     denormalizationContext={"groups"={"course:write"}},
34
 * )
35
 *
36
 * @ApiFilter(SearchFilter::class, properties={"title": "partial", "code": "partial"})
37
 * @ApiFilter(PropertyFilter::class)
38
 * @ApiFilter(OrderFilter::class, properties={"id", "title"})
39
 *
40
 * @ORM\Table(
41
 *     name="course",
42
 *     indexes={
43
 *     }
44
 * )
45
 * @UniqueEntity("code")
46
 * @UniqueEntity("visualCode")
47
 * @ORM\Entity
48
 * @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\ResourceListener", "Chamilo\CoreBundle\Entity\Listener\CourseListener"})
49
 */
50
class Course extends AbstractResource implements ResourceInterface, ResourceWithAccessUrlInterface, ResourceIllustrationInterface
51
{
52
    public const CLOSED = 0;
53
    public const REGISTERED = 1;
54
    public const OPEN_PLATFORM = 2;
55
    public const OPEN_WORLD = 3;
56
    public const HIDDEN = 4;
57
58
    /**
59
     * @Groups({"course:read", "course_rel_user:read", "session_rel_user:read", "session_rel_course_rel_user:read", "session_rel_user:read"})
60
     * @ORM\Column(name="id", type="integer")
61
     * @ORM\Id
62
     * @ORM\GeneratedValue(strategy="AUTO")
63
     */
64
    protected ?int $id = null;
65
66
    /**
67
     * The course title.
68
     *
69
     * @Assert\NotBlank(message="A Course requires a title")
70
     *
71
     * @Groups({"course:read", "course:write", "course_rel_user:read", "session_rel_course_rel_user:read", "session_rel_user:read"})
72
     *
73
     * @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false)
74
     */
75
    protected ?string $title = null;
76
77
    /**
78
     * The course code.
79
     *
80
     * @Assert\NotBlank()
81
     * @Assert\Length(
82
     *     max = 40,
83
     *     maxMessage = "Code cannot be longer than {{ limit }} characters"
84
     * )
85
     * @ApiProperty(iri="http://schema.org/courseCode")
86
     * @Groups({"course:read", "course:write", "course_rel_user:read"})
87
     *
88
     * @Gedmo\Slug(
89
     *     fields={"title"},
90
     *     updatable=false,
91
     *     unique=true,
92
     *     separator="",
93
     *     style="upper"
94
     * )
95
     * @ORM\Column(name="code", type="string", length=40, nullable=false, unique=true)
96
     */
97
    protected string $code;
98
99
    /**
100
     * @Assert\Length(
101
     *     max = 40,
102
     *     maxMessage = "Code cannot be longer than {{ limit }} characters"
103
     * )
104
     * @ORM\Column(name="visual_code", type="string", length=40, nullable=true, unique=false)
105
     */
106
    protected ?string $visualCode = null;
107
108
    /**
109
     * @var Collection|CourseRelUser[]
110
     *
111
     * @ApiSubresource()
112
     * @Groups({"course:read", "user:read"})
113
     * "orphanRemoval" is needed to delete the CourseRelUser relation
114
     * in the CourseAdmin class. The setUsers, getUsers, removeUsers and
115
     * addUsers methods need to be added.
116
     *
117
     * @ORM\OneToMany(targetEntity="CourseRelUser", mappedBy="course", cascade={"persist"}, orphanRemoval=true)
118
     */
119
    protected Collection $users;
120
121
    /**
122
     * @var AccessUrlRelCourse[]|Collection
123
     *
124
     * @ORM\OneToMany(
125
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelCourse",
126
     *     mappedBy="course", cascade={"persist", "remove"}, orphanRemoval=true
127
     * )
128
     */
129
    protected Collection $urls;
130
131
    /**
132
     * @var Collection|SessionRelCourse[]
133
     *
134
     * @ORM\OneToMany(targetEntity="SessionRelCourse", mappedBy="course", cascade={"persist", "remove"})
135
     */
136
    protected Collection $sessions;
137
138
    /**
139
     * @var Collection|SessionRelCourseRelUser[]
140
     *
141
     * @ORM\OneToMany(targetEntity="SessionRelCourseRelUser", mappedBy="course", cascade={"persist", "remove"})
142
     */
143
    protected Collection $sessionRelCourseRelUsers;
144
145
    /**
146
     * @var Collection|CTool[]
147
     *
148
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CTool", mappedBy="course", cascade={"persist", "remove"})
149
     */
150
    protected Collection $tools;
151
152
    protected Session $currentSession;
153
154
    protected AccessUrl $currentUrl;
155
156
    /**
157
     * @var Collection|SkillRelCourse[]
158
     *
159
     * @ORM\OneToMany(targetEntity="SkillRelCourse", mappedBy="course", cascade={"persist", "remove"})
160
     */
161
    protected Collection $skills;
162
163
    /**
164
     * @var Collection|SkillRelUser[]
165
     *
166
     * @ORM\OneToMany(targetEntity="SkillRelUser", mappedBy="course", cascade={"persist", "remove"})
167
     */
168
    protected Collection $issuedSkills;
169
170
    /**
171
     * @var Collection|GradebookCategory[]
172
     *
173
     * @ORM\OneToMany(targetEntity="GradebookCategory", mappedBy="course", cascade={"persist", "remove"})
174
     */
175
    protected Collection $gradebookCategories;
176
177
    /**
178
     * @var Collection|GradebookEvaluation[]
179
     *
180
     * @ORM\OneToMany(targetEntity="GradebookEvaluation", mappedBy="course", cascade={"persist", "remove"})
181
     */
182
    protected Collection $gradebookEvaluations;
183
184
    /**
185
     * @var Collection|GradebookLink[]
186
     *
187
     * @ORM\OneToMany(targetEntity="GradebookLink", mappedBy="course", cascade={"persist", "remove"})
188
     */
189
    protected Collection $gradebookLinks;
190
191
    /**
192
     * @var Collection|TrackEHotspot[]
193
     *
194
     * @ORM\OneToMany(targetEntity="TrackEHotspot", mappedBy="course", cascade={"persist", "remove"})
195
     */
196
    protected Collection $trackEHotspots;
197
198
    /**
199
     * @var Collection|TrackEAttempt[]
200
     *
201
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\TrackEAttempt", mappedBy="course", cascade={"persist", "remove"})
202
     */
203
    protected Collection $trackEAttempts;
204
205
    /**
206
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SearchEngineRef", mappedBy="course", cascade={"persist", "remove"})
207
     *
208
     * @var SearchEngineRef[]|Collection
209
     */
210
    protected Collection $searchEngineRefs;
211
212
    /**
213
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Templates", mappedBy="course", cascade={"persist", "remove"})
214
     *
215
     * @var Templates[]|Collection
216
     */
217
    protected Collection $templates;
218
219
    /**
220
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course")
221
     */
222
    //protected $specificFieldValues;
223
224
    /**
225
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course")
226
     */
227
    //protected $sharedSurveys;
228
229
    /**
230
     * @ORM\Column(name="directory", type="string", length=40, nullable=true, unique=false)
231
     */
232
    protected ?string $directory = null;
233
234
    /**
235
     * @Groups({"course:read", "list"})
236
     * @ORM\Column(name="course_language", type="string", length=20, nullable=false, unique=false)
237
     */
238
    protected string $courseLanguage;
239
240
    /**
241
     * @Groups({"course:read", "course_rel_user:read"})
242
     *
243
     * @ORM\Column(name="description", type="text", nullable=true, unique=false)
244
     */
245
    protected ?string $description;
246
247
    /**
248
     * @ApiSubresource()
249
     * @Groups({"course:read", "course:write", "course_rel_user:read"})
250
     * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="courses")
251
     * @ORM\JoinTable(
252
     *     name="course_rel_category",
253
     *     joinColumns={
254
     *         @ORM\JoinColumn(name="course_id", referencedColumnName="id")
255
     *     },
256
     *     inverseJoinColumns={
257
     *         @ORM\JoinColumn(name="course_category_id", referencedColumnName="id")}
258
     * )
259
     */
260
    protected Collection $categories;
261
262
    /**
263
     * @var int Course visibility
264
     *
265
     * @Groups({"course:read", "course:write"})
266
     * @Assert\NotBlank()
267
     *
268
     * @ORM\Column(name="visibility", type="integer", nullable=false, unique=false)
269
     */
270
    protected int $visibility;
271
272
    /**
273
     * @ORM\Column(name="show_score", type="integer", nullable=true, unique=false)
274
     */
275
    protected ?int $showScore = null;
276
277
    /**
278
     * @ORM\Column(name="tutor_name", type="string", length=200, nullable=true, unique=false)
279
     */
280
    protected ?string $tutorName;
281
282
    /**
283
     * @Groups({"course:read", "list"})
284
     * @ORM\Column(name="department_name", type="string", length=30, nullable=true, unique=false)
285
     */
286
    protected ?string $departmentName = null;
287
288
    /**
289
     * @Groups({"course:read", "list"})
290
     * @Assert\Url()
291
     *
292
     * @ORM\Column(name="department_url", type="string", length=180, nullable=true, unique=false)
293
     */
294
    protected ?string $departmentUrl = null;
295
296
    /**
297
     * @ORM\Column(name="disk_quota", type="bigint", nullable=true, unique=false)
298
     */
299
    protected ?int $diskQuota = null;
300
301
    /**
302
     * @ORM\Column(name="last_visit", type="datetime", nullable=true, unique=false)
303
     */
304
    protected ?DateTime $lastVisit;
305
306
    /**
307
     * @ORM\Column(name="last_edit", type="datetime", nullable=true, unique=false)
308
     */
309
    protected ?DateTime $lastEdit;
310
311
    /**
312
     * @ORM\Column(name="creation_date", type="datetime", nullable=false, unique=false)
313
     */
314
    protected DateTime $creationDate;
315
316
    /**
317
     * @Groups({"course:read", "list"})
318
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
319
     */
320
    protected ?DateTime $expirationDate = null;
321
322
    /**
323
     * @ORM\Column(name="subscribe", type="boolean", nullable=false, unique=false)
324
     */
325
    protected bool $subscribe;
326
327
    /**
328
     * @ORM\Column(name="unsubscribe", type="boolean", nullable=false, unique=false)
329
     */
330
    protected bool $unsubscribe;
331
332
    /**
333
     * @ORM\Column(name="registration_code", type="string", length=255, nullable=true, unique=false)
334
     */
335
    protected ?string $registrationCode;
336
337
    /**
338
     * @ORM\Column(name="legal", type="text", nullable=true, unique=false)
339
     */
340
    protected ?string $legal;
341
342
    /**
343
     * @ORM\Column(name="activate_legal", type="integer", nullable=true, unique=false)
344
     */
345
    protected ?int $activateLegal;
346
347
    /**
348
     * @ORM\Column(name="add_teachers_to_sessions_courses", type="boolean", nullable=true)
349
     */
350
    protected ?bool $addTeachersToSessionsCourses;
351
352
    /**
353
     * @ORM\Column(name="course_type_id", type="integer", nullable=true, unique=false)
354
     */
355
    protected ?int $courseTypeId;
356
357
    /**
358
     * ORM\OneToMany(targetEntity="CurriculumCategory", mappedBy="course").
359
     */
360
    //protected $curriculumCategories;
361
362
    /**
363
     * @ORM\ManyToOne(targetEntity="Room")
364
     * @ORM\JoinColumn(name="room_id", referencedColumnName="id")
365
     */
366
    protected ?Room $room;
367
368
    public function __construct()
369
    {
370
        $this->sessions = new ArrayCollection();
371
        $this->sessionRelCourseRelUsers = new ArrayCollection();
372
        $this->skills = new ArrayCollection();
373
        $this->issuedSkills = new ArrayCollection();
374
        $this->creationDate = new DateTime();
375
        $this->lastVisit = new DateTime();
376
        $this->lastEdit = new DateTime();
377
        $this->description = '';
378
        $this->tutorName = '';
379
        $this->registrationCode = null;
380
        $this->legal = '';
381
        $this->users = new ArrayCollection();
382
        $this->urls = new ArrayCollection();
383
        $this->tools = new ArrayCollection();
384
        $this->categories = new ArrayCollection();
385
        $this->gradebookCategories = new ArrayCollection();
386
        $this->gradebookEvaluations = new ArrayCollection();
387
        $this->gradebookLinks = new ArrayCollection();
388
        $this->trackEHotspots = new ArrayCollection();
389
        $this->trackEAttempts = new ArrayCollection();
390
        $this->searchEngineRefs = new ArrayCollection();
391
        $this->templates = new ArrayCollection();
392
        $this->activateLegal = 0;
393
        $this->addTeachersToSessionsCourses = false;
394
        $this->courseTypeId = null;
395
        $this->room = null;
396
        $this->courseLanguage = 'en';
397
        $this->visibility = self::OPEN_PLATFORM;
398
        $this->subscribe = true;
399
        $this->unsubscribe = false;
400
        //$this->specificFieldValues = new ArrayCollection();
401
        //$this->sharedSurveys = new ArrayCollection();
402
    }
403
404
    public function __toString(): string
405
    {
406
        return $this->getTitle();
407
    }
408
409
    public function getSessions()
410
    {
411
        return $this->sessions;
412
    }
413
414
    public function getTools()
415
    {
416
        return $this->tools;
417
    }
418
419
    public function setTools(array $tools)
420
    {
421
        foreach ($tools as $tool) {
422
            $this->addTool($tool);
423
        }
424
425
        return $this;
426
    }
427
428
    public function addTool(CTool $tool)
429
    {
430
        $tool->setCourse($this);
431
        $this->tools->add($tool);
432
433
        return $this;
434
    }
435
436
    /**
437
     * @return AccessUrlRelCourse[]|Collection
438
     */
439
    public function getUrls()
440
    {
441
        return $this->urls;
442
    }
443
444
    public function setUrls(Collection $urls)
445
    {
446
        $this->urls = new ArrayCollection();
447
        foreach ($urls as $url) {
448
            $this->addAccessUrl($url);
449
        }
450
451
        return $this;
452
    }
453
454
    public function addUrlRelCourse(AccessUrlRelCourse $accessUrlRelCourse)
455
    {
456
        $accessUrlRelCourse->setCourse($this);
457
        $this->urls->add($accessUrlRelCourse);
458
459
        return $this;
460
    }
461
462
    public function addAccessUrl(AccessUrl $url): self
463
    {
464
        $urlRelCourse = new AccessUrlRelCourse();
465
        $urlRelCourse->setCourse($this);
466
        $urlRelCourse->setUrl($url);
467
        $this->addUrlRelCourse($urlRelCourse);
468
469
        return $this;
470
    }
471
472
    /**
473
     * @return Collection|CourseRelUser[]
474
     */
475
    public function getUsers()
476
    {
477
        return $this->users;
478
    }
479
480
    /**
481
     * @return Collection|CourseRelUser[]
482
     */
483
    public function getTeachers()
484
    {
485
        $criteria = Criteria::create();
486
        $criteria->where(Criteria::expr()->eq('status', User::COURSE_MANAGER));
487
488
        return $this->users->matching($criteria);
489
    }
490
491
    /**
492
     * @return Collection|CourseRelUser[]
493
     */
494
    public function getStudents()
495
    {
496
        $criteria = Criteria::create();
497
        $criteria->where(Criteria::expr()->eq('status', User::STUDENT));
498
499
        return $this->users->matching($criteria);
500
    }
501
502
    public function setUsers(Collection $users)
503
    {
504
        $this->users = new ArrayCollection();
505
506
        foreach ($users as $user) {
507
            $this->addUsers($user);
508
        }
509
510
        return $this;
511
    }
512
513
    public function addUsers(CourseRelUser $courseRelUser)
514
    {
515
        $courseRelUser->setCourse($this);
516
517
        if (!$this->hasSubscription($courseRelUser)) {
518
            $this->users->add($courseRelUser);
519
        }
520
521
        return $this;
522
    }
523
524
    public function hasUser(User $user): bool
525
    {
526
        $criteria = Criteria::create()->where(
527
            Criteria::expr()->eq('user', $user)
528
        );
529
530
        return $this->getUsers()->matching($criteria)->count() > 0;
531
    }
532
533
    public function hasStudent(User $user): bool
534
    {
535
        $criteria = Criteria::create()->where(
536
            Criteria::expr()->eq('user', $user)
537
        );
538
539
        return $this->getStudents()->matching($criteria)->count() > 0;
540
    }
541
542
    public function hasTeacher(User $user): bool
543
    {
544
        $criteria = Criteria::create()->where(
545
            Criteria::expr()->eq('user', $user)
546
        );
547
548
        return $this->getTeachers()->matching($criteria)->count() > 0;
549
    }
550
551
    public function hasGroup(CGroup $group): void
552
    {
553
        /*$criteria = Criteria::create()->where(
554
            Criteria::expr()->eq('groups', $group)
555
        );*/
556
557
        //return $this->getGroups()->contains($group);
558
    }
559
560
    /**
561
     * Remove $user.
562
     */
563
    public function removeUsers(CourseRelUser $user): void
564
    {
565
        foreach ($this->users as $key => $value) {
566
            if ($value->getId() === $user->getId()) {
567
                unset($this->users[$key]);
568
            }
569
        }
570
    }
571
572
    public function addTeacher(User $user)
573
    {
574
        $this->addUser($user, 0, 'Trainer', User::COURSE_MANAGER);
575
576
        return $this;
577
    }
578
579
    public function addStudent(User $user)
580
    {
581
        $this->addUser($user, 0, '', User::STUDENT);
582
583
        return $this;
584
    }
585
586
    /**
587
     * Get id.
588
     *
589
     * @return int
590
     */
591
    public function getId()
592
    {
593
        return $this->id;
594
    }
595
596
    public function setCode(string $code): self
597
    {
598
        $this->code = $code;
599
        $this->visualCode = $code;
600
601
        return $this;
602
    }
603
604
    public function getCode(): string
605
    {
606
        return $this->code;
607
    }
608
609
    /**
610
     * Get directory.
611
     *
612
     * @return string
613
     */
614
    public function getDirectory()
615
    {
616
        return $this->directory;
617
    }
618
619
    public function setCourseLanguage(string $courseLanguage): self
620
    {
621
        $this->courseLanguage = $courseLanguage;
622
623
        return $this;
624
    }
625
626
    public function getCourseLanguage(): string
627
    {
628
        return $this->courseLanguage;
629
    }
630
631
    public function setTitle(string $title): self
632
    {
633
        $this->title = $title;
634
635
        // Set the code based in the title if it doesnt exists.
636
        if (empty($this->code)) {
637
            $this->setCode($title);
638
        }
639
640
        return $this;
641
    }
642
643
    public function getTitle(): string
644
    {
645
        return $this->title;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->title could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
646
    }
647
648
    public function getName()
649
    {
650
        return $this->getTitle();
651
    }
652
653
    public function getTitleAndCode(): string
654
    {
655
        return $this->getTitle().' ('.$this->getCode().')';
656
    }
657
658
    public function setDescription(string $description): self
659
    {
660
        $this->description = $description;
661
662
        return $this;
663
    }
664
665
    public function getDescription(): ?string
666
    {
667
        return $this->description;
668
    }
669
670
    public function setCategories(Collection $categories): self
671
    {
672
        $this->categories = $categories;
673
674
        return $this;
675
    }
676
677
    public function getCategories()
678
    {
679
        return $this->categories;
680
    }
681
682
    public function addCategory(CourseCategory $category): self
683
    {
684
        $this->categories[] = $category;
685
686
        return $this;
687
    }
688
689
    public function removeCategory(CourseCategory $category): void
690
    {
691
        $this->categories->removeElement($category);
692
    }
693
694
    public function setVisibility(int $visibility): self
695
    {
696
        $this->visibility = $visibility;
697
698
        return $this;
699
    }
700
701
    public function getVisibility(): int
702
    {
703
        return $this->visibility;
704
    }
705
706
    public function setShowScore(int $showScore): self
707
    {
708
        $this->showScore = $showScore;
709
710
        return $this;
711
    }
712
713
    /**
714
     * Get showScore.
715
     *
716
     * @return int
717
     */
718
    public function getShowScore()
719
    {
720
        return $this->showScore;
721
    }
722
723
    public function setTutorName(?string $tutorName): self
724
    {
725
        $this->tutorName = $tutorName;
726
727
        return $this;
728
    }
729
730
    public function getTutorName(): ?string
731
    {
732
        return $this->tutorName;
733
    }
734
735
    public function setVisualCode(string $visualCode): self
736
    {
737
        $this->visualCode = $visualCode;
738
739
        return $this;
740
    }
741
742
    /**
743
     * Get visualCode.
744
     *
745
     * @return string
746
     */
747
    public function getVisualCode()
748
    {
749
        return $this->visualCode;
750
    }
751
752
    public function setDepartmentName(string $departmentName): self
753
    {
754
        $this->departmentName = $departmentName;
755
756
        return $this;
757
    }
758
759
    /**
760
     * Get departmentName.
761
     *
762
     * @return string
763
     */
764
    public function getDepartmentName()
765
    {
766
        return $this->departmentName;
767
    }
768
769
    public function setDepartmentUrl(string $departmentUrl): self
770
    {
771
        $this->departmentUrl = $departmentUrl;
772
773
        return $this;
774
    }
775
776
    /**
777
     * Get departmentUrl.
778
     *
779
     * @return string
780
     */
781
    public function getDepartmentUrl()
782
    {
783
        return $this->departmentUrl;
784
    }
785
786
    public function setDiskQuota(int $diskQuota): self
787
    {
788
        $this->diskQuota = $diskQuota;
789
790
        return $this;
791
    }
792
793
    /**
794
     * Get diskQuota.
795
     *
796
     * @return int
797
     */
798
    public function getDiskQuota()
799
    {
800
        return $this->diskQuota;
801
    }
802
803
    public function setLastVisit(DateTime $lastVisit): self
804
    {
805
        $this->lastVisit = $lastVisit;
806
807
        return $this;
808
    }
809
810
    /**
811
     * Get lastVisit.
812
     *
813
     * @return DateTime
814
     */
815
    public function getLastVisit()
816
    {
817
        return $this->lastVisit;
818
    }
819
820
    public function setLastEdit(DateTime $lastEdit): self
821
    {
822
        $this->lastEdit = $lastEdit;
823
824
        return $this;
825
    }
826
827
    /**
828
     * Get lastEdit.
829
     *
830
     * @return DateTime
831
     */
832
    public function getLastEdit()
833
    {
834
        return $this->lastEdit;
835
    }
836
837
    public function setCreationDate(DateTime $creationDate): self
838
    {
839
        $this->creationDate = $creationDate;
840
841
        return $this;
842
    }
843
844
    /**
845
     * Get creationDate.
846
     *
847
     * @return DateTime
848
     */
849
    public function getCreationDate()
850
    {
851
        return $this->creationDate;
852
    }
853
854
    public function setExpirationDate(DateTime $expirationDate): self
855
    {
856
        $this->expirationDate = $expirationDate;
857
858
        return $this;
859
    }
860
861
    /**
862
     * Get expirationDate.
863
     *
864
     * @return DateTime
865
     */
866
    public function getExpirationDate()
867
    {
868
        return $this->expirationDate;
869
    }
870
871
    public function setSubscribe(bool $subscribe): self
872
    {
873
        $this->subscribe = $subscribe;
874
875
        return $this;
876
    }
877
878
    /**
879
     * Get subscribe.
880
     *
881
     * @return bool
882
     */
883
    public function getSubscribe()
884
    {
885
        return $this->subscribe;
886
    }
887
888
    public function setUnsubscribe(bool $unsubscribe): self
889
    {
890
        $this->unsubscribe = $unsubscribe;
891
892
        return $this;
893
    }
894
895
    /**
896
     * Get unsubscribe.
897
     *
898
     * @return bool
899
     */
900
    public function getUnsubscribe()
901
    {
902
        return $this->unsubscribe;
903
    }
904
905
    public function setRegistrationCode(string $registrationCode): self
906
    {
907
        $this->registrationCode = $registrationCode;
908
909
        return $this;
910
    }
911
912
    /**
913
     * Get registrationCode.
914
     *
915
     * @return string
916
     */
917
    public function getRegistrationCode()
918
    {
919
        return $this->registrationCode;
920
    }
921
922
    public function setLegal(string $legal): self
923
    {
924
        $this->legal = $legal;
925
926
        return $this;
927
    }
928
929
    /**
930
     * Get legal.
931
     *
932
     * @return string
933
     */
934
    public function getLegal()
935
    {
936
        return $this->legal;
937
    }
938
939
    public function setActivateLegal(int $activateLegal): self
940
    {
941
        $this->activateLegal = $activateLegal;
942
943
        return $this;
944
    }
945
946
    /**
947
     * Get activateLegal.
948
     *
949
     * @return int
950
     */
951
    public function getActivateLegal()
952
    {
953
        return $this->activateLegal;
954
    }
955
956
    /**
957
     * @return bool
958
     */
959
    public function isAddTeachersToSessionsCourses()
960
    {
961
        return $this->addTeachersToSessionsCourses;
962
    }
963
964
    public function setAddTeachersToSessionsCourses(bool $addTeachersToSessionsCourses): self
965
    {
966
        $this->addTeachersToSessionsCourses = $addTeachersToSessionsCourses;
967
968
        return $this;
969
    }
970
971
    public function setCourseTypeId(int $courseTypeId): self
972
    {
973
        $this->courseTypeId = $courseTypeId;
974
975
        return $this;
976
    }
977
978
    /**
979
     * Get courseTypeId.
980
     *
981
     * @return int
982
     */
983
    public function getCourseTypeId()
984
    {
985
        return $this->courseTypeId;
986
    }
987
988
    public function getRoom(): ?Room
989
    {
990
        return $this->room;
991
    }
992
993
    public function setRoom(Room $room): self
994
    {
995
        $this->room = $room;
996
997
        return $this;
998
    }
999
1000
    public function isActive(): bool
1001
    {
1002
        $activeVisibilityList = [
1003
            self::REGISTERED,
1004
            self::OPEN_PLATFORM,
1005
            self::OPEN_WORLD,
1006
        ];
1007
1008
        return \in_array($this->visibility, $activeVisibilityList, true);
1009
    }
1010
1011
    /**
1012
     * Anybody can see this course.
1013
     */
1014
    public function isPublic(): bool
1015
    {
1016
        return self::OPEN_WORLD === $this->visibility;
1017
    }
1018
1019
    public function isHidden(): bool
1020
    {
1021
        return self::HIDDEN === $this->visibility;
1022
    }
1023
1024
    public static function getStatusList(): array
1025
    {
1026
        return [
1027
            self::CLOSED => 'Closed',
1028
            self::REGISTERED => 'Registered',
1029
            self::OPEN_PLATFORM => 'Open platform',
1030
            self::OPEN_WORLD => 'Open world',
1031
            self::HIDDEN => 'Hidden',
1032
        ];
1033
    }
1034
1035
    /**
1036
     * @return Session
1037
     */
1038
    public function getCurrentSession()
1039
    {
1040
        return $this->currentSession;
1041
    }
1042
1043
    public function setCurrentSession(Session $session): self
1044
    {
1045
        // If the session is registered in the course session list.
1046
        /*if ($this->getSessions()->contains($session->getId())) {
1047
            $this->currentSession = $session;
1048
        }*/
1049
1050
        $list = $this->getSessions();
1051
        /** @var SessionRelCourse $item */
1052
        foreach ($list as $item) {
1053
            if ($item->getSession()->getId() === $session->getId()) {
1054
                $this->currentSession = $session;
1055
1056
                break;
1057
            }
1058
        }
1059
1060
        return $this;
1061
    }
1062
1063
    public function setCurrentUrl(AccessUrl $url): self
1064
    {
1065
        $urlList = $this->getUrls();
1066
        /** @var AccessUrlRelCourse $item */
1067
        foreach ($urlList as $item) {
1068
            if ($item->getUrl()->getId() === $url->getId()) {
1069
                $this->currentUrl = $url;
1070
1071
                break;
1072
            }
1073
        }
1074
1075
        return $this;
1076
    }
1077
1078
    /**
1079
     * @return AccessUrl
1080
     */
1081
    public function getCurrentUrl()
1082
    {
1083
        return $this->currentUrl;
1084
    }
1085
1086
    /**
1087
     * Get issuedSkills.
1088
     *
1089
     * @return Collection
1090
     */
1091
    public function getIssuedSkills()
1092
    {
1093
        return $this->issuedSkills;
1094
    }
1095
1096
    public function hasSubscription(CourseRelUser $subscription): bool
1097
    {
1098
        if (0 !== $this->getUsers()->count()) {
1099
            $criteria = Criteria::create()->where(
1100
                Criteria::expr()->eq('user', $subscription->getUser())
1101
            )->andWhere(
1102
                Criteria::expr()->eq('status', $subscription->getStatus())
1103
            )->andWhere(
1104
                Criteria::expr()->eq('relationType', $subscription->getRelationType())
1105
            );
1106
1107
            $relation = $this->getUsers()->matching($criteria);
1108
1109
            return $relation->count() > 0;
1110
        }
1111
1112
        return false;
1113
    }
1114
1115
    public function addUser(User $user, int $relationType, $role, int $status): self
1116
    {
1117
        $courseRelUser = new CourseRelUser();
1118
        $courseRelUser->setCourse($this);
1119
        $courseRelUser->setUser($user);
1120
        $courseRelUser->setRelationType($relationType);
1121
        //$courseRelUser->setRole($role);
1122
        $courseRelUser->setStatus($status);
1123
        $this->addUsers($courseRelUser);
1124
1125
        return $this;
1126
    }
1127
1128
    /**
1129
     * @return SessionRelCourseRelUser[]|Collection
1130
     */
1131
    public function getSessionRelCourseRelUsers()
1132
    {
1133
        return $this->sessionRelCourseRelUsers;
1134
    }
1135
1136
    public function setSessionRelCourseRelUsers(Collection $sessionUserSubscriptions): self
1137
    {
1138
        $this->sessionRelCourseRelUsers = $sessionUserSubscriptions;
1139
1140
        return $this;
1141
    }
1142
1143
    /**
1144
     * @return SkillRelCourse[]|Collection
1145
     */
1146
    public function getSkills()
1147
    {
1148
        return $this->skills;
1149
    }
1150
1151
    /**
1152
     * @param SkillRelCourse[]|Collection $skills
1153
     */
1154
    public function setSkills(Collection $skills): self
1155
    {
1156
        $this->skills = $skills;
1157
1158
        return $this;
1159
    }
1160
1161
    /**
1162
     * @return GradebookCategory[]|Collection
1163
     */
1164
    public function getGradebookCategories()
1165
    {
1166
        return $this->gradebookCategories;
1167
    }
1168
1169
    /**
1170
     * @param GradebookCategory[]|Collection $gradebookCategories
1171
     */
1172
    public function setGradebookCategories(Collection $gradebookCategories): self
1173
    {
1174
        $this->gradebookCategories = $gradebookCategories;
1175
1176
        return $this;
1177
    }
1178
1179
    /**
1180
     * @return GradebookEvaluation[]|Collection
1181
     */
1182
    public function getGradebookEvaluations()
1183
    {
1184
        return $this->gradebookEvaluations;
1185
    }
1186
1187
    /**
1188
     * @param GradebookEvaluation[]|Collection $gradebookEvaluations
1189
     */
1190
    public function setGradebookEvaluations(Collection $gradebookEvaluations): self
1191
    {
1192
        $this->gradebookEvaluations = $gradebookEvaluations;
1193
1194
        return $this;
1195
    }
1196
1197
    /**
1198
     * @return GradebookLink[]|Collection
1199
     */
1200
    public function getGradebookLinks()
1201
    {
1202
        return $this->gradebookLinks;
1203
    }
1204
1205
    /**
1206
     * @param GradebookLink[]|Collection $gradebookLinks
1207
     */
1208
    public function setGradebookLinks(Collection $gradebookLinks): self
1209
    {
1210
        $this->gradebookLinks = $gradebookLinks;
1211
1212
        return $this;
1213
    }
1214
1215
    /**
1216
     * @return TrackEHotspot[]|Collection
1217
     */
1218
    public function getTrackEHotspots()
1219
    {
1220
        return $this->trackEHotspots;
1221
    }
1222
1223
    /**
1224
     * @param TrackEHotspot[]|Collection $trackEHotspots
1225
     */
1226
    public function setTrackEHotspots(Collection $trackEHotspots): self
1227
    {
1228
        $this->trackEHotspots = $trackEHotspots;
1229
1230
        return $this;
1231
    }
1232
1233
    /**
1234
     * @return TrackEAttempt[]|Collection
1235
     */
1236
    public function getTrackEAttempts()
1237
    {
1238
        return $this->trackEAttempts;
1239
    }
1240
1241
    /**
1242
     * @param TrackEAttempt[]|Collection $trackEAttempts
1243
     */
1244
    public function setTrackEAttempts(Collection $trackEAttempts): self
1245
    {
1246
        $this->trackEAttempts = $trackEAttempts;
1247
1248
        return $this;
1249
    }
1250
1251
    /**
1252
     * @return SearchEngineRef[]|Collection
1253
     */
1254
    public function getSearchEngineRefs()
1255
    {
1256
        return $this->searchEngineRefs;
1257
    }
1258
1259
    /**
1260
     * @param SearchEngineRef[]|Collection $searchEngineRefs
1261
     */
1262
    public function setSearchEngineRefs(Collection $searchEngineRefs): self
1263
    {
1264
        $this->searchEngineRefs = $searchEngineRefs;
1265
1266
        return $this;
1267
    }
1268
1269
    /**
1270
     * @return Templates[]|Collection
1271
     */
1272
    public function getTemplates()
1273
    {
1274
        return $this->templates;
1275
    }
1276
1277
    /**
1278
     * @param Templates[]|Collection $templates
1279
     */
1280
    public function setTemplates(Collection $templates): self
1281
    {
1282
        $this->templates = $templates;
1283
1284
        return $this;
1285
    }
1286
1287
    public function getDefaultIllustration(int $size): string
1288
    {
1289
        return '/img/icons/32/course.png';
1290
    }
1291
1292
    public function getResourceIdentifier(): int
1293
    {
1294
        return $this->getId();
1295
    }
1296
1297
    public function getResourceName(): string
1298
    {
1299
        return $this->getCode();
1300
    }
1301
1302
    public function setResourceName(string $name): self
1303
    {
1304
        return $this->setCode($name);
1305
    }
1306
}
1307