Passed
Push — master ( fabd80...b89051 )
by Yannick
06:43
created

Course::getName()   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
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Entity;
8
9
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
10
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
11
use ApiPlatform\Metadata\ApiFilter;
12
use ApiPlatform\Metadata\ApiProperty;
13
use ApiPlatform\Metadata\ApiResource;
14
use ApiPlatform\Metadata\Get;
15
use ApiPlatform\Metadata\GetCollection;
16
use ApiPlatform\Metadata\Post;
17
use Chamilo\CoreBundle\Entity\Listener\CourseListener;
18
use Chamilo\CoreBundle\Entity\Listener\ResourceListener;
19
use Chamilo\CoreBundle\Repository\Node\CourseRepository;
20
use Chamilo\CourseBundle\Entity\CGroup;
21
use Chamilo\CourseBundle\Entity\CTool;
22
use DateTime;
23
use Doctrine\Common\Collections\ArrayCollection;
24
use Doctrine\Common\Collections\Collection;
25
use Doctrine\Common\Collections\Criteria;
26
use Doctrine\ORM\Mapping as ORM;
27
use Gedmo\Mapping\Annotation as Gedmo;
28
use Stringable;
29
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
30
use Symfony\Component\Serializer\Annotation\Groups;
31
use Symfony\Component\Validator\Constraints as Assert;
32
33
#[ApiResource(
34
    types: ['https://schema.org/Course'],
35
    operations: [
36
        new Get(security: "is_granted('VIEW', object)"),
37
        new Post(),
38
        new GetCollection(),
39
    ],
40
    normalizationContext: [
41
        'groups' => ['course:read'],
42
    ],
43
    denormalizationContext: [
44
        'groups' => ['course:write'],
45
    ],
46
    filters: [
47
        'course.sticky_boolean_filter',
48
    ],
49
    security: "is_granted('ROLE_USER')"
50
)]
51
#[ORM\Table(name: 'course')]
52
#[UniqueEntity('code')]
53
#[UniqueEntity('visualCode')]
54
#[ORM\Entity(repositoryClass: CourseRepository::class)]
55
#[ORM\EntityListeners([ResourceListener::class, CourseListener::class])]
56
#[ApiFilter(filterClass: SearchFilter::class, properties: ['title' => 'partial', 'code' => 'partial'])]
57
#[ApiFilter(filterClass: OrderFilter::class, properties: ['id', 'title'])]
58
class Course extends AbstractResource implements ResourceInterface, ResourceWithAccessUrlInterface, ResourceIllustrationInterface, ExtraFieldItemInterface, Stringable
59
{
60
    public const CLOSED = 0;
61
    public const REGISTERED = 1;
62
    // Only registered users in the course.
63
    public const OPEN_PLATFORM = 2;
64
    // All users registered in the platform (default).
65
    public const OPEN_WORLD = 3;
66
    public const HIDDEN = 4;
67
68
    #[Groups([
69
        'course:read',
70
        'course_rel_user:read',
71
        'session:read',
72
        'session_rel_course_rel_user:read',
73
        'session_rel_user:read',
74
        'session_rel_course:read',
75
        'track_e_exercise:read',
76
    ])]
77
    #[ORM\Column(name: 'id', type: 'integer')]
78
    #[ORM\Id]
79
    #[ORM\GeneratedValue(strategy: 'AUTO')]
80
    protected ?int $id = null;
81
82
    /**
83
     * The course title.
84
     */
85
    #[Groups([
86
        'course:read',
87
        'course:write',
88
        'course_rel_user:read',
89
        'session:read',
90
        'session_rel_course_rel_user:read',
91
        'session_rel_user:read',
92
        'session_rel_course:read',
93
        'track_e_exercise:read',
94
    ])]
95
    #[Assert\NotBlank(message: 'A Course requires a title')]
96
    #[ORM\Column(name: 'title', type: 'string', length: 250, unique: false, nullable: true)]
97
    protected ?string $title = null;
98
99
    /**
100
     * The course code.
101
     */
102
    #[ApiProperty(iris: ['http://schema.org/courseCode'])]
103
    #[Groups(['course:read', 'user:write', 'course_rel_user:read'])]
104
    #[Assert\NotBlank]
105
    #[Assert\Length(max: 40, maxMessage: 'Code cannot be longer than {{ limit }} characters')]
106
    #[Gedmo\Slug(fields: ['title'], updatable: false, style: 'upper', unique: true, separator: '')]
107
    #[ORM\Column(name: 'code', type: 'string', length: 40, unique: true, nullable: false)]
