Passed
Push — master ( 777bb3...b79720 )
by
unknown
22:29 queued 11:09
created

Course::setSkills()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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