Completed
Push — master ( be5baf...1af7e4 )
by Julito
11:10
created

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