108
    protected string $code;
109
110
    #[Assert\Length(max: 40, maxMessage: 'Code cannot be longer than {{ limit }} characters')]
111
    #[ORM\Column(name: 'visual_code', type: 'string', length: 40, unique: false, nullable: true)]
112
    protected ?string $visualCode = null;
113
114
    /**
115
     * @var Collection<int, CourseRelUser>
116
     */
117
    #[Groups([
118
        'course:read',
119
        'user:read',
120
        'course_rel_user:read',
121
    ])]
122
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: CourseRelUser::class, cascade: ['persist'], orphanRemoval: true)]
123
    protected Collection $users;
124
125
    /**
126
     * @var Collection<int, EntityAccessUrlInterface>
127
     */
128
    #[ORM\OneToMany(
129
        mappedBy: 'course',
130
        targetEntity: AccessUrlRelCourse::class,
131
        cascade: ['persist', 'remove'],
132
        orphanRemoval: true
133
    )]
134
    protected Collection $urls;
135
136
    /**
137
     * @var Collection<int, SessionRelCourse>
138
     */
139
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: SessionRelCourse::class, cascade: ['persist', 'remove'])]
140
    protected Collection $sessions;
141
142
    /**
143
     * @var Collection<int, SessionRelCourseRelUser>
144
     */
145
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: SessionRelCourseRelUser::class, cascade: [
146
        'persist',
147
        'remove',
148
    ])]
149
    protected Collection $sessionRelCourseRelUsers;
150
151
    /**
152
     * @var Collection<int, CTool>
153
     */
154
    #[ORM\OneToMany(
155
        mappedBy: 'course',
156
        targetEntity: CTool::class,
157
        cascade: [
158
            'persist',
159
            'remove',
160
        ],
161
        orphanRemoval: true
162
    )]
163
    protected Collection $tools;
164
165
    #[Groups(['course:read'])]
166
    #[ORM\OneToOne(
167
        mappedBy: 'course',
168
        targetEntity: TrackCourseRanking::class,
169
        cascade: [
170
            'persist',
171
            'remove',
172
        ],
173
        orphanRemoval: true
174
    )]
175
    protected ?TrackCourseRanking $trackCourseRanking = null;
176
177
    protected Session $currentSession;
178
179
    protected AccessUrl $currentUrl;
180
181
    /**
182
     * @var Collection<int, SkillRelCourse>
183
     */
184
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: SkillRelCourse::class, cascade: ['persist', 'remove'])]
185
    protected Collection $skills;
186
187
    /**
188
     * @var Collection<int, SkillRelUser>
189
     */
190
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: SkillRelUser::class, cascade: ['persist', 'remove'])]
191
    protected Collection $issuedSkills;
192
193
    /**
194
     * @var Collection<int, GradebookCategory>
195
     */
196
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: GradebookCategory::class, cascade: ['persist', 'remove'])]
197
    protected Collection $gradebookCategories;
198
199
    /**
200
     * @var Collection<int, GradebookEvaluation>
201
     */
202
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: GradebookEvaluation::class, cascade: ['persist', 'remove'])]
203
    protected Collection $gradebookEvaluations;
204
205
    /**
206
     * @var Collection<int, GradebookLink>
207
     */
208
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: GradebookLink::class, cascade: ['persist', 'remove'])]
209
    protected Collection $gradebookLinks;
210
211
    /**
212
     * @var Collection<int, TrackEHotspot>
213
     */
214
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: TrackEHotspot::class, cascade: ['persist', 'remove'])]
215
    protected Collection $trackEHotspots;
216
217
    /**
218
     * @var Collection<int, SearchEngineRef>
219
     */
220
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: SearchEngineRef::class, cascade: ['persist', 'remove'])]
221
    protected Collection $searchEngineRefs;
222
223
    /**
224
     * @var Collection<int, Templates>
225
     */
226
    #[ORM\OneToMany(mappedBy: 'course', targetEntity: Templates::class, cascade: ['persist', 'remove'])]
227
    protected Collection $templates;
228
229
    /**
230
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course").
231
     */
232
    // protected $specificFieldValues;
233
234
    /**
235
     * ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course").
236
     */
237
    // protected $sharedSurveys;
238
239
    #[ORM\Column(name: 'directory', type: 'string', length: 40, unique: false, nullable: true)]
240
    protected ?string $directory = null;
241
242
    #[Groups(['course:read', 'session:read'])]
243
    #[Assert\NotBlank]
244
    #[ORM\Column(name: 'course_language', type: 'string', length: 20, unique: false, nullable: false)]
