Passed
Push — master ( b95980...a81919 )
by Julito
08:46
created

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