Passed
Push — master ( b5ff3f...de0fbe )
by Julito
09:48
created

Course::getResourceIdentifier()   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, ResourceWithAccessUrlInterface, 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
     * @Groups({"course:read", "course_rel_user:read"})
61
     * @ORM\Column(name="id", type="integer", nullable=false, unique=false)
62
     * @ORM\Id
63
     * @ORM\GeneratedValue(strategy="AUTO")
64
     */
65
    protected int $id;
66
67
    /**
68
     * The course title.
69
     *
70
     * @Assert\NotBlank(message="A Course requires a title")
71
     *
72
     * @Groups({"course:read", "course:write", "course_rel_user:read", "session_rel_course_rel_user:read"})
73
     *
74
     * @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false)
75
     */
76
    protected string $title;
77
78
    /**
79
     * The course code.
80
     *
81
     * @Assert\NotBlank()
82
     * @ApiProperty(iri="http://schema.org/courseCode")
83
     * @Groups({"course:read", "course:write", "course_rel_user:read"})
84
     *
85
     * @Gedmo\Slug(
86
     *      fields={"title"},
87
     *      updatable = false,
88
     *      unique = true,
89
     *      style = "upper"
90
     * )
91
     * @ORM\Column(name="code", type="string", length=40, nullable=false, unique=true)
92
     */
93
    protected string $code;
94
95
    /**
96
     * @var CourseRelUser[]|ArrayCollection
97
     *
98
     * @ApiSubresource()
99
     * Groups({"course:read"})
100
     * "orphanRemoval" is needed to delete the CourseRelUser relation
101
     * in the CourseAdmin class. The setUsers, getUsers, removeUsers and
102
     * addUsers methods need to be added.
103
     *
104
     * @ORM\OneToMany(targetEntity="CourseRelUser", mappedBy="course", cascade={"persist"}, orphanRemoval=true)
105
     */
106
    protected $users;
107
108
    /**
109
     * @var ArrayCollection|ResourceLink[]
110
     *
111
     * ApiSubresource()
112
     * Groups({"course:read"})
113
     * @ORM\OneToMany(targetEntity="ResourceLink", mappedBy="course", cascade={"persist"}, orphanRemoval=true)
114
     */
115
    protected $resourceLinks;
116
117
    /**
118
     * @var ArrayCollection|AccessUrlRelCourse[]
119
     *
120
     * @ORM\OneToMany(
121
     *     targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelCourse",
122
     *     mappedBy="course", cascade={"persist", "remove"}, orphanRemoval=true
123
     * )
124
     */
125
    protected $urls;
126
127
    /**
128
     * @var SessionRelCourse[]
129
     *
130
     * @ORM\OneToMany(targetEntity="SessionRelCourse", mappedBy="course", cascade={"persist", "remove"})
131
     */
132
    protected $sessions;
133
134
    /**
135
     * @ORM\OneToMany(targetEntity="SessionRelCourseRelUser", mappedBy="course", cascade={"persist", "remove"})
136
     */
137
    protected $sessionUserSubscriptions;
138
139
    /**
140
     * @var CTool[]|ArrayCollection
141
     *
142
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CTool", mappedBy="course", cascade={"persist", "remove"})
143
     */
144
    protected $tools;
145
146
    /**
147
     * @var Session
148
     */
149
    protected $currentSession;
150
151
    /**
152
     * @var AccessUrl
153
     */
154
    protected $currentUrl;
155
156
    /**
157
     * @ORM\OneToMany(targetEntity="SkillRelCourse", mappedBy="course", cascade={"persist", "remove"})
158
     */
159
    protected $skills;
160
161
    /**
162
     * @ORM\OneToMany(targetEntity="SkillRelUser", mappedBy="course", cascade={"persist", "remove"})
163
     */
164
    protected $issuedSkills;
165
166
    /**
167
     * @ORM\OneToMany(targetEntity="GradebookCategory", mappedBy="course", cascade={"persist", "remove"})
168
     */
169
    protected $gradebookCategories;
170
171
    /**
172
     * @ORM\OneToMany(targetEntity="GradebookEvaluation", mappedBy="course", cascade={"persist", "remove"})
173
     */
174
    protected $gradebookEvaluations;
175
176
    /**
177
     * @ORM\OneToMany(targetEntity="GradebookLink", mappedBy="course", cascade={"persist", "remove"})
178
     */
179
    protected $gradebookLinks;
