Passed
Push — master ( 3ef090...0b35a3 )
by Julito
12:21
created

Course::setId()   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 1
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(message="A Course requires a title")
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
     * @var ArrayCollection|AccessUrlRelCourse[]
120
     * @ORM\OneToMany(targetEntity="AccessUrlRelCourse", mappedBy="course", cascade={"persist", "remove"}, orphanRemoval=true)
121
     */
122
    protected $urls;
123
124
    /**
125
     * @var SessionRelCourse[]
126
     *
127
     * @ORM\OneToMany(targetEntity="SessionRelCourse", mappedBy="course", cascade={"persist", "remove"})
128
     */
129
    protected $sessions;
130
131
    /**
132
     * @ORM\OneToMany(targetEntity="SessionRelCourseRelUser", mappedBy="course", cascade={"persist", "remove"})
133
     */
134
    protected $sessionUserSubscriptions;
135
136
    /**
137
     * @var CTool[]|ArrayCollection
138
     *
139
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CTool", mappedBy="course", cascade={"persist", "remove"})
140
     */
141
    protected $tools;
142
143
    /**
144
     * @var Session
145
     */
146
    protected $currentSession;
147
148
    /**
149
     * @var AccessUrl
150
     */
151
    protected $currentUrl;
152
153
    /**
154
     * @ORM\OneToMany(targetEntity="SkillRelCourse", mappedBy="course", cascade={"persist", "remove"})
155
     */
156
    protected $skills;
157
158
    /**
159
     * @ORM\OneToMany(targetEntity="SkillRelUser", mappedBy="course", cascade={"persist", "remove"})
160
     */
161
    protected $issuedSkills;
162
163
    /**
164
     * @ORM\OneToMany(targetEntity="GradebookCategory", mappedBy="course", cascade={"persist", "remove"})
165
     */
166
    protected $gradebookCategories;
167
168
    /**
169
     * @ORM\OneToMany(targetEntity="GradebookEvaluation", mappedBy="course", cascade={"persist", "remove"})
170
     */
171
    protected $gradebookEvaluations;
172
173
    /**
174
     * @ORM\OneToMany(targetEntity="GradebookLink", mappedBy="course", cascade={"persist", "remove"})
175
     */
176
    protected $gradebookLinks;
177
178
    /**
179
     * @ORM\OneToMany(targetEntity="TrackEHotspot", mappedBy="course", cascade={"persist", "remove"})
180
     */
181
    protected $trackEHotspots;
182
183
    /**
184
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\TrackEAttempt", mappedBy="course", cascade={"persist", "remove"})
185
     */
186
    protected $trackEAttempts;
187
188
    /**
189
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SearchEngineRef", mappedBy="course", cascade={"persist", "remove"})
190
     */
191
    protected $searchEngineRefs;
192
193
    /**
194
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Templates", mappedBy="course", cascade={"persist", "remove"})
195
     */
196
    protected $templates;
197
198
    /**
199
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course")
200
     */
201
    //protected $specificFieldValues;
202
203
    /**
204
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course")
205
     */
206
    //protected $sharedSurveys;
207
208
    /**
209
     * @var string
210
     *
211
     * @ORM\Column(name="directory", type="string", length=40, nullable=true, unique=false)
212
     */
213
    protected $directory;
214
215
    /**
216
     * @var string
217
     * @Groups({"course:read", "list"})
218
     * @ORM\Column(name="course_language", type="string", length=20, nullable=true, unique=false)
219
     */
220
    protected $courseLanguage;
221
222
    /**
223
     * @var string
224
     *
225
     * @ORM\Column(name="description", type="text", nullable=true, unique=false)
226
     */
227
    protected $description;
228
229
    /**
230
     * @var ArrayCollection
231
     * @ApiSubresource()
232
     * @Groups({"course:read", "course:write"})
233
     * @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="courses")
234
     * @ORM\JoinTable(
235
     *      name="course_rel_category",
236
     *      joinColumns={@ORM\JoinColumn(name="course_id", referencedColumnName="id")},
237
     *      inverseJoinColumns={@ORM\JoinColumn(name="course_category_id", referencedColumnName="id")}
238
     * )
239
     */
