Completed
Push — master ( 76b5db...d28136 )
by Julito
13:35
created

Course::getResourceFieldName()   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
c 0
b 0
f 0
nop 0
dl 0
loc 3
rs 10
nc 1
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Entity;
5
6
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
7
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface;
8
use Chamilo\CourseBundle\Entity\CGroupInfo;
9
use Chamilo\CourseBundle\Entity\CTool;
10
use Chamilo\UserBundle\Entity\User;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\Common\Collections\Criteria;
13
use Doctrine\ORM\Mapping as ORM;
14
use Gedmo\Mapping\Annotation as Gedmo;
15
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
16
use Symfony\Component\Validator\Constraints as Assert;
17
18
/**
19
 * Class Course.
20
 *
21
 * @ORM\HasLifecycleCallbacks
22
 * @ORM\Table(
23
 *  name="course",
24
 *  indexes={
25
 *      @ORM\Index(name="directory", columns={"directory"}),
26
 *  }
27
 * )
28
 * @UniqueEntity("code")
29
 * @UniqueEntity("visualCode")
30
 * @UniqueEntity("directory")
31
 *
32
 * @ORM\Entity
33
 * @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\CourseListener"})
34
 */
35
class Course extends AbstractResource implements ResourceInterface
36
{
37
    public const CLOSED = 0;
38
    public const REGISTERED = 1;
39
    public const OPEN_PLATFORM = 2;
40
    public const OPEN_WORLD = 3;
41
    public const HIDDEN = 4;
42
43
    /**
44
     * @var int
45
     *
46
     * @ORM\Column(name="id", type="integer", nullable=false, unique=false)
47
     * @ORM\Id
48
     * @ORM\GeneratedValue(strategy="AUTO")
49
     */
50
    protected $id;
51
52
    /**
53
     * @var string
54
     *
55
     * @Assert\NotBlank()
56
     *
57
     * @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false)
58
     */
59
    protected $title;
60
61
    /**
62
     * "orphanRemoval" is needed to delete the CourseRelUser relation
63
     * in the CourseAdmin class. The setUsers, getUsers, removeUsers and
64
     * addUsers methods need to be added.
65
     *
66
     * @ORM\OneToMany(targetEntity="CourseRelUser", mappedBy="course", cascade={"persist"}, orphanRemoval=true)
67
     */
68
    protected $users;
69
70
    /**
71
     * @ORM\OneToMany(targetEntity="AccessUrlRelCourse", mappedBy="course", cascade={"persist", "remove"}, orphanRemoval=true)
72
     */
73
    protected $urls;
74
75
    /**
76
     * @ORM\OneToMany(targetEntity="SessionRelCourse", mappedBy="course", cascade={"persist", "remove"})
77
     */
78
    protected $sessions;
79
80
    /**
81
     * @ORM\OneToMany(targetEntity="SessionRelCourseRelUser", mappedBy="course", cascade={"persist", "remove"})
82
     */
83
    protected $sessionUserSubscriptions;
84
85
    /**
86
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CGroupInfo", mappedBy="course", cascade={"persist", "remove"})
87
     */
88
    protected $groups;
89
90
    /**
91
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CItemProperty", mappedBy="course")
92
     */
93
    //protected $items;
94
95
    /**
96
     * @var ArrayCollection
97
     *
98
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CTool", mappedBy="course", cascade={"persist", "remove"})
99
     */
100
    protected $tools;
101
102
    /**
103
     * @var Session
104
     */
105
    protected $currentSession;
106
107
    /**
108
     * @var AccessUrl
109
     */
110
    protected $currentUrl;
111
112
    /**
113
     * @ORM\OneToMany(targetEntity="Chamilo\SkillBundle\Entity\SkillRelCourse", mappedBy="course", cascade={"persist", "remove"})
114
     */
115
    protected $skills;
116
117
    /**
118
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SkillRelUser", mappedBy="course", cascade={"persist", "remove"})
119
     */
120
    protected $issuedSkills;
121
122
    /**
123
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookCategory", mappedBy="course", cascade={"persist", "remove"})
124
     */
125
    protected $gradebookCategories;
126
127
    /**
128
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookEvaluation", mappedBy="course", cascade={"persist", "remove"})
129
     */
130
    protected $gradebookEvaluations;
131
132
    /**
133
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\GradebookLink", mappedBy="course", cascade={"persist", "remove"})
134
     */
135
    protected $gradebookLinks;
136
137
    /**
138
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\TrackEHotspot", mappedBy="course", cascade={"persist", "remove"})
139
     */
140
    protected $trackEHotspots;
141
142
    /**
143
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\TrackEAttempt", mappedBy="course", cascade={"persist", "remove"})
144
     */
145
    protected $trackEAttempts;
146
147
    /**
148
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SearchEngineRef", mappedBy="course", cascade={"persist", "remove"})
149
     */
150
    protected $searchEngineRefs;
151
152
    /**
153
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Templates", mappedBy="course", cascade={"persist", "remove"})
154
     */
155
    protected $templates;
156
157
    /**
158
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\Resource\ResourceLink", mappedBy="course", cascade={"remove"}, orphanRemoval=true)
159
     */
160
    protected $resourceLinks;
161
162
    /**
163
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course")
164
     */
165
    //protected $specificFieldValues;
166
167
    /**
168
     * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course")
169
     */
170
    //protected $sharedSurveys;
171
172
    /**
173
     * @var string
174
     *
175
     * @Gedmo\Slug(
176
     *      fields={"title"},
177
     *      updatable = false,
178
     *      unique = true,
179
     *      style = "upper"
180
     * )
181
     * @ORM\Column(name="code", type="string", length=40, nullable=false, unique=true)
182
     */
183
    protected $code;
184
185
    /**
186
     * @var string
187
     *
188
     * @ORM\Column(name="directory", type="string", length=40, nullable=true, unique=false)
189
     */
190
    protected $directory;
191
192
    /**
193
     * @var string
194
     *
195
     * @ORM\Column(name="course_language", type="string", length=20, nullable=true, unique=false)
196
     */
197
    protected $courseLanguage;
198
199
    /**
200
     * @var string
201
     *
202
     * @ORM\Column(name="description", type="text", nullable=true, unique=false)
203
     */
204
    protected $description;
205
206
    /**
207
     * @var CourseCategory
208
     *
209
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="courses")
210
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
211
     */
212
    protected $category;
213
214
    /**
215
     * @var int
216
     *
217
     * @Assert\NotBlank()
218
     *
219
     * @ORM\Column(name="visibility", type="integer", nullable=true, unique=false)
220
     */
221
    protected $visibility;
222
223
    /**
224
     * @var int
225
     *
226
     * @ORM\Column(name="show_score", type="integer", nullable=true, unique=false)
227
     */
228
    protected $showScore;
229
230
    /**
231
     * @var string
232
     *
233
     * @ORM\Column(name="tutor_name", type="string", length=200, nullable=true, unique=false)
234
     */
235
    protected $tutorName;
236
237
    /**
238
     * @var string
239
     *
240
     * @ORM\Column(name="visual_code", type="string", length=40, nullable=true, unique=false)
241
     */
242
    protected $visualCode;
243
244
    /**
245
     * @var string
246
     *
247
     * @ORM\Column(name="department_name", type="string", length=30, nullable=true, unique=false)
248
     */
249
    protected $departmentName;
250
251
    /**
252
     * @var string
253
     *
254
     * @Assert\Url()
255
     *
256
     * @ORM\Column(name="department_url", type="string", length=180, nullable=true, unique=false)
257
     */
258
    protected $departmentUrl;
259
260
    /**
261
     * @var int
262
     *
263
     * @ORM\Column(name="disk_quota", type="bigint", nullable=true, unique=false)
264
     */
265
    protected $diskQuota;
266
267
    /**
268
     * @var \DateTime
269
     *
270
     * @ORM\Column(name="last_visit", type="datetime", nullable=true, unique=false)
271
     */
272
    protected $lastVisit;
273
274
    /**
275
     * @var \DateTime
276
     *
277
     * @ORM\Column(name="last_edit", type="datetime", nullable=true, unique=false)
278
     */
279
    protected $lastEdit;
280
281
    /**
282
     * @var \DateTime
283
     *
284
     * @ORM\Column(name="creation_date", type="datetime", nullable=true, unique=false)
285
     */
286
    protected $creationDate;
287
288
    /**
289
     * @var \DateTime
290
     *
291
     * @ORM\Column(name="expiration_date", type="datetime", nullable=true, unique=false)
292
     */
293
    protected $expirationDate;
294
295
    /**
296
     * @var bool
297
     *
298
     * @ORM\Column(name="subscribe", type="boolean", nullable=true, unique=false)
299
     */
300
    protected $subscribe;
301
302
    /**
303
     * @var bool
304
     *
305
     * @ORM\Column(name="unsubscribe", type="boolean", nullable=true, unique=false)
306
     */
307
    protected $unsubscribe;
308
309
    /**
310
     * @var string
311
     *
312
     * @ORM\Column(name="registration_code", type="string", length=255, nullable=true, unique=false)
313
     */
314
    protected $registrationCode;
315
316
    /**
317
     * @var string
318
     *
319
     * @ORM\Column(name="legal", type="text", nullable=true, unique=false)
320
     */
321
    protected $legal;
322
323
    /**
324
     * @var int
325
     *
326
     * @ORM\Column(name="activate_legal", type="integer", nullable=true, unique=false)
327
     */
328
    protected $activateLegal;
329
330
    /**
331
     * @var bool
332
     *
333
     * @ORM\Column(name="add_teachers_to_sessions_courses", type="boolean", nullable=true)
334
     */
335
    protected $addTeachersToSessionsCourses;
336
337
    /**
338
     * @var int
339
     *
340
     * @ORM\Column(name="course_type_id", type="integer", nullable=true, unique=false)
341
     */
342
    protected $courseTypeId;
343
344
    /**
345
     * ORM\OneToMany(targetEntity="CurriculumCategory", mappedBy="course").
346
     */
347
    //protected $curriculumCategories;
348
349
    /**
350
     * @var Room
351
     *
352
     * @ORM\ManyToOne(targetEntity="Room")
353
     * @ORM\JoinColumn(name="room_id", referencedColumnName="id")
354
     */
355
    protected $room;
356
357
    /**
358
     * Constructor.
359
     */
360
    public function __construct()
361
    {
362
        $this->creationDate = new \DateTime();
363
        $this->lastVisit = new \DateTime();
364
        $this->lastEdit = new \DateTime();
365
366
        $this->users = new ArrayCollection();
367
        $this->urls = new ArrayCollection();
368
        $this->gradebookCategories = new ArrayCollection();
369
        $this->gradebookEvaluations = new ArrayCollection();
370
        $this->gradebookLinks = new ArrayCollection();
371
        $this->trackEHotspots = new ArrayCollection();
372
        $this->trackEAttempts = new ArrayCollection();
373
        $this->searchEngineRefs = new ArrayCollection();
374
        $this->templates = new ArrayCollection();
375
        $this->specificFieldValues = new ArrayCollection();
0 ignored issues
show
Bug Best Practice introduced by
The property specificFieldValues does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
376
        $this->sharedSurveys = new ArrayCollection();
0 ignored issues
show
Bug Best Practice introduced by
The property sharedSurveys does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
377
    }
378
379
    /**
380
     * @return string
381
     */
382
    public function __toString(): string
383
    {
384
        return $this->getTitle();
385
    }
386
387
    /**
388
     * @return ArrayCollection
389
     */
390
    public function getSessions()
391
    {
392
        return $this->sessions;
393
    }
394
395
    /**
396
     * @param Session $session
397
     *
398
     * @return ArrayCollection
399
     */
400
    public function getTools(Session $session = null)
401
    {
402
        $orWhere = Criteria::expr()->eq('sessionId', 0);
403
404
        if ($session) {
405
            $orWhere = Criteria::expr()->in('sessionId', [0, $session->getId()]);
406
        }
407
408
        $criteria = Criteria::create()
409
            ->where(Criteria::expr()->isNull('sessionId'))
410
            ->orWhere($orWhere);
411
412
        return $this->tools->matching($criteria);
413
    }
414
415
    /**
416
     * @param array $tools
417
     */
418
    public function setTools($tools)
419
    {
420
        foreach ($tools as $tool) {
421
            $this->addTools($tool);
422
        }
423
    }
424
425
    public function addTools(CTool $tool)
426
    {
427
        $tool->setCourse($this);
428
        $this->tools[] = $tool;
429
    }
430
431
    /**
432
     * @return ArrayCollection
433
     */
434
    public function getUrls()
435
    {
436
        return $this->urls;
437
    }
438
439
    /**
440
     * @param $urls
441
     */
442
    public function setUrls($urls)
443
    {
444
        $this->urls = new ArrayCollection();
445
446
        foreach ($urls as $url) {
447
            $this->addUrls($url);
448
        }
449
    }
450
451
    public function addUrlRelCourse(AccessUrlRelCourse $url)
452
    {
453
        $url->setCourse($this);
454
        $this->urls[] = $url;
455
    }
456
457
    public function addUrl(AccessUrl $url)
458
    {
459
        $urlRelCourse = new AccessUrlRelCourse();
460
        $urlRelCourse->setCourse($this);
461
        $urlRelCourse->setUrl($url);
462
        $this->addUrlRelCourse($urlRelCourse);
463
    }
464
465
    /**
466
     * @return ArrayCollection
467
     */
468
    public function getUsers()
469
    {
470
        return $this->users;
471
    }
472
473
    /**
474
     * @return ArrayCollection
475
     */
476
    public function getGroups()
477
    {
478
        return $this->groups;
479
    }
480
481
    /**
482
     * @return ArrayCollection
483
     */
484
    public function getTeachers()
485
    {
486
        $criteria = Criteria::create();
487
        $criteria->where(Criteria::expr()->eq('status', User::COURSE_MANAGER));
488
489
        return $this->users->matching($criteria);
490
    }
491
492
    /**
493
     * @return ArrayCollection
494
     */
495
    public function getStudents()
496
    {
497
        $criteria = Criteria::create();
498
        $criteria->where(Criteria::expr()->eq('status', User::STUDENT));
499
500
        return $this->users->matching($criteria);
501
    }
502
503
    /**
504
     * @param ArrayCollection $users
505
     */
506
    public function setUsers($users)
507
    {
508
        $this->users = new ArrayCollection();
509
510
        foreach ($users as $user) {
511
            $this->addUsers($user);
512
        }
513
    }
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
     * @return bool
526
     */
527
    public function hasUser(User $user)
528
    {
529
        $criteria = Criteria::create()->where(
530
            Criteria::expr()->eq('user', $user)
531
        );
532
533
        return $this->getUsers()->matching($criteria)->count() > 0;
534
    }
535
536
    /**
537
     * @return bool
538
     */
539
    public function hasStudent(User $user)
540
    {
541
        $criteria = Criteria::create()->where(
542
            Criteria::expr()->eq('user', $user)
543
        );
544
545
        return $this->getStudents()->matching($criteria)->count() > 0;
546
    }
547
548
    /**
549
     * @return bool
550
     */
551
    public function hasTeacher(User $user)
552
    {
553
        $criteria = Criteria::create()->where(
554
            Criteria::expr()->eq('user', $user)
555
        );
556
557
        return $this->getTeachers()->matching($criteria)->count() > 0;
558
    }
559
560
    /**
561
     * @return bool
562
     */
563
    public function hasGroup(CGroupInfo $group)
564
    {
565
        /*$criteria = Criteria::create()->where(
566
            Criteria::expr()->eq('groups', $group)
567
        );*/
568
569
        return $this->getGroups()->contains($group);
570
    }
571
572
    /**
573
     * Remove $user.
574
     */
575
    public function removeUsers(CourseRelUser $user)
576
    {
577
        foreach ($this->users as $key => $value) {
578
            if ($value->getId() == $user->getId()) {
579
                unset($this->users[$key]);
580
            }
581
        }
582
    }
583
584
    public function addTeacher(User $user)
585
    {
586
        $this->addUser($user, 0, "Trainer", User::COURSE_MANAGER);
587
    }
588
589
    public function addStudent(User $user)
590
    {
591
        $this->addUser($user, 0, "", User::STUDENT);
592
    }
593
594
    /**
595
     * Set id.
596
     *
597
     * @return int
598
     */
599
    public function setId($id)
600
    {
601
        $this->id = $id;
602
    }
603
604
    /**
605
     * Get id.
606
     *
607
     * @return int
608
     */
609
    public function getId()
610
    {
611
        return $this->id;
612
    }
613
614
    /**
615
     * Set code.
616
     *
617
     * @param string $code
618
     *
619
     * @return Course
620
     */
621
    public function setCode($code)
622
    {
623
        $this->code = $code;
624
        $this->visualCode = $code;
625
        $this->directory = $code;
626
627
        return $this;
628
    }
629
630
    /**
631
     * Get code.
632
     *
633
     * @return string
634
     */
635
    public function getCode()
636
    {
637
        return $this->code;
638
    }
639
640
    /**
641
     * Set directory.
642
     *
643
     * @param string $directory
644
     *
645
     * @return Course
646
     */
647
    public function setDirectory($directory)
648
    {
649
        $this->directory = $directory;
650
651
        return $this;
652
    }
653
654
    /**
655
     * Get directory.
656
     *
657
     * @return string
658
     */
659
    public function getDirectory()
660
    {
661
        return $this->directory;
662
    }
663
664
    /**
665
     * Set courseLanguage.
666
     *
667
     * @param string $courseLanguage
668
     *
669
     * @return Course
670
     */
671
    public function setCourseLanguage($courseLanguage)
672
    {
673
        $this->courseLanguage = $courseLanguage;
674
675
        return $this;
676
    }
677
678
    /**
679
     * Get courseLanguage.
680
     *
681
     * @return string
682
     */
683
    public function getCourseLanguage()
684
    {
685
        return $this->courseLanguage;
686
    }
687
688
    /**
689
     * Set title.
690
     *
691
     * @param string $title
692
     *
693
     * @return Course
694
     */
695
    public function setTitle($title)
696
    {
697
        $this->title = $title;
698
699
        return $this;
700
    }
701
702
    /**
703
     * Get title.
704
     *
705
     * @return string
706
     */
707
    public function getTitle()
708
    {
709
        return (string) $this->title;
710
    }
711
712
    /**
713
     * @return string
714
     */
715
    public function getTitleAndCode()
716
    {
717
        return $this->getTitle().' ('.$this->getCode().')';
718
    }
719
720
    /**
721
     * Set description.
722
     *
723
     * @param string $description
724
     *
725
     * @return Course
726
     */
727
    public function setDescription($description)
728
    {
729
        $this->description = $description;
730
731
        return $this;
732
    }
733
734
    /**
735
     * Get description.
736
     *
737
     * @return string
738
     */
739
    public function getDescription()
740
    {
741
        return $this->description;
742
    }
743
744
    /**
745
     * Set category.
746
     *
747
     * @param CourseCategory $category
748
     */
749
    public function setCategory(CourseCategory $category = null): Course
750
    {
751
        $this->category = $category;
752
753
        return $this;
754
    }
755
756
    /**
757
     * Get category.
758
     *
759
     * @return CourseCategory
760
     */
761
    public function getCategory(): ?CourseCategory
762
    {
763
        return $this->category;
764
    }
765
766
    /**
767
     * Set visibility.
768
     *
769
     * @param int $visibility
770
     *
771
     * @return Course
772
     */
773
    public function setVisibility($visibility)
774
    {
775
        $this->visibility = $visibility;
776
777
        return $this;
778
    }
779
780
    /**
781
     * Get visibility.
782
     *
783
     * @return int
784
     */
785
    public function getVisibility()
786
    {
787
        return (int) $this->visibility;
788
    }
789
790
    /**
791
     * Set showScore.
792
     *
793
     * @param int $showScore
794
     *
795
     * @return Course
796
     */
797
    public function setShowScore($showScore)
798
    {
799
        $this->showScore = $showScore;
800
801
        return $this;
802
    }
803
804
    /**
805
     * Get showScore.
806
     *
807
     * @return int
808
     */
809
    public function getShowScore()
810
    {
811
        return $this->showScore;
812
    }
813
814
    /**
815
     * Set tutorName.
816
     *
817
     * @param string $tutorName
818
     *
819
     * @return Course
820
     */
821
    public function setTutorName($tutorName)
822
    {
823
        $this->tutorName = $tutorName;
824
825
        return $this;
826
    }
827
828
    /**
829
     * Get tutorName.
830
     *
831
     * @return string
832
     */
833
    public function getTutorName()
834
    {
835
        return $this->tutorName;
836
    }
837
838
    /**
839
     * Set visualCode.
840
     *
841
     * @param string $visualCode
842
     *
843
     * @return Course
844
     */
845
    public function setVisualCode($visualCode)
846
    {
847
        $this->visualCode = $visualCode;
848
849
        return $this;
850
    }
851
852
    /**
853
     * Get visualCode.
854
     *
855
     * @return string
856
     */
857
    public function getVisualCode()
858
    {
859
        return $this->visualCode;
860
    }
861
862
    /**
863
     * Set departmentName.
864
     *
865
     * @param string $departmentName
866
     *
867
     * @return Course
868
     */
869
    public function setDepartmentName($departmentName)
870
    {
871
        $this->departmentName = $departmentName;
872
873
        return $this;
874
    }
875
876
    /**
877
     * Get departmentName.
878
     *
879
     * @return string
880
     */
881
    public function getDepartmentName()
882
    {
883
        return $this->departmentName;
884
    }
885
886
    /**
887
     * Set departmentUrl.
888
     *
889
     * @param string $departmentUrl
890
     *
891
     * @return Course
892
     */
893
    public function setDepartmentUrl($departmentUrl)
894
    {
895
        $this->departmentUrl = $departmentUrl;
896
897
        return $this;
898
    }
899
900
    /**
901
     * Get departmentUrl.
902
     *
903
     * @return string
904
     */
905
    public function getDepartmentUrl()
906
    {
907
        return $this->departmentUrl;
908
    }
909
910
    /**
911
     * Set diskQuota.
912
     *
913
     * @param int $diskQuota
914
     *
915
     * @return Course
916
     */
917
    public function setDiskQuota($diskQuota)
918
    {
919
        $this->diskQuota = intval($diskQuota);
920
921
        return $this;
922
    }
923
924
    /**
925
     * Get diskQuota.
926
     *
927
     * @return int
928
     */
929
    public function getDiskQuota()
930
    {
931
        return $this->diskQuota;
932
    }
933
934
    /**
935
     * Set lastVisit.
936
     *
937
     * @param \DateTime $lastVisit
938
     *
939
     * @return Course
940
     */
941
    public function setLastVisit($lastVisit)
942
    {
943
        $this->lastVisit = $lastVisit;
944
945
        return $this;
946
    }
947
948
    /**
949
     * Get lastVisit.
950
     *
951
     * @return \DateTime
952
     */
953
    public function getLastVisit()
954
    {
955
        return $this->lastVisit;
956
    }
957
958
    /**
959
     * Set lastEdit.
960
     *
961
     * @param \DateTime $lastEdit
962
     *
963
     * @return Course
964
     */
965
    public function setLastEdit($lastEdit)
966
    {
967
        $this->lastEdit = $lastEdit;
968
969
        return $this;
970
    }
971
972
    /**
973
     * Get lastEdit.
974
     *
975
     * @return \DateTime
976
     */
977
    public function getLastEdit()
978
    {
979
        return $this->lastEdit;
980
    }
981
982
    /**
983
     * Set creationDate.
984
     *
985
     * @param \DateTime $creationDate
986
     *
987
     * @return Course
988
     */
989
    public function setCreationDate($creationDate)
990
    {
991
        $this->creationDate = $creationDate;
992
993
        return $this;
994
    }
995
996
    /**
997
     * Get creationDate.
998
     *
999
     * @return \DateTime
1000
     */
1001
    public function getCreationDate()
1002
    {
1003
        return $this->creationDate;
1004
    }
1005
1006
    /**
1007
     * Set expirationDate.
1008
     *
1009
     * @param \DateTime $expirationDate
1010
     *
1011
     * @return Course
1012
     */
1013
    public function setExpirationDate($expirationDate)
1014
    {
1015
        $this->expirationDate = $expirationDate;
1016
1017
        return $this;
1018
    }
1019
1020
    /**
1021
     * Get expirationDate.
1022
     *
1023
     * @return \DateTime
1024
     */
1025
    public function getExpirationDate()
1026
    {
1027
        return $this->expirationDate;
1028
    }
1029
1030
    /**
1031
     * Set subscribe.
1032
     *
1033
     * @param bool $subscribe
1034
     *
1035
     * @return Course
1036
     */
1037
    public function setSubscribe($subscribe)
1038
    {
1039
        $this->subscribe = (bool) $subscribe;
1040
1041
        return $this;
1042
    }
1043
1044
    /**
1045
     * Get subscribe.
1046
     *
1047
     * @return bool
1048
     */
1049
    public function getSubscribe()
1050
    {
1051
        return $this->subscribe;
1052
    }
1053
1054
    /**
1055
     * Set unsubscribe.
1056
     *
1057
     * @param bool $unsubscribe
1058
     *
1059
     * @return Course
1060
     */
1061
    public function setUnsubscribe($unsubscribe)
1062
    {
1063
        $this->unsubscribe = (bool) $unsubscribe;
1064
1065
        return $this;
1066
    }
1067
1068
    /**
1069
     * Get unsubscribe.
1070
     *
1071
     * @return bool
1072
     */
1073
    public function getUnsubscribe()
1074
    {
1075
        return $this->unsubscribe;
1076
    }
1077
1078
    /**
1079
     * Set registrationCode.
1080
     *
1081
     * @param string $registrationCode
1082
     *
1083
     * @return Course
1084
     */
1085
    public function setRegistrationCode($registrationCode)
1086
    {
1087
        $this->registrationCode = $registrationCode;
1088
1089
        return $this;
1090
    }
1091
1092
    /**
1093
     * Get registrationCode.
1094
     *
1095
     * @return string
1096
     */
1097
    public function getRegistrationCode()
1098
    {
1099
        return $this->registrationCode;
1100
    }
1101
1102
    /**
1103
     * Set legal.
1104
     *
1105
     * @param string $legal
1106
     *
1107
     * @return Course
1108
     */
1109
    public function setLegal($legal)
1110
    {
1111
        $this->legal = $legal;
1112
1113
        return $this;
1114
    }
1115
1116
    /**
1117
     * Get legal.
1118
     *
1119
     * @return string
1120
     */
1121
    public function getLegal()
1122
    {
1123
        return $this->legal;
1124
    }
1125
1126
    /**
1127
     * Set activateLegal.
1128
     *
1129
     * @param int $activateLegal
1130
     *
1131
     * @return Course
1132
     */
1133
    public function setActivateLegal($activateLegal)
1134
    {
1135
        $this->activateLegal = $activateLegal;
1136
1137
        return $this;
1138
    }
1139
1140
    /**
1141
     * Get activateLegal.
1142
     *
1143
     * @return int
1144
     */
1145
    public function getActivateLegal()
1146
    {
1147
        return $this->activateLegal;
1148
    }
1149
1150
    /**
1151
     * @return bool
1152
     */
1153
    public function isAddTeachersToSessionsCourses()
1154
    {
1155
        return $this->addTeachersToSessionsCourses;
1156
    }
1157
1158
    /**
1159
     * @param bool $addTeachersToSessionsCourses
1160
     */
1161
    public function setAddTeachersToSessionsCourses($addTeachersToSessionsCourses): Course
1162
    {
1163
        $this->addTeachersToSessionsCourses = $addTeachersToSessionsCourses;
1164
1165
        return $this;
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
     * @return $this
1260
     */
1261
    public function setCurrentSession(Session $session)
1262
    {
1263
        // If the session is registered in the course session list.
1264
        /*if ($this->getSessions()->contains($session->getId())) {
1265
            $this->currentSession = $session;
1266
        }*/
1267
1268
        $list = $this->getSessions();
1269
        /** @var SessionRelCourse $item */
1270
        foreach ($list as $item) {
1271
            if ($item->getSession()->getId() == $session->getId()) {
1272
                $this->currentSession = $session;
1273
                break;
1274
            }
1275
        }
1276
1277
        return $this;
1278
    }
1279
1280
    /**
1281
     * @return $this
1282
     */
1283
    public function setCurrentUrl(AccessUrl $url)
1284
    {
1285
        $urlList = $this->getUrls();
1286
        /** @var AccessUrlRelCourse $item */
1287
        foreach ($urlList as $item) {
1288
            if ($item->getUrl()->getId() == $url->getId()) {
1289
                $this->currentUrl = $url;
1290
                break;
1291
            }
1292
        }
1293
1294
        return $this;
1295
    }
1296
1297
    /**
1298
     * @return AccessUrl
1299
     */
1300
    public function getCurrentUrl()
1301
    {
1302
        return $this->currentUrl;
1303
    }
1304
1305
    /**
1306
     * Get issuedSkills.
1307
     *
1308
     * @return ArrayCollection
1309
     */
1310
    public function getIssuedSkills()
1311
    {
1312
        return $this->issuedSkills;
1313
    }
1314
1315
    /**
1316
     * @return bool
1317
     */
1318
    public function hasSubscription(CourseRelUser $subscription)
1319
    {
1320
        if ($this->getUsers()->count()) {
1321
            $criteria = Criteria::create()->where(
1322
                Criteria::expr()->eq('user', $subscription->getUser())
1323
            )->andWhere(
1324
                Criteria::expr()->eq('status', $subscription->getStatus())
1325
            )->andWhere(
1326
                Criteria::expr()->eq('relationType', $subscription->getRelationType())
1327
            );
1328
1329
            $relation = $this->getUsers()->matching($criteria);
1330
1331
            return $relation->count() > 0;
1332
        }
1333
1334
        return false;
1335
    }
1336
1337
    /**
1338
     * @param string $relationType
1339
     * @param string $role
1340
     * @param string $status
1341
     */
1342
    public function addUser(User $user, $relationType, $role, $status)
1343
    {
1344
        $courseRelUser = new CourseRelUser();
1345
        $courseRelUser->setCourse($this);
1346
        $courseRelUser->setUser($user);
1347
        $courseRelUser->setRelationType($relationType);
1348
        $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

1348
        $courseRelUser->/** @scrutinizer ignore-call */ 
1349
                        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...
1349
        $courseRelUser->setStatus($status);
1350
        $this->addUsers($courseRelUser);
1351
    }
1352
1353
    /**
1354
     * Resource identifier.
1355
     */
1356
    public function getResourceIdentifier(): int
1357
    {
1358
        return $this->getId();
1359
    }
1360
1361
    public function getResourceName(): string
1362
    {
1363
        return $this->getCode();
1364
    }
1365
1366
    public function getResourceFieldName(): string
1367
    {
1368
        return 'code';
1369
    }
1370
}
1371