180
181
    /**
182
     * @ORM\OneToMany(targetEntity="TrackEHotspot", mappedBy="course", cascade={"persist", "remove"})
183
     */
184
    protected $trackEHotspots;
185
186
    /**
187
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\TrackEAttempt", mappedBy="course", cascade={"persist", "remove"})
188
     */
189
    protected $trackEAttempts;
190
191
    /**
192
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SearchEngineRef", mappedBy="course", cascade={"persist", "remove"})
193
     */
194
    protected $searchEngineRefs;
195
196
    /**
197
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Templates", mappedBy="course", cascade={"persist", "remove"})
198
     */
199
    protected $templates;
200
201
    /**
202
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course")
203
     */
204
    //protected $specificFieldValues;
205
206
    /**
207
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course")
208
     */
209
    //protected $sharedSurveys;
210
211
    /**
212
     * @var string
213
     *
214
     * @ORM\Column(name="directory", type="string", length=40, nullable=true, unique=false)
215
     */
216
    protected $directory;
217
218
    /**
219
     * @var string
220
     * @Groups({"course:read", "list"})
221
     * @ORM\Column(name="course_language", type="string", length=20, nullable=true, unique=false)
222
     */
223
    protected $courseLanguage;
224
225
    /**
226
     * @ORM\Column(name="description", type="text", nullable=true, unique=false)
227
     */
228
    protected string $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
        $this->description = '';
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
    public function setUrls(ArrayCollection $urls)
459
    {
460
        $this->urls = new ArrayCollection();
461
        foreach ($urls as $url) {
462
            $this->addUrl($url);
463
        }
464
465
        return $this;
466
    }
467
468
    public function addUrlRelCourse(AccessUrlRelCourse $url)
469
    {
470
        $url->setCourse($this);
471
        $this->urls[] = $url;
472
473
        return $this;
474
    }
475
476
    public function addUrl(AccessUrl $url)
477
    {
478
        $urlRelCourse = new AccessUrlRelCourse();
479
        $urlRelCourse->setCourse($this);
480
        $urlRelCourse->setUrl($url);
481
        $this->addUrlRelCourse($urlRelCourse);
482
483
        return $this;
484
    }
485
486
    /**
487
     * @return CourseRelUser[]|ArrayCollection
488
     */
489
    public function getUsers()
490
    {
491
        return $this->users;
492
    }
493
494
    /**
495
     * @return CourseRelUser[]|ArrayCollection
496
     */
497
    public function getTeachers()
498
    {
499
        $criteria = Criteria::create();
500
        $criteria->where(Criteria::expr()->eq('status', User::COURSE_MANAGER));
501
502
        return $this->users->matching($criteria);
503
    }
504
505
    /**
506
     * @return CourseRelUser[]|ArrayCollection
507
     */
508
    public function getStudents()
509
    {
510
        $criteria = Criteria::create();
511
        $criteria->where(Criteria::expr()->eq('status', User::STUDENT));
512
513
        return $this->users->matching($criteria);
514
    }
515
516
    /**
517
     * @param ArrayCollection $users
518
     */
519
    public function setUsers($users)
520
    {
521
        $this->users = new ArrayCollection();
522
523
        foreach ($users as $user) {
524
            $this->addUsers($user);
525
        }
526
527
        return $this;
528
    }
529
530
    public function addUsers(CourseRelUser $courseRelUser)
531
    {
532
        $courseRelUser->setCourse($this);
533
534
        if (!$this->hasSubscription($courseRelUser)) {
535
            $this->users[] = $courseRelUser;
536
        }
537
538
        return $this;
539
    }
540
541
    public function hasUser(User $user): bool
542
    {
543
        $criteria = Criteria::create()->where(
544
            Criteria::expr()->eq('user', $user)
545
        );
546
547
        return $this->getUsers()->matching($criteria)->count() > 0;
548
    }
549
550
    public function hasStudent(User $user): bool
551
    {
552
        $criteria = Criteria::create()->where(
553
            Criteria::expr()->eq('user', $user)
554
        );
555
556
        return $this->getStudents()->matching($criteria)->count() > 0;
557
    }
558
559
    public function hasTeacher(User $user): bool
560
    {
561
        $criteria = Criteria::create()->where(
562
            Criteria::expr()->eq('user', $user)
563
        );
564
565
        return $this->getTeachers()->matching($criteria)->count() > 0;
566
    }
567
568
    public function hasGroup(CGroup $group): bool
