Passed
Push — master ( efc6d8...ea9271 )
by Julito
11:57
created

Course::getTitle()   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\CGroupInfo;
7
use Chamilo\CourseBundle\Entity\CTool;
8
use Chamilo\UserBundle\Entity\User;
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\Common\Collections\Criteria;
11
use Doctrine\ORM\Mapping as ORM;
12
use Gedmo\Mapping\Annotation as Gedmo;
13
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
14
use Symfony\Component\Validator\Constraints as Assert;
15
16
/**
17
 * Class Course.
18
 *
19
 * @ORM\HasLifecycleCallbacks
20
 * @ORM\Table(
21
 *  name="course",
22
 *  indexes={
23
 *      @ORM\Index(name="category_code", columns={"category_code"}),
24
 *      @ORM\Index(name="directory", columns={"directory"}),
25
 *  }
26
 * )
27
 * @UniqueEntity("code")
28
 * @UniqueEntity("visualCode")
29
 * @UniqueEntity("directory")
30
 * @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Repository\CourseRepository")
31
 * @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\CourseListener"})
32
 */
33
class Course
34
{
35
    public const CLOSED = 0;
36
    public const REGISTERED = 1;
37
    public const OPEN_PLATFORM = 2;
38
    public const OPEN_WORLD = 3;
39
    public const HIDDEN = 4;
40
41
    /**
42
     * @var int
43
     *
44
     * @ORM\Column(name="id", type="integer", nullable=false, unique=false)
45
     * @ORM\Id
46
     * @ORM\GeneratedValue(strategy="AUTO")
47
     */
48
    protected $id;
49
50
    /**
51
     * "orphanRemoval" is needed to delete the CourseRelUser relation
52
     * in the CourseAdmin class. The setUsers, getUsers, removeUsers and
53
     * addUsers methods need to be added.
54
     *
55
     * @ORM\OneToMany(targetEntity="CourseRelUser", mappedBy="course", cascade={"persist"}, orphanRemoval=true)
56
     */
57
    protected $users;
58
59
    /**
60
     * @ORM\OneToMany(targetEntity="AccessUrlRelCourse", mappedBy="course", cascade={"persist"}, orphanRemoval=true)
61
     */
62
    protected $urls;
63
64
    /**
65
     * @ORM\OneToMany(targetEntity="SessionRelCourse", mappedBy="course", cascade={"persist"})
66
     */
67
    protected $sessions;
68
69
    /**
70
     * @ORM\OneToMany(targetEntity="SessionRelCourseRelUser", mappedBy="course", cascade={"persist"})
71
     */
72
    protected $sessionUserSubscriptions;
73
74
    /**
75
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CGroupInfo", mappedBy="course", cascade={"persist"}, orphanRemoval=true)
76
     */
77
    protected $groups;
78
79
    /**
80
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="course")
81
     */
82
    //protected $items;
83
84
    /**
85
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CTool", mappedBy="course", cascade={"persist"})
86
     */
87
    protected $tools;
88
89
    /**
90
     * @var Session
91
     */
92
    protected $currentSession;
93
94
    /**
95
     * @var AccessUrl
96
     */
97
    protected $currentUrl;
98
99
    /**
100
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="course", cascade={"persist"})
101
     */
102
    protected $issuedSkills;
103
104
    /**
105
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="course")
106
     */
107
    protected $gradebookCategories;
108
109
    /**
110
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookEvaluation", mappedBy="course")
111
     */
112
    protected $gradebookEvaluations;
113
114
    /**
115
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookLink", mappedBy="course")
116
     */
117
    protected $gradebookLinks;
118
119
    /**
120
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\TrackEHotspot", mappedBy="course")
121
     */
122
    protected $trackEHotspots;
123
124
    /**
125
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\TrackEAttempt", mappedBy="course")
126
     */
127
    protected $trackEAttempts;
128
129
    /**
130
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SearchEngineRef", mappedBy="course")
131
     */
132
    protected $searchEngineRefs;
133
134
    /**
135
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Templates", mappedBy="course")
136
     */
137
    protected $templates;
138
139
    /**
140
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course")
141
     */
142
    protected $specificFieldValues;
143
144
    /**
145
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course")
146
     */
147
    protected $sharedSurveys;
148
149
    /**
150
     * @var string
151
     *
152
     * @Assert\NotBlank()
153
     *
154
     * @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false)
155
     */
156
    protected $title;
157
158
    /**
159
     * @var string
160
     * @Gedmo\Slug(
161
     *      fields={"title"},
162
     *      updatable = false,
163
     *      unique = true
164
     * )
165
     * @ORM\Column(name="code", type="string", length=40, nullable=false, unique=true)
166
     */
167
    protected $code;
168
169
    /**
170
     * @var string
171
     *
172
     * @ORM\Column(name="directory", type="string", length=40, nullable=true, unique=false)
173
     */
174
    protected $directory;
175
176
    /**
177
     * @var string
178
     *
179
     * @ORM\Column(name="course_language", type="string", length=20, nullable=true, unique=false)
180
     */
181
    protected $courseLanguage;
182
183
    /**
184
     * @var string
185
     *
186
     * @ORM\Column(name="description", type="text", nullable=true, unique=false)
187
     */
188
    protected $description;
189
190
    /**
191
     * @var string
192
     *
193
     * @ORM\Column(name="category_code", type="string", length=40, nullable=true, unique=false)
194
     */
195
    protected $categoryCode;
196
197
    /**
198
     * @var bool
199
     * @Assert\NotBlank()
200
     * @ORM\Column(name="visibility", type="integer", nullable=true, unique=false)
201
     */
202
    protected $visibility;
203
204
    /**
205
     * @var int
206
     *
207
     * @ORM\Column(name="show_score", type="integer", nullable=true, unique=false)
208
     */
209
    protected $showScore;
210
211
    /**
212
     * @var string
213
     *
214
     * @ORM\Column(name="tutor_name", type="string", length=200, nullable=true, unique=false)
215
     */
216
    protected $tutorName;
217
218
    /**
219
     * @var string
220
     *
221
     * @ORM\Column(name="visual_code", type="string", length=40, nullable=true, unique=false)
222
     */
223
    protected $visualCode;
224
225
    /**
226
     * @var string
227
     *
228
     * @ORM\Column(name="department_name", type="string", length=30, nullable=true, unique=false)
229
     */
230
    protected $departmentName;
231
232
    /**
233
     * @var string
234
     * @Assert\Url()
235
     * @ORM\Column(name="department_url", type="string", length=180, nullable=true, unique=false)
236
     */
237
    protected $departmentUrl;
238
239
    /**
240
     * @var int
241
     *
242
     * @ORM\Column(name="disk_quota", type="bigint", nullable=true, unique=false)
243
     */
244
    protected $diskQuota;
245
246
    /**
247
     * @var \DateTime
248
     *
249
     * @ORM\Column(name="last_visit", type="datetime", nullable=true, unique=false)
250
     */
251
    protected $lastVisit;
252
253
    /**
254
     * @var \DateTime
255
     *
256
     * @ORM\Column(name="last_edit", type="datetime", nullable=true, unique=false)
257
     */
258
    protected $lastEdit;
259
260
    /**
261
     * @var \DateTime
262
     *
263
     * @ORM\Column(name="creation_date", type="datetime", nullable=true, unique=false)
264
     */
265
    protected $creationDate;
266
267
    /**
268
     * @var \DateTime
269
     *
270
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
271
     */
272
    protected $expirationDate;
273
274
    /**
275
     * @var bool
276
     *
277
     * @ORM\Column(name="subscribe", type="boolean", nullable=true, unique=false)
278
     */
279
    protected $subscribe;
280
281
    /**
282
     * @var bool
283
     *
284
     * @ORM\Column(name="unsubscribe", type="boolean", nullable=true, unique=false)
285
     */
286
    protected $unsubscribe;
287
288
    /**
289
     * @var string
290
     *
291
     * @ORM\Column(name="registration_code", type="string", length=255, nullable=true, unique=false)
292
     */
293
    protected $registrationCode;
294
295
    /**
296
     * @var string
297
     *
298
     * @ORM\Column(name="legal", type="text", nullable=true, unique=false)
299
     */
300
    protected $legal;
301
302
    /**
303
     * @var int
304
     *
305
     * @ORM\Column(name="activate_legal", type="integer", nullable=true, unique=false)
306
     */
307
    protected $activateLegal;
308
309
    /**
310
     * @var bool
311
     *
312
     * @ORM\Column(name="add_teachers_to_sessions_courses", type="boolean", nullable=true)
313
     */
314
    protected $addTeachersToSessionsCourses;
315
316
    /**
317
     * @var int
318
     *
319
     * @ORM\Column(name="course_type_id", type="integer", nullable=true, unique=false)
320
     */
321
    protected $courseTypeId;
322
323
    /**
324
     * @ORM\OneToMany(targetEntity="Chamilo\NotebookBundle\Entity\CNotebook", mappedBy="course")
325
     */
326
    //protected $notebooks;
327
328
    /**
329
     * ORM\OneToMany(targetEntity="CurriculumCategory", mappedBy="course").
330
     */
331
    //protected $curriculumCategories;
332
333
    /**
334
     * @var Room
335
     *
336
     * @ORM\ManyToOne(targetEntity="Room")
337
     * @ORM\JoinColumn(name="room_id", referencedColumnName="id")
338
     */
339
    protected $room;
340
341
    /**
342
     * Constructor.
343
     */
344
    public function __construct()
345
    {
346
        $this->creationDate = new \DateTime();
347
        $this->lastVisit = new \DateTime();
348
        $this->lastEdit = new \DateTime();
349
350
        $this->users = new ArrayCollection();
351
        $this->urls = new ArrayCollection();
352
        $this->gradebookCategories = new ArrayCollection();
353
        $this->gradebookEvaluations = new ArrayCollection();
354
        $this->gradebookLinks = new ArrayCollection();
355
        $this->trackEHotspots = new ArrayCollection();
356
        $this->trackEAttempts = new ArrayCollection();
357
        $this->searchEngineRefs = new ArrayCollection();
358
        $this->templates = new ArrayCollection();
359
        $this->specificFieldValues = new ArrayCollection();
360
        $this->sharedSurveys = new ArrayCollection();
361
    }
362
363
    /**
364
     * @return string
365
     */
366
    public function __toString()
367
    {
368
        return (string) $this->getTitle();
369
    }
370
371
    /**
372
     * @return ArrayCollection
373
     */
374
    public function getSessions()
375
    {
376
        return $this->sessions;
377
    }
378
379
    /**
380
     * @return ArrayCollection
381
     */
382
    public function getNotebooks()
383
    {
384
        return $this->notebooks;
0 ignored issues
show
Bug Best Practice introduced by
The property notebooks does not exist on Chamilo\CoreBundle\Entity\Course. Did you maybe forget to declare it?
Loading history...
385
    }
386
387
    /**
388
     * @return ArrayCollection
389
     */
390
    public function getItems()
391
    {
392
        return $this->items;
0 ignored issues
show
Bug Best Practice introduced by
The property items does not exist on Chamilo\CoreBundle\Entity\Course. Did you maybe forget to declare it?
Loading history...
393
    }
394
395
    /**
396
     * @return ArrayCollection
397
     */
398
    public function getTools()
399
    {
400
        return $this->tools;
401
    }
402
403
    /**
404
     * @param array $tools
405
     */
406
    public function setTools($tools)
407
    {
408
        foreach ($tools as $tool) {
409
            $this->addTools($tool);
410
        }
411
    }
412
413
    /**
414
     * @param CTool $tool
415
     */
416
    public function addTools(CTool $tool)
417
    {
418
        $tool->setCourse($this);
419
        $this->tools[] = $tool;
420
    }
421
422
    /**
423
     * @return ArrayCollection
424
     */
425
    public function getUrls()
426
    {
427
        return $this->urls;
428
    }
429
430
    /**
431
     * @param $urls
432
     */
433
    public function setUrls($urls)
434
    {
435
        $this->urls = new ArrayCollection();
436
437
        foreach ($urls as $url) {
438
            $this->addUrls($url);
0 ignored issues
show
Bug introduced by
The method addUrls() does not exist on Chamilo\CoreBundle\Entity\Course. Did you maybe mean addUrl()? ( Ignorable by Annotation )

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

438
            $this->/** @scrutinizer ignore-call */ 
439
                   addUrls($url);

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

1355
        $courseRelUser->/** @scrutinizer ignore-call */ 
1356
                        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...
1356
        $courseRelUser->setStatus($status);
1357
        $this->addUsers($courseRelUser);
1358
    }
1359
}
1360