Completed
Push — master ( d9adeb...430d2c )
by
unknown
01:15 queued 37s
created

Course::getDepartmentName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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