569
    {
570
        /*$criteria = Criteria::create()->where(
571
            Criteria::expr()->eq('groups', $group)
572
        );*/
573
574
        //return $this->getGroups()->contains($group);
575
    }
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
576
577
    /**
578
     * Remove $user.
579
     */
580
    public function removeUsers(CourseRelUser $user)
581
    {
582
        foreach ($this->users as $key => $value) {
583
            if ($value->getId() == $user->getId()) {
584
                unset($this->users[$key]);
585
            }
586
        }
587
    }
588
589
    public function addTeacher(User $user)
590
    {
591
        $this->addUser($user, 0, 'Trainer', User::COURSE_MANAGER);
592
593
        return $this;
594
    }
595
596
    public function addStudent(User $user)
597
    {
598
        $this->addUser($user, 0, '', User::STUDENT);
599
600
        return $this;
601
    }
602
603
    /**
604
     * Get id.
605
     *
606
     * @return int
607
     */
608
    public function getId()
609
    {
610
        return $this->id;
611
    }
612
613
    /**
614
     * Set code.
615
     *
616
     * @param string $code
617
     *
618
     * @return Course
619
     */
620
    public function setCode($code)
621
    {
622
        $this->code = $code;
623
        $this->visualCode = $code;
624
        $this->directory = $code;
625
626
        return $this;
627
    }
628
629
    /**
630
     * Get code.
631
     *
632
     * @return string
633
     */
634
    public function getCode()
635
    {
636
        return $this->code;
637
    }
638
639
    /**
640
     * Set directory.
641
     *
642
     * @param string $directory
643
     *
644
     * @return Course
645
     */
646
    public function setDirectory($directory)
647
    {
648
        $this->directory = $directory;
649
650
        return $this;
651
    }
652
653
    /**
654
     * Get directory.
655
     *
656
     * @return string
657
     */
658
    public function getDirectory()
659
    {
660
        return $this->directory;
661
    }
662
663
    /**
664
     * Set courseLanguage.
665
     *
666
     * @param string $courseLanguage
667
     *
668
     * @return Course
669
     */
670
    public function setCourseLanguage($courseLanguage)
671
    {
672
        $this->courseLanguage = $courseLanguage;
673
674
        return $this;
675
    }
676
677
    /**
678
     * Get courseLanguage.
679
     *
680
     * @return string
681
     */
682
    public function getCourseLanguage()
683
    {
684
        return $this->courseLanguage;
685
    }
686
687
    /**
688
     * Set title.
689
     *
690
     * @param string $title
691
     *
692
     * @return Course
693
     */
694
    public function setTitle($title)
695
    {
696
        $this->title = $title;
697
698
        return $this;
699
    }
700
701
    /**
702
     * Get title.
703
     */
704
    public function getTitle(): string
705
    {
706
        return $this->title;
707
    }
708
709
    public function getName()
710
    {
711
        return $this->getTitle();
712
    }
713
714
    /**
715
     * @return string
716
     */
717
    public function getTitleAndCode()
718
    {
719
        return $this->getTitle().' ('.$this->getCode().')';
720
    }
721
722
    /**
723
     * Set description.
724
     *
725
     * @param string $description
726
     *
727
     * @return Course
728
     */
729
    public function setDescription($description)
730
    {
731
        $this->description = $description;
732
733
        return $this;
734
    }
735
736
    /**
737
     * Get description.
738
     *
739
     * @return string
740
     */
741
    public function getDescription()
742
    {
743
        return $this->description;
744
    }
745
746
    /**
747
     * Set category.
748
     *
749
     * @return Course
750
     */
751
    public function setCategories(ArrayCollection $categories): self
752
    {
753
        $this->categories = $categories;
754
755
        return $this;
756
    }
757
758
    public function getCategories()
759
    {
760
        return $this->categories;
761
    }
762
763
    public function addCategory(CourseCategory $category): self
764
    {
765
        $this->categories[] = $category;
766
767
        return $this;
768
    }
769
770
    public function removeCategory(CourseCategory $category)
771
    {
772
        $this->categories->removeElement($category);
773
    }
774
775
    /**
776
     * Set visibility.
777
     */
778
    public function setVisibility(int $visibility): Course
779
    {
780
        $this->visibility = $visibility;
781
782
        return $this;
783
    }
784
785
    /**
786
     * Get visibility.
787
     */
788
    public function getVisibility(): int
789
    {
790
        return (int) $this->visibility;
791
    }
792
793
    /**
794
     * Set showScore.
795
     *
796
     * @param int $showScore
797
     *
798
     * @return Course
799
     */
800
    public function setShowScore($showScore)