245
    protected string $courseLanguage;
246
247
    #[Groups(['course:read', 'course_rel_user:read'])]
248
    #[ORM\Column(name: 'description', type: 'text', unique: false, nullable: true)]
249
    protected ?string $description;
250
251
    #[Groups(['course:read', 'course_rel_user:read'])]
252
    #[ORM\Column(name: 'introduction', type: 'text', nullable: true)]
253
    protected ?string $introduction;
254
255
    /**
256
     * @var Collection<int, CourseCategory>
257
     */
258
    #[Groups(['course:read', 'course:write', 'course_rel_user:read', 'session:read'])]
259
    #[ORM\JoinTable(name: 'course_rel_category')]
260
    #[ORM\JoinColumn(name: 'course_id', referencedColumnName: 'id')]
261
    #[ORM\InverseJoinColumn(name: 'course_category_id', referencedColumnName: 'id')]
262
    #[ORM\ManyToMany(targetEntity: CourseCategory::class, inversedBy: 'courses')]
263
    protected Collection $categories;
264
265
    #[Assert\NotBlank]
266
    #[Groups(['course:read', 'course:write'])]
267
    #[ORM\Column(name: 'visibility', type: 'integer', unique: false, nullable: false)]
268
    protected int $visibility;
269
270
    #[ORM\Column(name: 'show_score', type: 'integer', unique: false, nullable: true)]
271
    protected ?int $showScore = null;
272
273
    #[ORM\Column(name: 'tutor_name', type: 'string', length: 200, unique: false, nullable: true)]
274
    protected ?string $tutorName;
275
276
    #[Groups(['course:read'])]
277
    #[ORM\Column(name: 'department_name', type: 'string', length: 30, unique: false, nullable: true)]
278
    protected ?string $departmentName = null;
279
280
    #[Assert\Url]
281
    #[Groups(['course:read', 'course:write'])]
282
    #[ORM\Column(name: 'department_url', type: 'string', length: 180, unique: false, nullable: true)]
283
    protected ?string $departmentUrl = null;
284
285
    #[Assert\Url]
286
    #[Groups(['course:read', 'course:write'])]
287
    #[ORM\Column(name: 'video_url', type: 'string', length: 255)]
288
    protected string $videoUrl;
289
290
    #[Groups(['course:read', 'course:write'])]
291
    #[ORM\Column(name: 'sticky', type: 'boolean')]
292
    protected bool $sticky;
293
294
    #[ORM\Column(name: 'disk_quota', type: 'integer', unique: false, nullable: true)]
295
    protected ?int $diskQuota = null;
296
297
    #[ORM\Column(name: 'last_visit', type: 'datetime', unique: false, nullable: true)]
298
    protected ?DateTime $lastVisit;
299
300
    #[ORM\Column(name: 'last_edit', type: 'datetime', unique: false, nullable: true)]
301
    protected ?DateTime $lastEdit;
302
303
    #[ORM\Column(name: 'creation_date', type: 'datetime', unique: false, nullable: false)]
304
    protected DateTime $creationDate;
305
306
    #[Groups(['course:read'])]
307
    #[ORM\Column(name: 'expiration_date', type: 'datetime', unique: false, nullable: true)]
308
    protected ?DateTime $expirationDate = null;
309
310
    #[Assert\NotNull]
311
    #[ORM\Column(name: 'subscribe', type: 'boolean', unique: false, nullable: false)]
312
    protected bool $subscribe;
313
314
    #[Assert\NotNull]
315
    #[ORM\Column(name: 'unsubscribe', type: 'boolean', unique: false, nullable: false)]
316
    protected bool $unsubscribe;
317
318
    #[ORM\Column(name: 'registration_code', type: 'string', length: 255, unique: false, nullable: true)]
319
    protected ?string $registrationCode;
320
321
    #[ORM\Column(name: 'legal', type: 'text', unique: false, nullable: true)]
322
    protected ?string $legal;
323
324
    #[ORM\Column(name: 'activate_legal', type: 'integer', unique: false, nullable: true)]
325
    protected ?int $activateLegal;
326
327
    #[ORM\Column(name: 'add_teachers_to_sessions_courses', type: 'boolean', nullable: true)]
328
    protected ?bool $addTeachersToSessionsCourses;
329
330
    #[ORM\Column(name: 'course_type_id', type: 'integer', unique: false, nullable: true)]
331
    protected ?int $courseTypeId;
332
333
    /**
334
     * ORM\OneToMany(targetEntity="CurriculumCategory", mappedBy="course").
335
     */