240
    protected $categories;
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->categories = new ArrayCollection();
400
        $this->gradebookCategories = new ArrayCollection();
401
        $this->gradebookEvaluations = new ArrayCollection();
402
        $this->gradebookLinks = new ArrayCollection();
403
        $this->trackEHotspots = new ArrayCollection();
404
        $this->trackEAttempts = new ArrayCollection();
405
        $this->searchEngineRefs = new ArrayCollection();
406
        $this->templates = new ArrayCollection();
407
        $this->specificFieldValues = new ArrayCollection();
408
        $this->sharedSurveys = new ArrayCollection();
409
    }
410
411
    public function __toString(): string
412
    {
413
        return $this->getTitle();
414
    }
415
416
    /**
417
     * @return SessionRelCourse[]|ArrayCollection
418
     */
419
    public function getSessions()
420
    {
421
        return $this->sessions;
422
    }
423
424
    public function getTools()
425
    {
426
        return $this->tools;
427
    }
428
429
    /**
430
     * @param array $tools
431
     */
432
    public function setTools($tools)
433
    {
434
        foreach ($tools as $tool) {
435
            $this->addTool($tool);
436
        }
437
438
        return $this;
439
    }
440
441
    public function addTool(CTool $tool)
442
    {
443
        $tool->setCourse($this);
444
        $this->tools[] = $tool;
445
446
        return $this;
447
    }
448
449
    /**
450
     * @return AccessUrlRelCourse[]|ArrayCollection
451
     */
452
    public function getUrls()
453
    {
454
        return $this->urls;
455
    }
456
457
    /**
458
     * @param $urls
459
     */
460
    public function setUrls(ArrayCollection $urls)
461
    {
462
        $this->urls = new ArrayCollection();
463
        foreach ($urls as $url) {
464
            $this->addUrl($url);
465
        }
466
467
        return $this;
468
    }
469
470
    public function addUrlRelCourse(AccessUrlRelCourse $url)
471
    {
472
        $url->setCourse($this);
473
        $this->urls[] = $url;
474
475
        return $this;
476
    }
477
478
    public function addUrl(AccessUrl $url)
479
    {
480
        $urlRelCourse = new AccessUrlRelCourse();
481
        $urlRelCourse->setCourse($this);
482
        $urlRelCourse->setUrl($url);
483
        $this->addUrlRelCourse($urlRelCourse);
484
485
        return $this;
486
    }
487
488
    /**
489
     * @return CourseRelUser[]|ArrayCollection
490
     */
491
    public function getUsers()
492
    {
493
        return $this->users;
494
    }
495
496
    /**
497
     * @return CGroup[]|ArrayCollection
498
     */
499
    public function getGroups()
500
    {
501
        return $this->groups;
0 ignored issues
show
Bug Best Practice introduced by
The property groups does not exist on Chamilo\CoreBundle\Entity\Course. Did you maybe forget to declare it?
Loading history...
502
    }
503
504
    /**
505
     * @return CourseRelUser[]|ArrayCollection
506
     */
507
    public function getTeachers()
508
    {
509
        $criteria = Criteria::create();
510
        $criteria->where(Criteria::expr()->eq('status', User::COURSE_MANAGER));
511
512
        return $this->users->matching($criteria);
513
    }
514
515
    /**
516
     * @return CourseRelUser[]|ArrayCollection
517
     */
518
    public function getStudents()
519
    {
520
        $criteria = Criteria::create();
521
        $criteria->where(Criteria::expr()->eq('status', User::STUDENT));
522
523
        return $this->users->matching($criteria);
524
    }
525
526
    /**
527
     * @param ArrayCollection $users
528
     */
529
    public function setUsers($users)
530
    {
531
        $this->users = new ArrayCollection();
532
533
        foreach ($users as $user) {
534
            $this->addUsers($user);
535
        }
536
537
        return $this;
538
    }