801
    {
802
        $this->showScore = $showScore;
803
804
        return $this;
805
    }
806
807
    /**
808
     * Get showScore.
809
     *
810
     * @return int
811
     */
812
    public function getShowScore()
813
    {
814
        return $this->showScore;
815
    }
816
817
    /**
818
     * Set tutorName.
819
     *
820
     * @param string $tutorName
821
     *
822
     * @return Course
823
     */
824
    public function setTutorName($tutorName)
825
    {
826
        $this->tutorName = $tutorName;
827
828
        return $this;
829
    }
830
831
    /**
832
     * Get tutorName.
833
     *
834
     * @return string
835
     */
836
    public function getTutorName()
837
    {
838
        return $this->tutorName;
839
    }
840
841
    /**
842
     * Set visualCode.
843
     *
844
     * @param string $visualCode
845
     *
846
     * @return Course
847
     */
848
    public function setVisualCode($visualCode)
849
    {
850
        $this->visualCode = $visualCode;
851
852
        return $this;
853
    }
854
855
    /**
856
     * Get visualCode.
857
     *
858
     * @return string
859
     */
860
    public function getVisualCode()
861
    {
862
        return $this->visualCode;
863
    }
864
865
    /**
866
     * Set departmentName.
867
     *
868
     * @param string $departmentName
869
     *
870
     * @return Course
871
     */
872
    public function setDepartmentName($departmentName)
873
    {
874
        $this->departmentName = $departmentName;
875
876
        return $this;
877
    }
878
879
    /**
880
     * Get departmentName.
881
     *
882
     * @return string
883
     */
884
    public function getDepartmentName()
885
    {
886
        return $this->departmentName;
887
    }
888
889
    /**
890
     * Set departmentUrl.
891
     *
892
     * @param string $departmentUrl
893
     *
894
     * @return Course
895
     */
896
    public function setDepartmentUrl($departmentUrl)
897
    {
898
        $this->departmentUrl = $departmentUrl;
899
900
        return $this;
901
    }
902
903
    /**
904
     * Get departmentUrl.
905
     *
906
     * @return string
907
     */
908
    public function getDepartmentUrl()
909
    {
910
        return $this->departmentUrl;
911
    }
912
913
    /**
914
     * Set diskQuota.
915
     *
916
     * @param int $diskQuota
917
     *
918
     * @return Course
919
     */
920
    public function setDiskQuota($diskQuota)
921
    {
922
        $this->diskQuota = (int) $diskQuota;
923
924
        return $this;
925
    }
926
927
    /**
928
     * Get diskQuota.
929
     *
930
     * @return int
931
     */
932
    public function getDiskQuota()
933
    {
934
        return $this->diskQuota;
935
    }
936
937
    /**
938
     * Set lastVisit.
939
     *
940
     * @param \DateTime $lastVisit
941
     *
942
     * @return Course
943
     */
944
    public function setLastVisit($lastVisit)
945
    {
946
        $this->lastVisit = $lastVisit;
947
948
        return $this;
949
    }
950
951
    /**
952
     * Get lastVisit.
953
     *
954
     * @return \DateTime
955
     */
956
    public function getLastVisit()
957
    {
958
        return $this->lastVisit;
959
    }
960
961
    /**
962
     * Set lastEdit.
963
     *
964
     * @param \DateTime $lastEdit
965
     *
966
     * @return Course
967
     */
968
    public function setLastEdit($lastEdit)
969
    {
970
        $this->lastEdit = $lastEdit;
971
972
        return $this;
973
    }
974
975
    /**
976
     * Get lastEdit.
977
     *
978
     * @return \DateTime
979
     */
980
    public function getLastEdit()
981
    {
982
        return $this->lastEdit;
983
    }
984
985
    /**
986
     * Set creationDate.
987
     *
988
     * @param \DateTime $creationDate
989
     *
990
     * @return Course
991
     */
992
    public function setCreationDate($creationDate)
993
    {
994
        $this->creationDate = $creationDate;
995
996
        return $this;
997
    }
998
999
    /**
1000
     * Get creationDate.
1001
     *
1002
     * @return \DateTime
1003
     */
1004
    public function getCreationDate()
1005
    {
1006
        return $this->creationDate;
1007
    }
1008
1009
    /**
1010
     * Set expirationDate.
1011
     *
1012
     * @param \DateTime $expirationDate
1013
     *
1014
     * @return Course
1015
     */
1016
    public function setExpirationDate($expirationDate)
