Passed
Pull Request — master (#6073)
by
unknown
08:52
created

Course::setTools()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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