539
540
    public function addUsers(CourseRelUser $courseRelUser)
541
    {
542
        $courseRelUser->setCourse($this);
543
544
        if (!$this->hasSubscription($courseRelUser)) {
545
            $this->users[] = $courseRelUser;
546
        }
547
548
        return $this;
549
    }
550
551
    /**
552
     * @return bool
553
     */
554
    public function hasUser(User $user)
555
    {
556
        $criteria = Criteria::create()->where(
557
            Criteria::expr()->eq('user', $user)
558
        );
559
560
        return $this->getUsers()->matching($criteria)->count() > 0;
561
    }
562
563
    /**
564
     * @return bool
565
     */
566
    public function hasStudent(User $user)
567
    {
568
        $criteria = Criteria::create()->where(
569
            Criteria::expr()->eq('user', $user)
570
        );
571
572
        return $this->getStudents()->matching($criteria)->count() > 0;
573
    }
574
575
    /**
576
     * @return bool
577
     */
578
    public function hasTeacher(User $user)
579
    {
580
        $criteria = Criteria::create()->where(
581
            Criteria::expr()->eq('user', $user)
582
        );
583
584
        return $this->getTeachers()->matching($criteria)->count() > 0;
585
    }
586
587
    /**
588
     * @return bool
589
     */
590
    public function hasGroup(CGroup $group)
591
    {
592
        /*$criteria = Criteria::create()->where(
593
            Criteria::expr()->eq('groups', $group)
594
        );*/
595
596
        return $this->getGroups()->contains($group);
597
    }
598
599
    /**
600
     * Remove $user.
601
     */
602
    public function removeUsers(CourseRelUser $user)
603
    {
604
        foreach ($this->users as $key => $value) {
605
            if ($value->getId() == $user->getId()) {
606
                unset($this->users[$key]);
607
            }
608
        }
609
    }
610
611
    public function addTeacher(User $user)
612
    {
613
        $this->addUser($user, 0, 'Trainer', User::COURSE_MANAGER);
614
615
        return $this;
616
    }
617
618
    public function addStudent(User $user)
619
    {
620
        $this->addUser($user, 0, '', User::STUDENT);
621
622
        return $this;
623
    }
624
625
    /**
626
     * Get id.
627
     *
628
     * @return int
629
     */
630
    public function getId()
631
    {
632
        return $this->id;
633
    }
634
635
    /**
636
     * Set code.
637
     *
638
     * @param string $code
639
     *
640
     * @return Course
641
     */
642
    public function setCode($code)
643
    {
644
        $this->code = $code;
645
        $this->visualCode = $code;
646
        $this->directory = $code;
647
648
        return $this;
649
    }
650
651
    /**
652
     * Get code.
653
     *
654
     * @return string
655
     */
656
    public function getCode()
657
    {
658
        return $this->code;
659
    }
660
661
    /**
662
     * Set directory.
663
     *
664
     * @param string $directory
665
     *
666
     * @return Course
667
     */
668
    public function setDirectory($directory)
669
    {
670
        $this->directory = $directory;
671
672
        return $this;
673
    }
674
675
    /**
676
     * Get directory.
677
     *
678
     * @return string
679
     */
680
    public function getDirectory()
681
    {
682
        return $this->directory;
683
    }
684
685
    /**
686
     * Set courseLanguage.
687
     *
688
     * @param string $courseLanguage
689
     *
690
     * @return Course
691
     */
692
    public function setCourseLanguage($courseLanguage)
693
    {
694
        $this->courseLanguage = $courseLanguage;
695
696
        return $this;
697
    }
698
699
    /**
700
     * Get courseLanguage.
701
     *
702
     * @return string
703
     */
704
    public function getCourseLanguage()
705
    {
706
        return $this->courseLanguage;
707
    }
708
709
    /**
710
     * Set title.
711
     *
712
     * @param string $title
713
     *
714
     * @return Course
715
     */