1017
    {
1018
        $this->expirationDate = $expirationDate;
1019
1020
        return $this;
1021
    }
1022
1023
    /**
1024
     * Get expirationDate.
1025
     *
1026
     * @return \DateTime
1027
     */
1028
    public function getExpirationDate()
1029
    {
1030
        return $this->expirationDate;
1031
    }
1032
1033
    /**
1034
     * Set subscribe.
1035
     *
1036
     * @param bool $subscribe
1037
     *
1038
     * @return Course
1039
     */
1040
    public function setSubscribe($subscribe)
1041
    {
1042
        $this->subscribe = (bool) $subscribe;
1043
1044
        return $this;
1045
    }
1046
1047
    /**
1048
     * Get subscribe.
1049
     *
1050
     * @return bool
1051
     */
1052
    public function getSubscribe()
1053
    {
1054
        return $this->subscribe;
1055
    }
1056
1057
    /**
1058
     * Set unsubscribe.
1059
     *
1060
     * @param bool $unsubscribe
1061
     *
1062
     * @return Course
1063
     */
1064
    public function setUnsubscribe($unsubscribe)
1065
    {
1066
        $this->unsubscribe = (bool) $unsubscribe;
1067
1068
        return $this;
1069
    }
1070
1071
    /**
1072
     * Get unsubscribe.
1073
     *
1074
     * @return bool
1075
     */
1076
    public function getUnsubscribe()
1077
    {
1078
        return $this->unsubscribe;
1079
    }
1080
1081
    /**
1082
     * Set registrationCode.
1083
     *
1084
     * @param string $registrationCode
1085
     *
1086
     * @return Course
1087
     */
1088
    public function setRegistrationCode($registrationCode)
1089
    {
1090
        $this->registrationCode = $registrationCode;
1091
1092
        return $this;
1093
    }
1094
1095
    /**
1096
     * Get registrationCode.
1097
     *
1098
     * @return string
1099
     */
1100
    public function getRegistrationCode()
1101
    {
1102
        return $this->registrationCode;
1103
    }
1104
1105
    /**
1106
     * Set legal.
1107
     *
1108
     * @param string $legal
1109
     *
1110
     * @return Course
1111
     */
1112
    public function setLegal($legal)
1113
    {
1114
        $this->legal = $legal;
1115
1116
        return $this;
1117
    }
1118
1119
    /**
1120
     * Get legal.
1121
     *
1122
     * @return string
1123
     */
1124
    public function getLegal()
1125
    {
1126
        return $this->legal;
1127
    }
1128
1129
    /**
1130
     * Set activateLegal.
1131
     *
1132
     * @param int $activateLegal
1133
     *
1134
     * @return Course
1135
     */
1136
    public function setActivateLegal($activateLegal)
1137
    {
1138
        $this->activateLegal = $activateLegal;
1139
1140
        return $this;
1141
    }
1142
1143
    /**
1144
     * Get activateLegal.
1145
     *
1146
     * @return int
1147
     */
1148
    public function getActivateLegal()
1149
    {
1150
        return $this->activateLegal;
1151
    }
1152
1153
    /**
1154
     * @return bool
1155
     */
1156
    public function isAddTeachersToSessionsCourses()
1157
    {
1158
        return $this->addTeachersToSessionsCourses;
1159
    }
1160
1161
    /**
1162
     * @param bool $addTeachersToSessionsCourses
1163
     */
1164
    public function setAddTeachersToSessionsCourses($addTeachersToSessionsCourses): self
1165
    {
1166
        $this->addTeachersToSessionsCourses = $addTeachersToSessionsCourses;
1167
1168
        return $this;
1169
    }
1170
1171
    /**
1172
     * Set courseTypeId.
1173
     *
1174
     * @param int $courseTypeId
1175
     *
1176
     * @return Course
1177
     */
1178
    public function setCourseTypeId($courseTypeId)
1179
    {
1180
        $this->courseTypeId = $courseTypeId;
1181
1182
        return $this;
1183
    }
1184
1185
    /**
1186
     * Get courseTypeId.
1187
     *
1188
     * @return int
1189
     */
1190
    public function getCourseTypeId()
1191
    {
1192
        return $this->courseTypeId;
1193
    }
1194
1195
    /**
1196
     * @return Room
1197
     */
1198
    public function getRoom()
1199
    {
1200
        return $this->room;
1201
    }
1202
1203
    public function setRoom(Room $room): self
1204
    {
1205
        $this->room = $room;
1206
1207
        return $this;
1208
    }
