Passed
Push — master ( 719760...59ab2e )
by Angel Fernando Quiroz
18:35
created

Course::hasSubscription()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0

3 Methods

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