716
    public function setTitle($title)
717
    {
718
        $this->title = $title;
719
720
        return $this;
721
    }
722
723
    /**
724
     * Get title.
725
     *
726
     * @return string
727
     */
728
    public function getTitle()
729
    {
730
        return (string) $this->title;
731
    }
732
733
    public function getName()
734
    {
735
        return $this->getTitle();
736
    }
737
738
    /**
739
     * @return string
740
     */
741
    public function getTitleAndCode()
742
    {
743
        return $this->getTitle().' ('.$this->getCode().')';
744
    }
745
746
    /**
747
     * Set description.
748
     *
749
     * @param string $description
750
     *
751
     * @return Course
752
     */
753
    public function setDescription($description)
754
    {
755
        $this->description = $description;
756
757
        return $this;
758
    }
759
760
    /**
761
     * Get description.
762
     *
763
     * @return string
764
     */
765
    public function getDescription()
766
    {
767
        return $this->description;
768
    }
769
770
    /**
771
     * Set category.
772
     *
773
     * @return Course
774
     */
775
    public function setCategories(ArrayCollection $categories): self
776
    {
777
        $this->categories = $categories;
778
779
        return $this;
780
    }
781
782
    public function getCategories()
783
    {
784
        return $this->categories;
785
    }
786
787
    public function addCategory(CourseCategory $category): self
788
    {
789
        $this->categories[] = $category;
790
791
        return $this;
792
    }
793
794
    public function removeCategory(CourseCategory $category)
795
    {
796
        $this->categories->removeElement($category);
797
    }
798
799
    /**
800
     * Set visibility.
801
     */
802
    public function setVisibility(int $visibility): Course
803
    {
804
        $this->visibility = $visibility;
805
806
        return $this;
807
    }
808
809
    /**
810
     * Get visibility.
811
     */
812
    public function getVisibility(): int
813
    {
814
        return (int) $this->visibility;
815
    }
816
817
    /**
818
     * Set showScore.
819
     *
820
     * @param int $showScore
821
     *
822
     * @return Course
823
     */
824
    public function setShowScore($showScore)
825
    {
826
        $this->showScore = $showScore;
827
828
        return $this;
829
    }
830
831
    /**
832
     * Get showScore.
833
     *
834
     * @return int
835
     */
836
    public function getShowScore()
837
    {
838
        return $this->showScore;
839
    }
840
841
    /**
842
     * Set tutorName.
843
     *
844
     * @param string $tutorName
845
     *
846
     * @return Course
847
     */
848
    public function setTutorName($tutorName)
849
    {
850
        $this->tutorName = $tutorName;
851
852
        return $this;
853
    }
854
855
    /**
856
     * Get tutorName.
857
     *
858
     * @return string
859
     */
860
    public function getTutorName()
861
    {
862
        return $this->tutorName;
863
    }
864
865
    /**
866
     * Set visualCode.
867
     *
868
     * @param string $visualCode
869
     *
870
     * @return Course
871
     */
872
    public function setVisualCode($visualCode)
873
    {
874
        $this->visualCode = $visualCode;
875
876
        return $this;
877
    }
878
879
    /**
880
     * Get visualCode.
881
     *
882
     * @return string
883
     */
884
    public function getVisualCode()
885
    {
886
        return $this->visualCode;
887
    }
888
889
    /**
890
     * Set departmentName.
891
     *
892
     * @param string $departmentName
893
     *
894
     * @return Course
895
     */
896
    public function setDepartmentName($departmentName)
897
    {
898
        $this->departmentName = $departmentName;
899
900
        return $this;
901
    }
902
903
    /**
904
     * Get departmentName.
905
     *
906
     * @return string
907
     */
908
    public function getDepartmentName()
909
    {
910
        return $this->departmentName;
911
    }
912
913
    /**
914
     * Set departmentUrl.
915
     *
916
     * @param string $departmentUrl
917
     *
918
     * @return Course
919
     */