1209
1210
    public function isActive(): bool
1211
    {
1212
        $activeVisibilityList = [
1213
            self::REGISTERED,
1214
            self::OPEN_PLATFORM,
1215
            self::OPEN_WORLD,
1216
        ];
1217
1218
        return in_array($this->visibility, $activeVisibilityList);
1219
    }
1220
1221
    /**
1222
     * Anybody can see this course.
1223
     */
1224
    public function isPublic(): bool
1225
    {
1226
        return self::OPEN_WORLD === $this->visibility;
1227
    }
1228
1229
    public function isHidden(): bool
1230
    {
1231
        return self::HIDDEN === $this->visibility;
1232
    }
1233
1234
    public static function getStatusList(): array
1235
    {
1236
        return [
1237
            self::CLOSED => 'Closed',
1238
            self::REGISTERED => 'Registered',
1239
            self::OPEN_PLATFORM => 'Open platform',
1240
            self::OPEN_WORLD => 'Open world',
1241
            self::HIDDEN => 'Hidden',
1242
        ];
1243
    }
1244
1245
    /**
1246
     * @return Session
1247
     */
1248
    public function getCurrentSession()
1249
    {
1250
        return $this->currentSession;
1251
    }
1252
1253
    public function setCurrentSession(Session $session): self
1254
    {
1255
        // If the session is registered in the course session list.
1256
        /*if ($this->getSessions()->contains($session->getId())) {
1257
            $this->currentSession = $session;
1258
        }*/
1259
1260
        $list = $this->getSessions();
1261
        /** @var SessionRelCourse $item */
1262
        foreach ($list as $item) {
1263
            if ($item->getSession()->getId() == $session->getId()) {
1264
                $this->currentSession = $session;
1265
1266
                break;
1267
            }
1268
        }
1269
1270
        return $this;
1271
    }
1272
1273
    public function setCurrentUrl(AccessUrl $url): self
1274
    {
1275
        $urlList = $this->getUrls();
1276
        /** @var AccessUrlRelCourse $item */
1277
        foreach ($urlList as $item) {
1278
            if ($item->getUrl()->getId() == $url->getId()) {
1279
                $this->currentUrl = $url;
1280
1281
                break;
1282
            }
1283
        }
1284
1285
        return $this;
1286
    }
1287
1288
    /**
1289
     * @return AccessUrl
1290
     */
1291
    public function getCurrentUrl()
1292
    {
1293
        return $this->currentUrl;
1294
    }
1295
1296
    /**
1297
     * Get issuedSkills.
1298
     *
1299
     * @return ArrayCollection
1300
     */
1301
    public function getIssuedSkills()
1302
    {
1303
        return $this->issuedSkills;
1304
    }
1305
1306
    public function hasSubscription(CourseRelUser $subscription): bool
1307
    {
1308
        if ($this->getUsers()->count()) {
1309
            $criteria = Criteria::create()->where(
1310
                Criteria::expr()->eq('user', $subscription->getUser())
1311
            )->andWhere(
1312
                Criteria::expr()->eq('status', $subscription->getStatus())
1313
            )->andWhere(
1314
                Criteria::expr()->eq('relationType', $subscription->getRelationType())
1315
            );
1316
1317
            $relation = $this->getUsers()->matching($criteria);
1318
1319
            return $relation->count() > 0;
1320
        }
1321
1322
        return false;
1323
    }
1324
1325
    /**
1326
     * @param string $relationType
1327
     * @param string $role
1328
     * @param string $status
1329
     */
1330
    public function addUser(User $user, $relationType, $role, $status): self
1331
    {
1332
        $courseRelUser = new CourseRelUser();
1333
        $courseRelUser->setCourse($this);
1334
        $courseRelUser->setUser($user);
1335
        $courseRelUser->setRelationType($relationType);
1336
        //$courseRelUser->setRole($role);
1337
        $courseRelUser->setStatus($status);
1338
        $this->addUsers($courseRelUser);
1339
1340
        return $this;
1341
    }
1342
1343
    public function getDefaultIllustration($size): string
1344
    {
1345
        return '/img/icons/32/course.png';
1346
    }
1347
1348
    public function getResourceIdentifier(): int
1349
    {
1350
        return $this->getId();
1351
    }
1352
1353
    public function getResourceName(): string
1354
    {
1355
        return $this->getCode();
1356
    }
1357
1358
    public function setResourceName(string $name): self
1359
    {
1360
        return $this->setCode($name);
1361
    }
1362
}
1363