Passed
Push — master ( 401a66...0a87d5 )
by Julito
12:18
created

Course::addUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
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, ResourceToRootInterface, ResourceIllustrationInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Chamilo\CoreBundle\Entity\ResourceToRootInterface has been deprecated: use ResourceWithAccessUrlInterface ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

50
class Course extends AbstractResource implements ResourceInterface, ResourceWithAccessUrlInterface, /** @scrutinizer ignore-deprecated */ ResourceToRootInterface, ResourceIllustrationInterface

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

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