920
    public function setDepartmentUrl($departmentUrl)
921
    {
922
        $this->departmentUrl = $departmentUrl;
923
924
        return $this;
925
    }
926
927
    /**
928
     * Get departmentUrl.
929
     *
930
     * @return string
931
     */
932
    public function getDepartmentUrl()
933
    {
934
        return $this->departmentUrl;
935
    }
936
937
    /**
938
     * Set diskQuota.
939
     *
940
     * @param int $diskQuota
941
     *
942
     * @return Course
943
     */
944
    public function setDiskQuota($diskQuota)
945
    {
946
        $this->diskQuota = (int) $diskQuota;
947
948
        return $this;
949
    }
950
951
    /**
952
     * Get diskQuota.
953
     *
954
     * @return int
955
     */
956
    public function getDiskQuota()
957
    {
958
        return $this->diskQuota;
959
    }
960
961
    /**
962
     * Set lastVisit.
963
     *
964
     * @param \DateTime $lastVisit
965
     *
966
     * @return Course
967
     */
968
    public function setLastVisit($lastVisit)
969
    {
970
        $this->lastVisit = $lastVisit;
971
972
        return $this;
973
    }
974
975
    /**
976
     * Get lastVisit.
977
     *
978
     * @return \DateTime
979
     */
980
    public function getLastVisit()
981
    {
982
        return $this->lastVisit;
983
    }
984
985
    /**
986
     * Set lastEdit.
987
     *
988
     * @param \DateTime $lastEdit
989
     *
990
     * @return Course
991
     */
992
    public function setLastEdit($lastEdit)
993
    {
994
        $this->lastEdit = $lastEdit;
995
996
        return $this;
997
    }
998
999
    /**
1000
     * Get lastEdit.
1001
     *
1002
     * @return \DateTime
1003
     */
1004
    public function getLastEdit()
1005
    {
1006
        return $this->lastEdit;
1007
    }
1008
1009
    /**
1010
     * Set creationDate.
1011
     *
1012
     * @param \DateTime $creationDate
1013
     *
1014
     * @return Course
1015
     */
1016
    public function setCreationDate($creationDate)
1017
    {
1018
        $this->creationDate = $creationDate;
1019
1020
        return $this;
1021
    }
1022
1023
    /**
1024
     * Get creationDate.
1025
     *
1026
     * @return \DateTime
1027
     */
1028
    public function getCreationDate()
1029
    {
1030
        return $this->creationDate;
1031
    }
1032
1033
    /**
1034
     * Set expirationDate.
1035
     *
1036
     * @param \DateTime $expirationDate
1037
     *
1038
     * @return Course
1039
     */
1040
    public function setExpirationDate($expirationDate)
1041
    {
1042
        $this->expirationDate = $expirationDate;
1043
1044
        return $this;
1045
    }
1046
1047
    /**
1048
     * Get expirationDate.
1049
     *
1050
     * @return \DateTime
1051
     */
1052
    public function getExpirationDate()
1053
    {
1054
        return $this->expirationDate;
1055
    }
1056
1057
    /**
1058
     * Set subscribe.
1059
     *
1060
     * @param bool $subscribe
1061
     *
1062
     * @return Course
1063
     */
1064
    public function setSubscribe($subscribe)
1065
    {
1066
        $this->subscribe = (bool) $subscribe;
1067
1068
        return $this;
1069
    }
1070
1071
    /**
1072
     * Get subscribe.
1073
     *
1074
     * @return bool
1075
     */
1076
    public function getSubscribe()
1077
    {
1078
        return $this->subscribe;
1079
    }
1080
1081
    /**
1082
     * Set unsubscribe.
1083
     *
1084
     * @param bool $unsubscribe
1085
     *
1086
     * @return Course
1087
     */
1088
    public function setUnsubscribe($unsubscribe)
1089
    {
1090
        $this->unsubscribe = (bool) $unsubscribe;
1091
1092
        return $this;
1093
    }