336
    // protected $curriculumCategories;
337
338
    #[ORM\ManyToOne(targetEntity: Room::class)]
339
    #[ORM\JoinColumn(name: 'room_id', referencedColumnName: 'id')]
340
    protected ?Room $room;
341
342
    public function __construct()
343
    {
344
        $this->visibility = self::OPEN_PLATFORM;
345
        $this->sessions = new ArrayCollection();
346
        $this->sessionRelCourseRelUsers = new ArrayCollection();
347
        $this->skills = new ArrayCollection();
348
        $this->issuedSkills = new ArrayCollection();
349
        $this->creationDate = new DateTime();
350
        $this->lastVisit = new DateTime();
351
        $this->lastEdit = new DateTime();
352
        $this->description = '';
353
        $this->introduction = '';
354
        $this->tutorName = '';
355
        $this->legal = '';
356
        $this->videoUrl = '';
357
        $this->registrationCode = null;
358
        $this->users = new ArrayCollection();
359
        $this->urls = new ArrayCollection();
360
        $this->tools = new ArrayCollection();
361
        $this->categories = new ArrayCollection();
362
        $this->gradebookCategories = new ArrayCollection();
363
        $this->gradebookEvaluations = new ArrayCollection();
364
        $this->gradebookLinks = new ArrayCollection();
365
        $this->trackEHotspots = new ArrayCollection();
366
        $this->searchEngineRefs = new ArrayCollection();
367
        $this->templates = new ArrayCollection();
368
        $this->activateLegal = 0;
369
        $this->addTeachersToSessionsCourses = false;
370
        $this->courseTypeId = null;
371
        $this->room = null;
372
        $this->courseLanguage = 'en';
373
        $this->subscribe = true;
374
        $this->unsubscribe = false;
375
        $this->sticky = false;
376
        // $this->specificFieldValues = new ArrayCollection();
377
        // $this->sharedSurveys = new ArrayCollection();
378
    }
379
380
    public function __toString(): string
381
    {
382
        return $this->getTitle();
383
    }
384
385
    public static function getStatusList(): array
386
    {
387
        return [
388
            self::CLOSED => 'Closed',
389
            self::REGISTERED => 'Registered',
390
            self::OPEN_PLATFORM => 'Open platform',
391
            self::OPEN_WORLD => 'Open world',
392
            self::HIDDEN => 'Hidden',
393
        ];
394
    }
395
396
    public function getTitle(): string
397
    {
398
        return $this->title;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->title could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
399
    }
400
401
    public function setTitle(string $title): self
402
    {
403
        $this->title = $title;
404
        // Set the code based in the title if it doesnt exists.
405
        if (empty($this->code)) {
406
            $this->setCode($title);
407
        }
408
409
        return $this;
410
    }
411
412
    /**
413
     * @return Collection<int, CTool>
414
     */
415
    public function getTools(): Collection
416
    {
417
        return $this->tools;
418
    }
419
420
    public function setTools(array $tools): self
421
    {
422
        foreach ($tools as $tool) {
423
            $this->addTool($tool);
424
        }
425
426
        return $this;
427
    }
428
429
    public function addTool(CTool $tool): self
430
    {
431
        $tool->setCourse($this);
432
        $this->tools->add($tool);
433
434
        return $this;
435
    }
436
437
    public function getTrackCourseRanking(): ?TrackCourseRanking
438
    {
439
        return $this->trackCourseRanking;
440
    }
441
442
    public function setTrackCourseRanking(?TrackCourseRanking $trackCourseRanking): self
443
    {
444
        $this->trackCourseRanking = $trackCourseRanking;
445
446
        return $this;
447
    }
448
449
    public function hasSubscriptionByUser(User $user): bool
450
    {
451
        $users = $this->getUsers();
452
453
        if (0 === $users->count()) {
454
            return false;
455
        }
456
457
        $matching = $users->filter(
458
            fn (CourseRelUser $subscription) => $subscription->getUser()->getId() === $user->getId()
459
        );
460
461
        return $matching->count() > 0;
462
    }
463
464
    /**
465
     * @return Collection<int, CourseRelUser>
466
     */
467
    public function getUsers(): Collection
468
    {
469
        return $this->users;
470
    }
471
472
    public function addSubscription(CourseRelUser $courseRelUser): self
473
    {
474
        $courseRelUser->setCourse($this);
475
        if (!$this->hasUsers($courseRelUser)) {
476
            $this->users->add($courseRelUser);
477
        }
478
479
        return $this;
480
    }
