Passed
Push — master ( 48aeb9...852133 )
by Julito
09:44
created

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