1094
1095
    /**
1096
     * Get unsubscribe.
1097
     *
1098
     * @return bool
1099
     */
1100
    public function getUnsubscribe()
1101
    {
1102
        return $this->unsubscribe;
1103
    }
1104
1105
    /**
1106
     * Set registrationCode.
1107
     *
1108
     * @param string $registrationCode
1109
     *
1110
     * @return Course
1111
     */
1112
    public function setRegistrationCode($registrationCode)
1113
    {
1114
        $this->registrationCode = $registrationCode;
1115
1116
        return $this;
1117
    }
1118
1119
    /**
1120
     * Get registrationCode.
1121
     *
1122
     * @return string
1123
     */
1124
    public function getRegistrationCode()
1125
    {
1126
        return $this->registrationCode;
1127
    }
1128
1129
    /**
1130
     * Set legal.
1131
     *
1132
     * @param string $legal
1133
     *
1134
     * @return Course
1135
     */
1136
    public function setLegal($legal)
1137
    {
1138
        $this->legal = $legal;
1139
1140
        return $this;
1141
    }
1142
1143
    /**
1144
     * Get legal.
1145
     *
1146
     * @return string
1147
     */
1148
    public function getLegal()
1149
    {
1150
        return $this->legal;
1151
    }
1152
1153
    /**
1154
     * Set activateLegal.
1155
     *
1156
     * @param int $activateLegal
1157
     *
1158
     * @return Course
1159
     */
1160
    public function setActivateLegal($activateLegal)
1161
    {
1162
        $this->activateLegal = $activateLegal;
1163
1164
        return $this;
1165
    }
1166
1167
    /**
1168
     * Get activateLegal.
1169
     *
1170
     * @return int
1171
     */
1172
    public function getActivateLegal()
1173
    {
1174
        return $this->activateLegal;
1175
    }
1176
1177
    /**
1178
     * @return bool
1179
     */
1180
    public function isAddTeachersToSessionsCourses()
1181
    {
1182
        return $this->addTeachersToSessionsCourses;
1183
    }
1184
1185
    /**
1186
     * @param bool $addTeachersToSessionsCourses
1187
     */
1188
    public function setAddTeachersToSessionsCourses($addTeachersToSessionsCourses): self
1189
    {
1190
        $this->addTeachersToSessionsCourses = $addTeachersToSessionsCourses;
1191
1192
        return $this;
1193
    }
1194
1195
    /**
1196
     * Set courseTypeId.
1197
     *
1198
     * @param int $courseTypeId
1199
     *
1200
     * @return Course
1201
     */
1202
    public function setCourseTypeId($courseTypeId)
1203
    {
1204
        $this->courseTypeId = $courseTypeId;
1205
1206
        return $this;
1207
    }
1208
1209
    /**
1210
     * Get courseTypeId.
1211
     *
1212
     * @return int
1213
     */
1214
    public function getCourseTypeId()
1215
    {
1216
        return $this->courseTypeId;
1217
    }
1218
1219
    /**
1220
     * @return Room
1221
     */
1222
    public function getRoom()
1223
    {
1224
        return $this->room;
1225
    }
1226
1227
    /**
1228
     * @param Room $room
1229
     *
1230
     * @return Course
1231
     */
1232
    public function setRoom($room)
1233
    {
1234
        $this->room = $room;
1235
1236
        return $this;
1237
    }
1238
1239
    /**
1240
     * @return bool
1241
     */
1242
    public function isActive()
1243
    {
1244
        $activeVisibilityList = [
1245
            self::REGISTERED,
1246
            self::OPEN_PLATFORM,
1247
            self::OPEN_WORLD,
1248
        ];
1249
1250
        return in_array($this->visibility, $activeVisibilityList);
1251
    }
1252
1253
    /**
1254
     * Anybody can see this course.
1255
     */
1256
    public function isPublic(): bool
1257
    {
1258
        return self::OPEN_WORLD === $this->visibility;
1259
    }
1260
1261
    public function isHidden(): bool
