Completed
Push — master ( db9c88...be5baf )
by Julito
14:58
created

Course::setTutorName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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