Passed
Push — 1.11.x ( c309d7...7d3fca )
by Julito
11:19
created

Course::getRegistrationCode()   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
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Entity;
5
6
use Chamilo\CourseBundle\Entity\CTool;
7
use Chamilo\UserBundle\Entity\User;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Criteria;
10
use Doctrine\ORM\Mapping as ORM;
11
use Gedmo\Mapping\Annotation as Gedmo;
12
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
13
use Symfony\Component\Validator\Constraints as Assert;
14
15
/**
16
 * Class Course.
17
 *
18
 * @ORM\HasLifecycleCallbacks
19
 * @ORM\Table(
20
 *  name="course",
21
 *  indexes={
22
 *      @ORM\Index(name="category_code", columns={"category_code"}),
23
 *      @ORM\Index(name="directory", columns={"directory"}),
24
 *  }
25
 * )
26
 * @UniqueEntity("code")
27
 * @UniqueEntity("visualCode")
28
 * @UniqueEntity("directory")
29
 * @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Entity\Repository\CourseRepository")
30
 * @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\CourseListener"})
31
 */
32
class Course
33
{
34
    const CLOSED = 0;
35
    const REGISTERED = 1;
36
    const OPEN_PLATFORM = 2;
37
    const OPEN_WORLD = 3;
38
    const HIDDEN = 4;
39
40
    /**
41
     * @var int
42
     *
43
     * @ORM\Column(name="id", type="integer", nullable=false, unique=false)
44
     * @ORM\Id
45
     * @ORM\GeneratedValue(strategy="AUTO")
46
     */
47
    protected $id;
48
49
    /**
50
     * "orphanRemoval" is needed to delete the CourseRelUser relation
51
     * in the CourseAdmin class. The setUsers, getUsers, removeUsers and
52
     * addUsers methods need to be added.
53
     *
54
     * @ORM\OneToMany(targetEntity="CourseRelUser", mappedBy="course", cascade={"persist"}, orphanRemoval=true)
55
     */
56
    protected $users;
57
58
    /**
59
     * @ORM\OneToMany(targetEntity="AccessUrlRelCourse", mappedBy="course", cascade={"persist"}, orphanRemoval=true)
60
     */
61
    protected $urls;
62
63
    /**
64
     * @ORM\OneToMany(targetEntity="SessionRelCourse", mappedBy="course", cascade={"persist"})
65
     */
66
    protected $sessions;
67
68
    /**
69
     * @ORM\OneToMany(targetEntity="SessionRelCourseRelUser", mappedBy="course", cascade={"persist"})
70
     */
71
    protected $sessionUserSubscriptions;
72
73
    /**
74
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="course")
75
     */
76
    //protected $items;
77
78
    /**
79
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CTool", mappedBy="course", cascade={"persist"})
80
     */
81
    protected $tools;
82
83
    /**
84
     * @var Session
85
     */
86
    protected $currentSession;
87
88
    /**
89
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="course", cascade={"persist"})
90
     */
91
    protected $issuedSkills;
92
93
    /**
94
     * @var string
95
     *
96
     * @Assert\NotBlank()
97
     *
98
     * @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false)
99
     */
100
    protected $title;
101
102
    /**
103
     * @var string
104
     * @Gedmo\Slug(
105
     *      fields={"title"},
106
     *      updatable = false,
107
     *      unique = true
108
     * )
109
     * @ORM\Column(name="code", type="string", length=40, nullable=false, unique=true)
110
     */
111
    protected $code;
112
113
    /**
114
     * @var string
115
     *
116
     * @ORM\Column(name="directory", type="string", length=40, nullable=true, unique=false)
117
     */
118
    protected $directory;
119
120
    /**
121
     * @var string
122
     *
123
     * @ORM\Column(name="course_language", type="string", length=20, nullable=true, unique=false)
124
     */
125
    protected $courseLanguage;
126
127
    /**
128
     * @var string
129
     *
130
     * @ORM\Column(name="description", type="text", nullable=true, unique=false)
131
     */
132
    protected $description;
133
134
    /**
135
     * @var string
136
     *
137
     * @ORM\Column(name="category_code", type="string", length=40, nullable=true, unique=false)
138
     */
139
    protected $categoryCode;
140
141
    /**
142
     * @var bool
143
     * @Assert\NotBlank()
144
     * @ORM\Column(name="visibility", type="integer", nullable=true, unique=false)
145
     */
146
    protected $visibility;
147
148
    /**
149
     * @var int
150
     *
151
     * @ORM\Column(name="show_score", type="integer", nullable=true, unique=false)
152
     */
153
    protected $showScore;
154
155
    /**
156
     * @var string
157
     *
158
     * @ORM\Column(name="tutor_name", type="string", length=200, nullable=true, unique=false)
159
     */
160
    protected $tutorName;
161
162
    /**
163
     * @var string
164
     *
165
     * @ORM\Column(name="visual_code", type="string", length=40, nullable=true, unique=false)
166
     */
167
    protected $visualCode;
168
169
    /**
170
     * @var string
171
     *
172
     * @ORM\Column(name="department_name", type="string", length=30, nullable=true, unique=false)
173
     */
174
    protected $departmentName;
175
176
    /**
177
     * @var string
178
     * @Assert\Url()
179
     * @ORM\Column(name="department_url", type="string", length=180, nullable=true, unique=false)
180
     */
181
    protected $departmentUrl;
182
183
    /**
184
     * @var int
185
     *
186
     * @ORM\Column(name="disk_quota", type="bigint", nullable=true, unique=false)
187
     */
188
    protected $diskQuota;
189
190
    /**
191
     * @var \DateTime
192
     *
193
     * @ORM\Column(name="last_visit", type="datetime", nullable=true, unique=false)
194
     */
195
    protected $lastVisit;
196
197
    /**
198
     * @var \DateTime
199
     *
200
     * @ORM\Column(name="last_edit", type="datetime", nullable=true, unique=false)
201
     */
202
    protected $lastEdit;
203
204
    /**
205
     * @var \DateTime
206
     *
207
     * @ORM\Column(name="creation_date", type="datetime", nullable=true, unique=false)
208
     */
209
    protected $creationDate;
210
211
    /**
212
     * @var \DateTime
213
     *
214
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
215
     */
216
    protected $expirationDate;
217
218
    /**
219
     * @var bool
220
     *
221
     * @ORM\Column(name="subscribe", type="boolean", nullable=true, unique=false)
222
     */
223
    protected $subscribe;
224
225
    /**
226
     * @var bool
227
     *
228
     * @ORM\Column(name="unsubscribe", type="boolean", nullable=true, unique=false)
229
     */
230
    protected $unsubscribe;
231
232
    /**
233
     * @var string
234
     *
235
     * @ORM\Column(name="registration_code", type="string", length=255, nullable=true, unique=false)
236
     */
237
    protected $registrationCode;
238
239
    /**
240
     * @var string
241
     *
242
     * @ORM\Column(name="legal", type="text", nullable=true, unique=false)
243
     */
244
    protected $legal;
245
246
    /**
247
     * @var int
248
     *
249
     * @ORM\Column(name="activate_legal", type="integer", nullable=true, unique=false)
250
     */
251
    protected $activateLegal;
252
253
    /**
254
     * @var bool
255
     *
256
     * @ORM\Column(name="add_teachers_to_sessions_courses", type="boolean", nullable=true)
257
     */
258
    protected $addTeachersToSessionsCourses;
259
260
    /**
261
     * @var int
262
     *
263
     * @ORM\Column(name="course_type_id", type="integer", nullable=true, unique=false)
264
     */
265
    protected $courseTypeId;
266
267
    /**
268
     * @ORM\OneToMany(targetEntity="Chamilo\NotebookBundle\Entity\CNotebook", mappedBy="course")
269
     */
270
    //protected $notebooks;
271
272
    /**
273
     * ORM\OneToMany(targetEntity="CurriculumCategory", mappedBy="course").
274
     */
275
    //protected $curriculumCategories;
276
277
    /**
278
     * @var Room
279
     *
280
     * @ORM\ManyToOne(targetEntity="Room")
281
     * @ORM\JoinColumn(name="room_id", referencedColumnName="id")
282
     */
283
    protected $room;
284
285
    /**
286
     * Constructor.
287
     */
288
    public function __construct()
289
    {
290
        $this->creationDate = new \DateTime();
291
        $this->users = new ArrayCollection();
292
    }
293
294
    /**
295
     * @return string
296
     */
297
    public function __toString()
298
    {
299
        return (string) $this->getTitle();
300
    }
301
302
    /**
303
     * @return ArrayCollection
304
     */
305
    public function getSessions()
306
    {
307
        return $this->sessions;
308
    }
309
310
    /**
311
     * @return ArrayCollection
312
     */
313
    /*public function getNotebooks()
314
    {
315
        return $this->notebooks;
316
    }*/
317
318
    /**
319
     * @return ArrayCollection
320
     */
321
    /*public function getItems()
322
    {
323
        return $this->items;
324
    }*/
325
326
    /**
327
     * @return ArrayCollection
328
     */
329
    public function getTools()
330
    {
331
        return $this->tools;
332
    }
333
334
    /**
335
     * @param $tools
336
     */
337
    public function setTools($tools)
338
    {
339
        foreach ($tools as $tool) {
340
            $this->addTools($tool);
341
        }
342
    }
343
344
    public function addTools(CTool $tool)
345
    {
346
        $tool->setCourse($this);
0 ignored issues
show
Bug introduced by
The method setCourse() does not exist on Chamilo\CourseBundle\Entity\CTool. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

346
        $tool->/** @scrutinizer ignore-call */ 
347
               setCourse($this);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
347
        $this->tools[] = $tool;
348
    }
349
350
    /**
351
     * @return ArrayCollection
352
     */
353
    public function getUrls()
354
    {
355
        return $this->urls;
356
    }
357
358
    /**
359
     * @param $urls
360
     */
361
    public function setUrls($urls)
362
    {
363
        $this->urls = new ArrayCollection();
364
365
        foreach ($urls as $url) {
366
            $this->addUrls($url);
367
        }
368
    }
369
370
    public function addUrls(AccessUrlRelCourse $url)
371
    {
372
        $url->setCourse($this);
373
        $this->urls[] = $url;
374
    }
375
376
    /**
377
     * @return ArrayCollection
378
     */
379
    public function getUsers()
380
    {
381
        return $this->users;
382
    }
383
384
    /**
385
     * @return ArrayCollection
386
     */
387
    public function getTeachers()
388
    {
389
        $criteria = Criteria::create();
390
        $criteria->where(Criteria::expr()->eq('status', User::COURSE_MANAGER));
391
392
        return $this->users->matching($criteria);
393
    }
394
395
    /**
396
     * @return ArrayCollection
397
     */
398
    public function getStudents()
399
    {
400
        $criteria = Criteria::create();
401
        $criteria->where(Criteria::expr()->eq('status', User::STUDENT));
402
403
        return $this->users->matching($criteria);
404
    }
405
406
    /**
407
     * @param ArrayCollection $users
408
     */
409
    public function setUsers($users)
410
    {
411
        $this->users = new ArrayCollection();
412
413
        foreach ($users as $user) {
414
            $this->addUsers($user);
415
        }
416
    }
417
418
    public function addUsers(CourseRelUser $courseRelUser)
419
    {
420
        $courseRelUser->setCourse($this);
421
422
        if (!$this->hasSubscription($courseRelUser)) {
423
            $this->users[] = $courseRelUser;
424
        }
425
    }
426
427
    /**
428
     * @return bool
429
     */
430
    public function hasUser(User $user)
431
    {
432
        $criteria = Criteria::create()->where(
433
            Criteria::expr()->eq("user", $user)
434
        );
435
436
        return $this->getUsers()->matching($criteria)->count() > 0;
437
    }
438
439
    /**
440
     * @return bool
441
     */
442
    public function hasStudent(User $user)
443
    {
444
        $criteria = Criteria::create()->where(
445
            Criteria::expr()->eq("user", $user)
446
        );
447
448
        return $this->getStudents()->matching($criteria)->count() > 0;
449
    }
450
451
    /**
452
     * @return bool
453
     */
454
    public function hasTeacher(User $user)
455
    {
456
        $criteria = Criteria::create()->where(
457
            Criteria::expr()->eq("user", $user)
458
        );
459
460
        return $this->getTeachers()->matching($criteria)->count() > 0;
461
    }
462
463
    /**
464
     * Remove $user.
465
     */
466
    public function removeUsers(CourseRelUser $user)
467
    {
468
        foreach ($this->users as $key => $value) {
469
            if ($value->getId() == $user->getId()) {
470
                unset($this->users[$key]);
471
            }
472
        }
473
    }
474
475
    public function addTeacher(User $user)
476
    {
477
        $this->addUser($user, 0, "Trainer", User::COURSE_MANAGER);
478
    }
479
480
    public function addStudent(User $user)
481
    {
482
        $this->addUser($user, 0, "", User::STUDENT);
483
    }
484
485
    /**
486
     * Set id.
487
     *
488
     * @return int
489
     */
490
    public function setId($id)
491
    {
492
        $this->id = $id;
493
    }
494
495
    /**
496
     * Get id.
497
     *
498
     * @return int
499
     */
500
    public function getId()
501
    {
502
        return $this->id;
503
    }
504
505
    /**
506
     * Set code.
507
     *
508
     * @param string $code
509
     *
510
     * @return Course
511
     */
512
    public function setCode($code)
513
    {
514
        $this->code = $code;
515
        $this->visualCode = $code;
516
        $this->directory = $code;
517
518
        return $this;
519
    }
520
521
    /**
522
     * Get code.
523
     *
524
     * @return string
525
     */
526
    public function getCode()
527
    {
528
        return $this->code;
529
    }
530
531
    /**
532
     * Set directory.
533
     *
534
     * @param string $directory
535
     *
536
     * @return Course
537
     */
538
    public function setDirectory($directory)
539
    {
540
        $this->directory = $directory;
541
542
        return $this;
543
    }
544
545
    /**
546
     * Get directory.
547
     *
548
     * @return string
549
     */
550
    public function getDirectory()
551
    {
552
        return $this->directory;
553
    }
554
555
    /**
556
     * Set courseLanguage.
557
     *
558
     * @param string $courseLanguage
559
     *
560
     * @return Course
561
     */
562
    public function setCourseLanguage($courseLanguage)
563
    {
564
        $this->courseLanguage = $courseLanguage;
565
566
        return $this;
567
    }
568
569
    /**
570
     * Get courseLanguage.
571
     *
572
     * @return string
573
     */
574
    public function getCourseLanguage()
575
    {
576
        return $this->courseLanguage;
577
    }
578
579
    /**
580
     * Set title.
581
     *
582
     * @param string $title
583
     *
584
     * @return Course
585
     */
586
    public function setTitle($title)
587
    {
588
        $this->title = $title;
589
590
        return $this;
591
    }
592
593
    /**
594
     * Get title.
595
     *
596
     * @return string
597
     */
598
    public function getTitle()
599
    {
600
        return $this->title;
601
    }
602
603
    public function getName()
604
    {
605
        return $this->getTitle();
606
    }
607
608
    /**
609
     * @return string
610
     */
611
    public function getTitleAndCode()
612
    {
613
        return $this->getTitle().' ('.$this->getCode().')';
614
    }
615
616
    /**
617
     * Set description.
618
     *
619
     * @param string $description
620
     *
621
     * @return Course
622
     */
623
    public function setDescription($description)
624
    {
625
        $this->description = $description;
626
627
        return $this;
628
    }
629
630
    /**
631
     * Get description.
632
     *
633
     * @return string
634
     */
635
    public function getDescription()
636
    {
637
        return $this->description;
638
    }
639
640
    /**
641
     * Set categoryCode.
642
     *
643
     * @param string $categoryCode
644
     *
645
     * @return Course
646
     */
647
    public function setCategoryCode($categoryCode)
648
    {
649
        $this->categoryCode = $categoryCode;
650
651
        return $this;
652
    }
653
654
    /**
655
     * Get categoryCode.
656
     *
657
     * @return string
658
     */
659
    public function getCategoryCode()
660
    {
661
        return $this->categoryCode;
662
    }
663
664
    /**
665
     * Set visibility.
666
     *
667
     * @param bool $visibility
668
     *
669
     * @return Course
670
     */
671
    public function setVisibility($visibility)
672
    {
673
        $this->visibility = $visibility;
674
675
        return $this;
676
    }
677
678
    /**
679
     * Get visibility.
680
     *
681
     * @return bool
682
     */
683
    public function getVisibility()
684
    {
685
        return $this->visibility;
686
    }
687
688
    /**
689
     * Set showScore.
690
     *
691
     * @param int $showScore
692
     *
693
     * @return Course
694
     */
695
    public function setShowScore($showScore)
696
    {
697
        $this->showScore = $showScore;
698
699
        return $this;
700
    }
701
702
    /**
703
     * Get showScore.
704
     *
705
     * @return int
706
     */
707
    public function getShowScore()
708
    {
709
        return $this->showScore;
710
    }
711
712
    /**
713
     * Set tutorName.
714
     *
715
     * @param string $tutorName
716
     *
717
     * @return Course
718
     */
719
    public function setTutorName($tutorName)
720
    {
721
        $this->tutorName = $tutorName;
722
723
        return $this;
724
    }
725
726
    /**
727
     * Get tutorName.
728
     *
729
     * @return string
730
     */
731
    public function getTutorName()
732
    {
733
        return $this->tutorName;
734
    }
735
736
    /**
737
     * Set visualCode.
738
     *
739
     * @param string $visualCode
740
     *
741
     * @return Course
742
     */
743
    public function setVisualCode($visualCode)
744
    {
745
        $this->visualCode = $visualCode;
746
747
        return $this;
748
    }
749
750
    /**
751
     * Get visualCode.
752
     *
753
     * @return string
754
     */
755
    public function getVisualCode()
756
    {
757
        return $this->visualCode;
758
    }
759
760
    /**
761
     * Set departmentName.
762
     *
763
     * @param string $departmentName
764
     *
765
     * @return Course
766
     */
767
    public function setDepartmentName($departmentName)
768
    {
769
        $this->departmentName = $departmentName;
770
771
        return $this;
772
    }
773
774
    /**
775
     * Get departmentName.
776
     *
777
     * @return string
778
     */
779
    public function getDepartmentName()
780
    {
781
        return $this->departmentName;
782
    }
783
784
    /**
785
     * Set departmentUrl.
786
     *
787
     * @param string $departmentUrl
788
     *
789
     * @return Course
790
     */
791
    public function setDepartmentUrl($departmentUrl)
792
    {
793
        $this->departmentUrl = $departmentUrl;
794
795
        return $this;
796
    }
797
798
    /**
799
     * Get departmentUrl.
800
     *
801
     * @return string
802
     */
803
    public function getDepartmentUrl()
804
    {
805
        return $this->departmentUrl;
806
    }
807
808
    /**
809
     * Set diskQuota.
810
     *
811
     * @param int $diskQuota
812
     *
813
     * @return Course
814
     */
815
    public function setDiskQuota($diskQuota)
816
    {
817
        $this->diskQuota = intval($diskQuota);
818
819
        return $this;
820
    }
821
822
    /**
823
     * Get diskQuota.
824
     *
825
     * @return int
826
     */
827
    public function getDiskQuota()
828
    {
829
        return $this->diskQuota;
830
    }
831
832
    /**
833
     * Set lastVisit.
834
     *
835
     * @param \DateTime $lastVisit
836
     *
837
     * @return Course
838
     */
839
    public function setLastVisit($lastVisit)
840
    {
841
        $this->lastVisit = $lastVisit;
842
843
        return $this;
844
    }
845
846
    /**
847
     * Get lastVisit.
848
     *
849
     * @return \DateTime
850
     */
851
    public function getLastVisit()
852
    {
853
        return $this->lastVisit;
854
    }
855
856
    /**
857
     * Set lastEdit.
858
     *
859
     * @param \DateTime $lastEdit
860
     *
861
     * @return Course
862
     */
863
    public function setLastEdit($lastEdit)
864
    {
865
        $this->lastEdit = $lastEdit;
866
867
        return $this;
868
    }
869
870
    /**
871
     * Get lastEdit.
872
     *
873
     * @return \DateTime
874
     */
875
    public function getLastEdit()
876
    {
877
        return $this->lastEdit;
878
    }
879
880
    /**
881
     * Set creationDate.
882
     *
883
     * @param \DateTime $creationDate
884
     *
885
     * @return Course
886
     */
887
    public function setCreationDate($creationDate)
888
    {
889
        $this->creationDate = $creationDate;
890
891
        return $this;
892
    }
893
894
    /**
895
     * Get creationDate.
896
     *
897
     * @return \DateTime
898
     */
899
    public function getCreationDate()
900
    {
901
        return $this->creationDate;
902
    }
903
904
    /**
905
     * Set expirationDate.
906
     *
907
     * @param \DateTime $expirationDate
908
     *
909
     * @return Course
910
     */
911
    public function setExpirationDate($expirationDate)
912
    {
913
        $this->expirationDate = $expirationDate;
914
915
        return $this;
916
    }
917
918
    /**
919
     * Get expirationDate.
920
     *
921
     * @return \DateTime
922
     */
923
    public function getExpirationDate()
924
    {
925
        return $this->expirationDate;
926
    }
927
928
    /**
929
     * Set subscribe.
930
     *
931
     * @param bool $subscribe
932
     *
933
     * @return Course
934
     */
935
    public function setSubscribe($subscribe)
936
    {
937
        $this->subscribe = boolval($subscribe);
938
939
        return $this;
940
    }
941
942
    /**
943
     * Get subscribe.
944
     *
945
     * @return bool
946
     */
947
    public function getSubscribe()
948
    {
949
        return $this->subscribe;
950
    }
951
952
    /**
953
     * Set unsubscribe.
954
     *
955
     * @param bool $unsubscribe
956
     *
957
     * @return Course
958
     */
959
    public function setUnsubscribe($unsubscribe)
960
    {
961
        $this->unsubscribe = boolval($unsubscribe);
962
963
        return $this;
964
    }
965
966
    /**
967
     * Get unsubscribe.
968
     *
969
     * @return bool
970
     */
971
    public function getUnsubscribe()
972
    {
973
        return $this->unsubscribe;
974
    }
975
976
    /**
977
     * Set registrationCode.
978
     *
979
     * @param string $registrationCode
980
     *
981
     * @return Course
982
     */
983
    public function setRegistrationCode($registrationCode)
984
    {
985
        $this->registrationCode = $registrationCode;
986
987
        return $this;
988
    }
989
990
    /**
991
     * Get registrationCode.
992
     *
993
     * @return string
994
     */
995
    public function getRegistrationCode()
996
    {
997
        return $this->registrationCode;
998
    }
999
1000
    /**
1001
     * Set legal.
1002
     *
1003
     * @param string $legal
1004
     *
1005
     * @return Course
1006
     */
1007
    public function setLegal($legal)
1008
    {
1009
        $this->legal = $legal;
1010
1011
        return $this;
1012
    }
1013
1014
    /**
1015
     * Get legal.
1016
     *
1017
     * @return string
1018
     */
1019
    public function getLegal()
1020
    {
1021
        return $this->legal;
1022
    }
1023
1024
    /**
1025
     * Set activateLegal.
1026
     *
1027
     * @param int $activateLegal
1028
     *
1029
     * @return Course
1030
     */
1031
    public function setActivateLegal($activateLegal)
1032
    {
1033
        $this->activateLegal = $activateLegal;
1034
1035
        return $this;
1036
    }
1037
1038
    /**
1039
     * Get activateLegal.
1040
     *
1041
     * @return int
1042
     */
1043
    public function getActivateLegal()
1044
    {
1045
        return $this->activateLegal;
1046
    }
1047
1048
    /**
1049
     * Set courseTypeId.
1050
     *
1051
     * @param int $courseTypeId
1052
     *
1053
     * @return Course
1054
     */
1055
    public function setCourseTypeId($courseTypeId)
1056
    {
1057
        $this->courseTypeId = $courseTypeId;
1058
1059
        return $this;
1060
    }
1061
1062
    /**
1063
     * Get courseTypeId.
1064
     *
1065
     * @return int
1066
     */
1067
    public function getCourseTypeId()
1068
    {
1069
        return $this->courseTypeId;
1070
    }
1071
1072
    /**
1073
     * @return Room
1074
     */
1075
    public function getRoom()
1076
    {
1077
        return $this->room;
1078
    }
1079
1080
    /**
1081
     * @param Room $room
1082
     *
1083
     * @return Course
1084
     */
1085
    public function setRoom($room)
1086
    {
1087
        $this->room = $room;
1088
1089
        return $this;
1090
    }
1091
1092
    /**
1093
     * @return bool
1094
     */
1095
    public function isActive()
1096
    {
1097
        $activeVisibilityList = [
1098
            self::REGISTERED,
1099
            self::OPEN_PLATFORM,
1100
            self::OPEN_WORLD,
1101
        ];
1102
1103
        return in_array($this->visibility, $activeVisibilityList);
1104
    }
1105
1106
    /**
1107
     * Anybody can see this course.
1108
     *
1109
     * @return bool
1110
     */
1111
    public function isPublic()
1112
    {
1113
        return $this->visibility == self::OPEN_WORLD;
1114
    }
1115
1116
    /**
1117
     * @return array
1118
     */
1119
    public static function getStatusList()
1120
    {
1121
        return [
1122
            self::CLOSED => 'Closed',
1123
            self::REGISTERED => 'Registered',
1124
            self::OPEN_PLATFORM => 'Open platform',
1125
            self::OPEN_WORLD => 'Open world',
1126
            self::HIDDEN => 'Hidden',
1127
        ];
1128
    }
1129
1130
    /**
1131
     * @return Session
1132
     */
1133
    public function getCurrentSession()
1134
    {
1135
        return $this->currentSession;
1136
    }
1137
1138
    /**
1139
     * @return $this
1140
     */
1141
    public function setCurrentSession(Session $session)
1142
    {
1143
        // If the session is registered in the course session list.
1144
        if ($this->getSessions()->contains($session->getId())) {
1145
            $this->currentSession = $session;
1146
        }
1147
1148
        return $this;
1149
    }
1150
1151
    /**
1152
     * @return bool
1153
     */
1154
    protected function hasSubscription(CourseRelUser $subscription)
1155
    {
1156
        if ($this->getUsers()->count()) {
1157
            $criteria = Criteria::create()->where(
1158
                Criteria::expr()->eq('user', $subscription->getUser())
1159
            )->andWhere(
1160
                Criteria::expr()->eq('status', $subscription->getStatus())
1161
            )->andWhere(
1162
                Criteria::expr()->eq('relationType', $subscription->getRelationType())
1163
            );
1164
1165
            $relation = $this->getUsers()->matching($criteria);
1166
1167
            return $relation->count() > 0;
1168
        }
1169
1170
        return false;
1171
    }
1172
1173
    /**
1174
     * @param string $relationType
1175
     * @param string $role
1176
     * @param string $status
1177
     */
1178
    protected function addUser(User $user, $relationType, $role, $status)
1179
    {
1180
        $courseRelUser = new CourseRelUser();
1181
        $courseRelUser->setCourse($this);
1182
        $courseRelUser->setUser($user);
1183
        $courseRelUser->setRelationType($relationType);
1184
        $courseRelUser->setRole($role);
0 ignored issues
show
Bug introduced by
The method setRole() does not exist on Chamilo\CoreBundle\Entity\CourseRelUser. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1184
        $courseRelUser->/** @scrutinizer ignore-call */ 
1185
                        setRole($role);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1185
        $courseRelUser->setStatus($status);
1186
        $this->addUsers($courseRelUser);
1187
    }
1188
}
1189