1262
    {
1263
        return self::HIDDEN === $this->visibility;
1264
    }
1265
1266
    /**
1267
     * @return array
1268
     */
1269
    public static function getStatusList()
1270
    {
1271
        return [
1272
            self::CLOSED => 'Closed',
1273
            self::REGISTERED => 'Registered',
1274
            self::OPEN_PLATFORM => 'Open platform',
1275
            self::OPEN_WORLD => 'Open world',
1276
            self::HIDDEN => 'Hidden',
1277
        ];
1278
    }
1279
1280
    /**
1281
     * @return Session
1282
     */
1283
    public function getCurrentSession()
1284
    {
1285
        return $this->currentSession;
1286
    }
1287
1288
    /**
1289
     * @return $this
1290
     */
1291
    public function setCurrentSession(Session $session)
1292
    {
1293
        // If the session is registered in the course session list.
1294
        /*if ($this->getSessions()->contains($session->getId())) {
1295
            $this->currentSession = $session;
1296
        }*/
1297
1298
        $list = $this->getSessions();
1299
        /** @var SessionRelCourse $item */
1300
        foreach ($list as $item) {
1301
            if ($item->getSession()->getId() == $session->getId()) {
1302
                $this->currentSession = $session;
1303
1304
                break;
1305
            }
1306
        }
1307
1308
        return $this;
1309
    }
1310
1311
    /**
1312
     * @return $this
1313
     */
1314
    public function setCurrentUrl(AccessUrl $url)
1315
    {
1316
        $urlList = $this->getUrls();
1317
        /** @var AccessUrlRelCourse $item */
1318
        foreach ($urlList as $item) {
1319
            if ($item->getUrl()->getId() == $url->getId()) {
1320
                $this->currentUrl = $url;
1321
1322
                break;
1323
            }
1324
        }
1325
1326
        return $this;
1327
    }
1328
1329
    /**
1330
     * @return AccessUrl
1331
     */
1332
    public function getCurrentUrl()
1333
    {
1334
        return $this->currentUrl;
1335
    }
1336
1337
    /**
1338
     * Get issuedSkills.
1339
     *
1340
     * @return ArrayCollection
1341
     */
1342
    public function getIssuedSkills()
1343
    {
1344
        return $this->issuedSkills;
1345
    }
1346
1347
    public function hasSubscription(CourseRelUser $subscription): bool
1348
    {
1349
        if ($this->getUsers()->count()) {
1350
            $criteria = Criteria::create()->where(
1351
                Criteria::expr()->eq('user', $subscription->getUser())
1352
            )->andWhere(
1353
                Criteria::expr()->eq('status', $subscription->getStatus())
1354
            )->andWhere(
1355
                Criteria::expr()->eq('relationType', $subscription->getRelationType())
1356
            );
1357
1358
            $relation = $this->getUsers()->matching($criteria);
1359
1360
            return $relation->count() > 0;
1361
        }
1362
1363
        return false;
1364
    }
1365
1366
    /**
1367
     * @param string $relationType
1368
     * @param string $role
1369
     * @param string $status
1370
     */
1371
    public function addUser(User $user, $relationType, $role, $status): self
1372
    {
1373
        $courseRelUser = new CourseRelUser();
1374
        $courseRelUser->setCourse($this);
1375
        $courseRelUser->setUser($user);
1376
        $courseRelUser->setRelationType($relationType);
1377
        //$courseRelUser->setRole($role);
1378
        $courseRelUser->setStatus($status);
1379
        $this->addUsers($courseRelUser);
1380
1381
        return $this;
1382
    }
1383
1384
    /**
1385
     * Resource identifier.
1386
     */
1387
    public function getResourceIdentifier(): int
1388
    {
1389
        return $this->getId();
1390
    }
1391
1392
    public function getResourceName(): string
1393
    {
1394
        return $this->getCode();
1395
    }
1396
1397
    public function setResourceName(string $name): self
1398
    {
1399
        return $this->setCode($name);
1400
    }
1401
}
1402