Passed
Push — 1.11.x ( 4399cc...8ad26f )
by Julito
10:24
created

Course::setToolList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* 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 setToolList($list)
345
    {
346
        $this->tools = $list;
347
    }
348
349
    public function addTools(CTool $tool)
350
    {
351
        $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

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

1189
        $courseRelUser->/** @scrutinizer ignore-call */ 
1190
                        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...
1190
        $courseRelUser->setStatus($status);
1191
        $this->addUsers($courseRelUser);
1192
    }
1193
}
1194