481
482
    public function removeSubscription(CourseRelUser $user): void
483
    {
484
        foreach ($this->users as $key => $value) {
485
            if ($value->getId() === $user->getId()) {
486
                unset($this->users[$key]);
487
            }
488
        }
489
    }
490
491
    public function hasUsers(CourseRelUser $subscription): bool
492
    {
493
        if (0 !== $this->users->count()) {
494
            $criteria = Criteria::create()
495
                ->where(
496
                    Criteria::expr()->eq('user', $subscription->getUser())
497
                )
498
                ->andWhere(
499
                    Criteria::expr()->eq('status', $subscription->getStatus())
500
                )
501
                ->andWhere(
502
                    Criteria::expr()->eq('relationType', $subscription->getRelationType())
503
                )
504
            ;
505
            $relation = $this->users->matching($criteria);
506
507
            return $relation->count() > 0;
508
        }
509
510
        return false;
511
    }
512
513
    public function addSubscriptionForUser(User $user, int $relationType, ?string $role, int $status): self
514
    {
515
        $courseRelUser = (new CourseRelUser())
516
            ->setCourse($this)
517
            ->setUser($user)
518
            ->setRelationType($relationType)
519
            ->setStatus($status)
520
        ;
521
        $this->addSubscription($courseRelUser);
522
523
        return $this;
524
    }
525
526
    public function hasUserAsStudent(User $user): bool
527
    {
528
        $criteria = Criteria::create()->where(Criteria::expr()->eq('user', $user));
529
530
        return $this->getStudentSubscriptions()->matching($criteria)->count() > 0;
531
    }
532
533
    public function getStudentSubscriptions(): Collection
534
    {
535
        $criteria = Criteria::create();
536
        $criteria->where(Criteria::expr()->eq('status', CourseRelUser::STUDENT));
537
538
        return $this->users->matching($criteria);
539
    }
540
541
    public function addUserAsStudent(User $user): self
542
    {
543
        $this->addSubscriptionForUser($user, 0, '', CourseRelUser::STUDENT);
544
545
        return $this;
546
    }
547
548
    public function hasUserAsTeacher(User $user): bool
549
    {
550
        $users = $this->getTeachersSubscriptions();
551
552
        if (0 === $users->count()) {
553
            return false;
554
        }
555
556
        $matching = $users->filter(
557
            fn (CourseRelUser $subscription) => $subscription->getUser()->getId() === $user->getId()
558
        );
559
560
        return $matching->count() > 0;
561
    }
562
563
    public function getTeachersSubscriptions(): Collection
564
    {
565
        $teacherSubscriptions = new ArrayCollection();
566
567
        foreach ($this->users as $subscription) {
568
            if (CourseRelUser::TEACHER === $subscription->getStatus()) {
569
                $teacherSubscriptions->add($subscription);
570
            }
571
        }
572
573
        return $teacherSubscriptions;
574
    }
575
576
    public function addUserAsTeacher(User $user): self
577
    {
578
        $this->addSubscriptionForUser($user, 0, 'Trainer', CourseRelUser::TEACHER);
579
580
        return $this;
581
    }
582
583
    public function hasGroup(CGroup $group): void
584
    {
585
        /*$criteria = Criteria::create()->where(
586
              Criteria::expr()->eq('groups', $group)
587
          );*/
588
        // return $this->getGroups()->contains($group);
589
    }
590
591
    public function getId(): ?int
592
    {
593
        return $this->id;
594
    }
595
596
    /**
597
     * Get directory, needed in migrations.
598
     */
599
    public function getDirectory(): ?string
600
    {
601
        return $this->directory;
602
    }
603
604
    public function getCourseLanguage(): string
605
    {
606
        return $this->courseLanguage;
607
    }
608
609
    public function setCourseLanguage(string $courseLanguage): self
610
    {
611
        $this->courseLanguage = $courseLanguage;
612
613
        return $this;
614
    }
615
616
    public function getTitleAndCode(): string
617
    {
618
        return $this->getTitle().' ('.$this->getCode().')';
619
    }
620
621
    public function getCode(): string
622
    {
623
        return $this->code;
624
    }
625
626
    public function setCode(string $code): self
627
    {
628
        $this->code = $code;
629
        $this->visualCode = $code;
630
631
        return $this;
632
    }
633
634
    public function getDescription(): ?string
635
    {
636
        return $this->description;
637
    }
638
639
    public function setDescription(string $description): self
640
    {
641
        $this->description = $description;
642
643
        return $this;
644
    }
