Passed
Push — master ( 8c095d...771bec )
by Julito
08:03
created

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