645
646
    /**
647
     * @return Collection<int, CourseCategory>
648
     */
649
    public function getCategories(): Collection
650
    {
651
        return $this->categories;
652
    }
653
654
    public function setCategories(Collection $categories): self
655
    {
656
        $this->categories = $categories;
657
658
        return $this;
659
    }
660
661
    public function addCategory(CourseCategory $category): self
662
    {
663
        $this->categories[] = $category;
664
665
        return $this;
666
    }
667
668
    public function removeCategory(CourseCategory $category): void
669
    {
670
        $this->categories->removeElement($category);
671
    }
672
673
    public function getVisibility(): int
674
    {
675
        return $this->visibility;
676
    }
677
678
    public function setVisibility(int $visibility): self
679
    {
680
        $this->visibility = $visibility;
681
682
        return $this;
683
    }
684
685
    public function getShowScore(): ?int
686
    {
687
        return $this->showScore;
688
    }
689
690
    public function setShowScore(int $showScore): self
691
    {
692
        $this->showScore = $showScore;
693
694
        return $this;
695
    }
696
697
    public function getTutorName(): ?string
698
    {
699
        return $this->tutorName;
700
    }
701
702
    public function setTutorName(?string $tutorName): self
703
    {
704
        $this->tutorName = $tutorName;
705
706
        return $this;
707
    }
708
709
    public function getVisualCode(): ?string
710
    {
711
        return $this->visualCode;
712
    }
713
714
    public function setVisualCode(string $visualCode): self
715
    {
716
        $this->visualCode = $visualCode;
717
718
        return $this;
719
    }
720
721
    public function getDepartmentName(): ?string
722
    {
723
        return $this->departmentName;
724
    }
725
726
    public function setDepartmentName(string $departmentName): self
727
    {
728
        $this->departmentName = $departmentName;
729
730
        return $this;
731
    }
732
733
    public function getDepartmentUrl(): ?string
734
    {
735
        return $this->departmentUrl;
736
    }
737
738
    public function setDepartmentUrl(string $departmentUrl): self
739
    {
740
        $this->departmentUrl = $departmentUrl;
741
742
        return $this;
743
    }
744
745
    public function getDiskQuota(): ?int
746
    {
747
        return $this->diskQuota;
748
    }
749
750
    public function setDiskQuota(int $diskQuota): self
751
    {
752
        $this->diskQuota = $diskQuota;
753
754
        return $this;
755
    }
756
757
    public function getLastVisit(): ?DateTime
758
    {
759
        return $this->lastVisit;
760
    }
761
762
    public function setLastVisit(DateTime $lastVisit): self
763
    {
764
        $this->lastVisit = $lastVisit;
765
766
        return $this;
767
    }
768
769
    public function getLastEdit(): ?DateTime
770
    {
771
        return $this->lastEdit;
772
    }
773
774
    public function setLastEdit(DateTime $lastEdit): self
775
    {
776
        $this->lastEdit = $lastEdit;
777
778
        return $this;
779
    }
780
781
    public function getCreationDate(): DateTime
782
    {
783
        return $this->creationDate;
784
    }
785
786
    public function setCreationDate(DateTime $creationDate): self
787
    {
788
        $this->creationDate = $creationDate;
789
790
        return $this;
791
    }
792
793
    public function getExpirationDate(): ?DateTime
794
    {
795
        return $this->expirationDate;
796
    }
797
798
    public function setExpirationDate(DateTime $expirationDate): self
799
    {
800
        $this->expirationDate = $expirationDate;
801
802
        return $this;
803
    }
804
805
    public function getSubscribe(): bool
806
    {
807
        return $this->subscribe;
808
    }
809
810
    public function setSubscribe(bool $subscribe): self
811
    {
812
        $this->subscribe = $subscribe;
813
814
        return $this;
815
    }
816
817
    public function getUnsubscribe(): bool
818
    {
819
        return $this->unsubscribe;
820
    }
821
822
    public function setUnsubscribe(bool $unsubscribe): self
823
    {
824
        $this->unsubscribe = $unsubscribe;
825
826
        return $this;
827
    }
828
829
    public function getRegistrationCode(): ?string
830
    {
831
        return $this->registrationCode;
832
    }
833
834
    public function setRegistrationCode(string $registrationCode): self
835
    {
836
        $this->registrationCode = $registrationCode;
837
838
        return $this;
839
    }
840
841
    public function getLegal(): ?string
842
    {
843
        return $this->legal;
844
    }
845
846
    public function setLegal(string $legal): self
847
    {
848
        $this->legal = $legal;
849
850
        return $this;
851
    }
852
853
    public function getActivateLegal(): ?int
854
    {
855
        return $this->activateLegal;
856
    }
857
858
    public function setActivateLegal(int $activateLegal): self
859
    {
860
        $this->activateLegal = $activateLegal;
861
862
        return $this;
863
    }
864
865
    public function isAddTeachersToSessionsCourses(): ?bool
866
    {
867
        return $this->addTeachersToSessionsCourses;
868
    }
869
870
    public function setAddTeachersToSessionsCourses(bool $addTeachersToSessionsCourses): self
871
    {
872
        $this->addTeachersToSessionsCourses = $addTeachersToSessionsCourses;
873
874
        return $this;
875
    }
876
877
    public function getCourseTypeId(): ?int
878
    {
879
        return $this->courseTypeId;
880
    }
881
882
    public function setCourseTypeId(int $courseTypeId): self
883
    {
884
        $this->courseTypeId = $courseTypeId;
885
886
        return $this;
887
    }
888
889
    public function getRoom(): ?Room
890
    {
891
        return $this->room;
892
    }
893
894
    public function setRoom(Room $room): self
895
    {
896
        $this->room = $room;
897
898
        return $this;
899
    }
900
901
    public function isActive(): bool
902
    {
903
        $activeVisibilityList = [self::REGISTERED, self::OPEN_PLATFORM, self::OPEN_WORLD];
904
905
        return \in_array($this->visibility, $activeVisibilityList, true);
906
    }
907
908
    /**
909
     * Anybody can see this course.
910
     */
911
    public function isPublic(): bool
912
    {
913
        return self::OPEN_WORLD === $this->visibility;
914
    }
915
916
    public function isHidden(): bool
917
    {
918
        return self::HIDDEN === $this->visibility;
919
    }
920
921
    public function getCurrentSession(): Session
922
    {
923
        return $this->currentSession;
924
    }
925
926
    public function setCurrentSession(Session $session): self
927
    {
928
        // If the session is registered in the course session list.
929
        /*if ($this->getSessions()->contains($session->getId())) {
930
              $this->currentSession = $session;
931
          }*/
932
        $list = $this->getSessions();
933
934
        /** @var SessionRelCourse $item */
935
        foreach ($list as $item) {
936
            if ($item->getSession()->getId() === $session->getId()) {
937
                $this->currentSession = $session;
938
939
                break;
940
            }
941
        }
942
943
        return $this;
944
    }
945
946
    /**
947
     * @return Collection<int, SessionRelCourse>
948
     */
949
    public function getSessions(): Collection
950
    {
951
        return $this->sessions;
952
    }
953
954
    public function getCurrentUrl(): AccessUrl
955
    {
956
        return $this->currentUrl;
957
    }
958
959
    public function setCurrentUrl(AccessUrl $url): self
960
    {
961
        $urlList = $this->getUrls();
962
963
        /** @var AccessUrlRelCourse $item */
964
        foreach ($urlList as $item) {
965
            if ($item->getUrl()->getId() === $url->getId()) {
966
                $this->currentUrl = $url;
967
968
                break;
969
            }
970
        }
971
972
        return $this;
973
    }
974
975
    public function getUrls(): Collection
976
    {
977
        return $this->urls;
978
    }
979
980
    public function addUrls(AccessUrlRelCourse $urlRelCourse): static
981
    {
982
        $urlRelCourse->setCourse($this);
983
984
        $this->urls->add($urlRelCourse);
985
986
        return $this;
987
    }
988
989
    public function addAccessUrl(?AccessUrl $url): self
990
    {
991
        $urlRelCourse = (new AccessUrlRelCourse())->setCourse($this)->setUrl($url);
992
        $this->addUrls($urlRelCourse);
993
994
        return $this;
995
    }
996
997
    public function addUrlRelCourse(AccessUrlRelCourse $accessUrlRelCourse): self
998
    {
999
        $accessUrlRelCourse->setCourse($this);
1000
        $this->urls->add($accessUrlRelCourse);
1001
1002
        return $this;
1003
    }
1004
1005
    /**
1006
     * @return Collection<int, SkillRelUser>
1007
     */
1008
    public function getIssuedSkills(): Collection
1009
    {
1010
        return $this->issuedSkills;
1011
    }
1012
1013
    /**
1014
     * @return Collection<int, SessionRelCourseRelUser>
1015
     */
1016
    public function getSessionRelCourseRelUsers(): Collection
1017
    {
1018
        return $this->sessionRelCourseRelUsers;
1019
    }
1020
1021
    public function setSessionRelCourseRelUsers(Collection $sessionUserSubscriptions): self
1022
    {
1023
        $this->sessionRelCourseRelUsers = $sessionUserSubscriptions;
1024
1025
        return $this;
1026
    }
1027
1028
    /**
1029
     * @return Collection<int, SkillRelCourse>
1030
     */
1031
    public function getSkills(): Collection
1032
    {
1033
        return $this->skills;
1034
    }
1035
1036
    public function setSkills(Collection $skills): self
1037
    {
1038
        $this->skills = $skills;
1039
1040
        return $this;
1041
    }
1042
1043
    /**
1044
     * @return Collection<int, GradebookCategory>
1045
     */
1046
    public function getGradebookCategories(): Collection
1047
    {
1048
        return $this->gradebookCategories;
1049
    }
1050
1051
    public function setGradebookCategories(Collection $gradebookCategories): self
1052
    {
1053
        $this->gradebookCategories = $gradebookCategories;
1054
1055
        return $this;
1056
    }
1057
1058
    /**
1059
     * @return Collection<int, GradebookEvaluation>
1060
     */
1061
    public function getGradebookEvaluations(): Collection
1062
    {
1063
        return $this->gradebookEvaluations;
1064
    }
1065
1066
    public function setGradebookEvaluations(Collection $gradebookEvaluations): self
1067
    {
1068
        $this->gradebookEvaluations = $gradebookEvaluations;
1069
1070
        return $this;
1071
    }
1072
1073
    /**
1074
     * @return Collection<int, GradebookLink>
1075
     */
1076
    public function getGradebookLinks(): Collection
1077
    {
1078
        return $this->gradebookLinks;
1079
    }
1080
1081
    public function setGradebookLinks(Collection $gradebookLinks): self
1082
    {
1083
        $this->gradebookLinks = $gradebookLinks;
1084
1085
        return $this;
1086
    }
1087
1088
    /**
1089
     * @return Collection<int, TrackEHotspot>
1090
     */
1091
    public function getTrackEHotspots(): Collection
1092
    {
1093
        return $this->trackEHotspots;
1094
    }
1095
1096
    public function setTrackEHotspots(Collection $trackEHotspots): self
1097
    {
1098
        $this->trackEHotspots = $trackEHotspots;
1099
1100
        return $this;
1101
    }
1102
1103
    /**
1104
     * @return Collection<int, SearchEngineRef>
1105
     */
1106
    public function getSearchEngineRefs(): Collection
1107
    {
1108
        return $this->searchEngineRefs;
1109
    }
1110
1111
    public function setSearchEngineRefs(Collection $searchEngineRefs): self
1112
    {
1113
        $this->searchEngineRefs = $searchEngineRefs;
1114
1115
        return $this;
1116
    }
1117
1118
    public function getIntroduction(): ?string
1119
    {
1120
        return $this->introduction;
1121
    }
1122
1123
    public function setIntroduction(?string $introduction): self
1124
    {
1125
        $this->introduction = $introduction;
1126
1127
        return $this;
1128
    }
1129
1130
    /**
1131
     * @return Collection<int, Templates>
1132
     */
1133
    public function getTemplates(): Collection
1134
    {
1135
        return $this->templates;
1136
    }
1137
1138
    public function setTemplates(Collection $templates): self
1139
    {
1140
        $this->templates = $templates;
1141
1142
        return $this;
1143
    }
1144
1145
    public function getVideoUrl(): string
1146
    {
1147
        return $this->videoUrl;
1148
    }
1149
1150
    public function setVideoUrl(string $videoUrl): self
1151
    {
1152
        $this->videoUrl = $videoUrl;
1153
1154
        return $this;
1155
    }
1156
1157
    public function isSticky(): bool
1158
    {
1159
        return $this->sticky;
1160
    }
1161
1162
    public function setSticky(bool $sticky): self
1163
    {
1164
        $this->sticky = $sticky;
1165
1166
        return $this;
1167
    }
1168
1169
    public function getDefaultIllustration(int $size): string
1170
    {
1171
        return '/img/session_default.svg';
1172
    }
1173
1174
    public function getResourceIdentifier(): int
1175
    {
1176
        return $this->getId();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getId() could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
1177
    }
1178
1179
    public function getResourceName(): string
1180
    {
1181
        return $this->getCode();
1182
    }
1183
1184
    public function setResourceName(string $name): self
1185
    {
1186
        return $this->setCode($name);
1187
    }
1188
}
1189