CLp::getLpType()   A
last analyzed

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\CourseBundle\Entity;
8
9
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
10
use ApiPlatform\Metadata\ApiFilter;
11
use ApiPlatform\Metadata\ApiResource;
12
use ApiPlatform\Metadata\Get;
13
use ApiPlatform\Metadata\GetCollection;
14
use ApiPlatform\Metadata\Post;
15
use ApiPlatform\OpenApi\Model\Operation;
16
use ApiPlatform\OpenApi\Model\Parameter;
17
use Chamilo\CoreBundle\Controller\Api\LpReorderController;
18
use Chamilo\CoreBundle\Entity\AbstractResource;
19
use Chamilo\CoreBundle\Entity\Asset;
20
use Chamilo\CoreBundle\Entity\ResourceInterface;
21
use Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface;
22
use Chamilo\CoreBundle\Filter\SidFilter;
23
use Chamilo\CoreBundle\State\LpCollectionStateProvider;
24
use Chamilo\CourseBundle\Repository\CLpRepository;
25
use DateTime;
26
use Doctrine\Common\Collections\ArrayCollection;
27
use Doctrine\Common\Collections\Collection;
28
use Doctrine\ORM\Mapping as ORM;
29
use Gedmo\Mapping\Annotation as Gedmo;
30
use Stringable;
31
use Symfony\Component\Serializer\Annotation\Groups;
32
use Symfony\Component\Serializer\Annotation\MaxDepth;
33
use Symfony\Component\Serializer\Annotation\SerializedName;
34
use Symfony\Component\Uid\Uuid;
35
use Symfony\Component\Validator\Constraints as Assert;
36
37
/**
38
 * Course learning paths (LPs).
39
 */
40
#[ApiResource(
41
    shortName: 'LearningPath',
42
    operations: [
43
        new GetCollection(
44
            openapi: new Operation(
45
                summary: 'List learning paths filtered by resourceNode.parent (course) and sid',
46
                parameters: [
47
                    new Parameter(
48
                        name: 'resourceNode.parent',
49
                        in: 'query',
50
                        required: true,
51
                        schema: ['type' => 'integer']
52
                    ),
53
                    new Parameter(
54
                        name: 'sid',
55
                        in: 'query',
56
                        required: false,
57
                        schema: ['type' => 'integer']
58
                    ),
59
                    new Parameter(
60
                        name: 'title',
61
                        in: 'query',
62
                        required: false,
63
                        schema: ['type' => 'string']
64
                    ),
65
                ],
66
            ),
67
            name: 'get_lp_collection_with_progress',
68
            provider: LpCollectionStateProvider::class,
69
        ),
70
        new Get(security: "is_granted('ROLE_USER')"),
71
        new Post(
72
            uriTemplate: '/learning_paths/reorder',
73
            status: 204,
74
            controller: LpReorderController::class,
75
            security: "is_granted('ROLE_TEACHER') or is_granted('ROLE_ADMIN')",
76
            read: false,
77
            deserialize: false,
78
            name: 'lp_reorder'
79
        ),
80
    ],
81
    normalizationContext: [
82
        'groups' => ['lp:read', 'resource_node:read', 'resource_link:read'],
83
        'enable_max_depth' => true,
84
    ],
85
    denormalizationContext: ['groups' => ['lp:write']],
86
    paginationEnabled: true,
87
)]
88
#[ApiFilter(SearchFilter::class, properties: [
89
    'title' => 'partial',
90
    'resourceNode.parent' => 'exact',
91
])]
92
#[ApiFilter(filterClass: SidFilter::class)]
93
#[ORM\Table(name: 'c_lp')]
94
#[ORM\Entity(repositoryClass: CLpRepository::class)]
95
class CLp extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface, Stringable
96
{
97
    public const LP_TYPE = 1;
98
    public const SCORM_TYPE = 2;
99
    public const AICC_TYPE = 3;
100
101
    #[ORM\Column(name: 'iid', type: 'integer')]
102
    #[ORM\Id]
103
    #[ORM\GeneratedValue]
104
    #[Groups(['lp:read'])]
105
    protected ?int $iid = null;
106
107
    #[Assert\NotBlank]
108
    #[ORM\Column(name: 'lp_type', type: 'integer', nullable: false)]
109
    #[Groups(['lp:read', 'lp:write'])]
110
    protected int $lpType;
111
112
    #[Assert\NotBlank]
113
    #[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)]
114
    #[Groups(['lp:read', 'lp:write'])]
115
    protected string $title;
116
117
    #[ORM\Column(name: 'ref', type: 'text', nullable: true)]
118
    #[Groups(['lp:read', 'lp:write'])]
119
    protected ?string $ref = null;
120
121
    #[ORM\Column(name: 'description', type: 'text', nullable: true)]
122
    #[Groups(['lp:read', 'lp:write'])]
123
    protected ?string $description;
124
125
    #[ORM\Column(name: 'path', type: 'text', nullable: false)]
126
    #[Groups(['lp:read', 'lp:write'])]
127
    protected string $path;
128
129
    #[ORM\Column(name: 'force_commit', type: 'boolean', nullable: false)]
130
    protected bool $forceCommit;
131
132
    #[ORM\Column(name: 'default_view_mod', type: 'string', length: 32, nullable: false, options: ['default' => 'embedded'])]
133
    protected string $defaultViewMod;
134
135
    #[ORM\Column(name: 'default_encoding', type: 'string', length: 32, nullable: false, options: ['default' => 'UTF-8'])]
136
    protected string $defaultEncoding;
137
138
    #[ORM\Column(name: 'content_maker', type: 'text', nullable: false)]
139
    protected string $contentMaker;
140
141
    #[ORM\Column(name: 'content_local', type: 'string', length: 32, nullable: false, options: ['default' => 'local'])]
142
    protected string $contentLocal;
143
144
    #[ORM\Column(name: 'content_license', type: 'text', nullable: false)]
145
    protected string $contentLicense;
146
147
    #[ORM\Column(name: 'prevent_reinit', type: 'boolean', nullable: false, options: ['default' => 1])]
148
    #[Groups(['lp:read', 'lp:write'])]
149
    protected bool $preventReinit;
150
151
    #[ORM\Column(name: 'js_lib', type: 'text', nullable: false)]
152
    protected string $jsLib;
153
154
    #[ORM\Column(name: 'debug', type: 'boolean', nullable: false)]
155
    protected bool $debug;
156
157
    #[Assert\NotBlank]
158
    #[ORM\Column(name: 'theme', type: 'string', length: 255, nullable: false)]
159
    protected string $theme;
160
161
    #[Assert\NotBlank]
162
    #[ORM\Column(name: 'author', type: 'text', nullable: false)]
163
    protected string $author;
164
165
    #[ORM\Column(name: 'prerequisite', type: 'integer', nullable: false)]
166
    #[Groups(['lp:read', 'lp:write'])]
167
    protected int $prerequisite;
168
169
    #[ORM\Column(name: 'hide_toc_frame', type: 'boolean', nullable: false)]
170
    protected bool $hideTocFrame;
171
172
    #[ORM\Column(name: 'seriousgame_mode', type: 'boolean', nullable: false)]
173
    protected bool $seriousgameMode;
174
175
    #[ORM\Column(name: 'use_max_score', type: 'integer', nullable: false, options: ['default' => 1])]
176
    protected int $useMaxScore;
177
178
    #[ORM\Column(name: 'autolaunch', type: 'integer', nullable: false)]
179
    #[Groups(['lp:read', 'lp:write'])]
180
    protected int $autolaunch;
181
182
    #[ORM\ManyToOne(targetEntity: CLpCategory::class, inversedBy: 'lps')]
183
    #[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'iid')]
184
    #[Groups(['lp:read'])]
185
    #[MaxDepth(1)]
186
    protected ?CLpCategory $category = null;
187
188
    #[ORM\Column(name: 'max_attempts', type: 'integer', nullable: false)]
189
    protected int $maxAttempts;
190
191
    #[ORM\Column(name: 'subscribe_users', type: 'integer', nullable: false)]
192
    protected int $subscribeUsers;
193
194
    #[Gedmo\Timestampable(on: 'create')]
195
    #[ORM\Column(name: 'created_on', type: 'datetime', nullable: false)]
196
    protected DateTime $createdOn;
197
198
    #[Gedmo\Timestampable(on: 'update')]
199
    #[ORM\Column(name: 'modified_on', type: 'datetime', nullable: false)]
200
    protected DateTime $modifiedOn;
201
202
    #[ORM\Column(name: 'published_on', type: 'datetime', nullable: true)]
203
    #[Groups(['lp:read'])]
204
    protected ?DateTime $publishedOn;
205
206
    #[ORM\Column(name: 'expired_on', type: 'datetime', nullable: true)]
207
    #[Groups(['lp:read'])]
208
    protected ?DateTime $expiredOn = null;
209
210
    #[ORM\Column(name: 'accumulate_scorm_time', type: 'integer', nullable: false, options: ['default' => 1])]
211
    protected int $accumulateScormTime = 1;
212
213
    #[ORM\Column(name: 'accumulate_work_time', type: 'integer', nullable: false, options: ['default' => 0])]
214
    protected int $accumulateWorkTime = 0;
215
216
    #[ORM\Column(name: 'next_lp_id', type: 'integer', nullable: false, options: ['default' => 0])]
217
    protected int $nextLpId = 0;
218
219
    #[ORM\Column(name: 'subscribe_user_by_date', type: 'boolean', nullable: false, options: ['default' => 0])]
220
    protected bool $subscribeUserByDate = false;
221
222
    #[ORM\Column(name: 'display_not_allowed_lp', type: 'boolean', nullable: true, options: ['default' => 0])]
223
    protected bool $displayNotAllowedLp = false;
224
225
    #[ORM\OneToMany(mappedBy: 'lp', targetEntity: CLpItem::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
226
    protected Collection $items;
227
228
    /**
229
     * @var Collection<int, CForum>
230
     */
231
    #[ORM\OneToMany(mappedBy: 'lp', targetEntity: CForum::class, cascade: ['persist', 'remove'])]
232
    protected Collection $forums;
233
234
    #[ORM\ManyToOne(targetEntity: Asset::class, cascade: ['persist', 'remove'])]
235
    #[ORM\JoinColumn(name: 'asset_id', referencedColumnName: 'id')]
236
    protected ?Asset $asset = null;
237
238
    #[ORM\Column(name: 'duration', type: 'integer', nullable: true)]
239
    protected ?int $duration = null;
240
241
    #[ORM\Column(name: 'auto_forward_video', type: 'boolean', options: ['default' => 0])]
242
    protected bool $autoForwardVideo = false;
243
244
    #[Groups(['lp:read'])]
245
    #[SerializedName('progress')]
246
    private ?int $progress = null;
247
248
    public function __construct()
249
    {
250
        $now = new DateTime();
251
        $this->createdOn = $now;
252
        $this->modifiedOn = $now;
253
        $this->publishedOn = $now;
254
        $this->accumulateScormTime = 1;
255
        $this->accumulateWorkTime = 0;
256
        $this->author = '';
257
        $this->autolaunch = 0;
258
        $this->contentLocal = 'local';
259
        $this->contentMaker = 'chamilo';
260
        $this->contentLicense = '';
261
        $this->defaultEncoding = 'UTF-8';
262
        $this->defaultViewMod = 'embedded';
263
        $this->description = '';
264
        $this->debug = false;
265
        $this->forceCommit = false;
266
        $this->hideTocFrame = false;
267
        $this->jsLib = '';
268
        $this->maxAttempts = 0;
269
        $this->preventReinit = true;
270
        $this->path = '';
271
        $this->prerequisite = 0;
272
        $this->seriousgameMode = false;
273
        $this->subscribeUsers = 0;
274
        $this->useMaxScore = 1;
275
        $this->theme = '';
276
        $this->nextLpId = 0;
277
        $this->items = new ArrayCollection();
278
        $this->forums = new ArrayCollection();
279
    }
280
281
    public function __toString(): string
282
    {
283
        return $this->getTitle();
284
    }
285
286
    public function setLpType(int $lpType): self
287
    {
288
        $this->lpType = $lpType;
289
290
        return $this;
291
    }
292
293
    public function getLpType(): int
294
    {
295
        return $this->lpType;
296
    }
297
298
    public function setTitle(string $title): self
299
    {
300
        $this->title = $title;
301
302
        return $this;
303
    }
304
305
    public function getTitle(): string
306
    {
307
        return $this->title;
308
    }
309
310
    public function setRef(string $ref): self
311
    {
312
        $this->ref = $ref;
313
314
        return $this;
315
    }
316
317
    public function getRef(): ?string
318
    {
319
        return $this->ref;
320
    }
321
322
    public function setDescription(string $description): self
323
    {
324
        $this->description = $description;
325
326
        return $this;
327
    }
328
329
    public function getDescription(): ?string
330
    {
331
        return $this->description;
332
    }
333
334
    public function setPath(string $path): self
335
    {
336
        $this->path = $path;
337
338
        return $this;
339
    }
340
341
    public function getPath(): string
342
    {
343
        return $this->path;
344
    }
345
346
    public function setForceCommit(bool $forceCommit): self
347
    {
348
        $this->forceCommit = $forceCommit;
349
350
        return $this;
351
    }
352
353
    public function getForceCommit(): bool
354
    {
355
        return $this->forceCommit;
356
    }
357
358
    public function setDefaultViewMod(string $defaultViewMod): self
359
    {
360
        $this->defaultViewMod = $defaultViewMod;
361
362
        return $this;
363
    }
364
365
    public function getDefaultViewMod(): string
366
    {
367
        return $this->defaultViewMod;
368
    }
369
370
    public function setDefaultEncoding(string $defaultEncoding): self
371
    {
372
        $this->defaultEncoding = $defaultEncoding;
373
374
        return $this;
375
    }
376
377
    public function getDefaultEncoding(): string
378
    {
379
        return $this->defaultEncoding;
380
    }
381
382
    public function setContentMaker(string $contentMaker): self
383
    {
384
        $this->contentMaker = $contentMaker;
385
386
        return $this;
387
    }
388
389
    public function getContentMaker(): string
390
    {
391
        return $this->contentMaker;
392
    }
393
394
    public function setContentLocal(string $contentLocal): self
395
    {
396
        $this->contentLocal = $contentLocal;
397
398
        return $this;
399
    }
400
401
    public function getContentLocal(): string
402
    {
403
        return $this->contentLocal;
404
    }
405
406
    public function setContentLicense(string $contentLicense): self
407
    {
408
        $this->contentLicense = $contentLicense;
409
410
        return $this;
411
    }
412
413
    public function getContentLicense(): string
414
    {
415
        return $this->contentLicense;
416
    }
417
418
    public function setPreventReinit(bool $preventReinit): self
419
    {
420
        $this->preventReinit = $preventReinit;
421
422
        return $this;
423
    }
424
425
    public function getPreventReinit(): bool
426
    {
427
        return $this->preventReinit;
428
    }
429
430
    public function setJsLib(string $jsLib): self
431
    {
432
        $this->jsLib = $jsLib;
433
434
        return $this;
435
    }
436
437
    public function getJsLib(): string
438
    {
439
        return $this->jsLib;
440
    }
441
442
    public function setDebug(bool $debug): self
443
    {
444
        $this->debug = $debug;
445
446
        return $this;
447
    }
448
449
    public function getDebug(): bool
450
    {
451
        return $this->debug;
452
    }
453
454
    public function setTheme(string $theme): self
455
    {
456
        $this->theme = $theme;
457
458
        return $this;
459
    }
460
461
    public function getTheme(): string
462
    {
463
        return $this->theme;
464
    }
465
466
    public function setAuthor(string $author): self
467
    {
468
        $this->author = $author;
469
470
        return $this;
471
    }
472
473
    public function getAuthor(): string
474
    {
475
        return $this->author;
476
    }
477
478
    public function setPrerequisite(int $prerequisite): self
479
    {
480
        $this->prerequisite = $prerequisite;
481
482
        return $this;
483
    }
484
485
    public function getPrerequisite(): int
486
    {
487
        return $this->prerequisite;
488
    }
489
490
    public function setHideTocFrame(bool $hideTocFrame): self
491
    {
492
        $this->hideTocFrame = $hideTocFrame;
493
494
        return $this;
495
    }
496
497
    public function getHideTocFrame(): bool
498
    {
499
        return $this->hideTocFrame;
500
    }
501
502
    public function setSeriousgameMode(bool $seriousgameMode): self
503
    {
504
        $this->seriousgameMode = $seriousgameMode;
505
506
        return $this;
507
    }
508
509
    public function getSeriousgameMode(): bool
510
    {
511
        return $this->seriousgameMode;
512
    }
513
514
    public function setUseMaxScore(int $useMaxScore): self
515
    {
516
        $this->useMaxScore = $useMaxScore;
517
518
        return $this;
519
    }
520
521
    public function getUseMaxScore(): int
522
    {
523
        return $this->useMaxScore;
524
    }
525
526
    public function setAutolaunch(int $autolaunch): self
527
    {
528
        $this->autolaunch = $autolaunch;
529
530
        return $this;
531
    }
532
533
    public function getAutolaunch(): int
534
    {
535
        return $this->autolaunch;
536
    }
537
538
    public function setCreatedOn(DateTime $createdOn): self
539
    {
540
        $this->createdOn = $createdOn;
541
542
        return $this;
543
    }
544
545
    public function getCreatedOn(): DateTime
546
    {
547
        return $this->createdOn;
548
    }
549
550
    public function setModifiedOn(DateTime $modifiedOn): self
551
    {
552
        $this->modifiedOn = $modifiedOn;
553
554
        return $this;
555
    }
556
557
    public function getModifiedOn(): DateTime
558
    {
559
        return $this->modifiedOn;
560
    }
561
562
    public function setPublishedOn(?DateTime $publishedOn): self
563
    {
564
        $this->publishedOn = $publishedOn;
565
566
        return $this;
567
    }
568
569
    public function getPublishedOn(): ?DateTime
570
    {
571
        return $this->publishedOn;
572
    }
573
574
    public function setExpiredOn(?DateTime $expiredOn): self
575
    {
576
        $this->expiredOn = $expiredOn;
577
578
        return $this;
579
    }
580
581
    public function getExpiredOn(): ?DateTime
582
    {
583
        return $this->expiredOn;
584
    }
585
586
    public function getCategory(): ?CLpCategory
587
    {
588
        return $this->category;
589
    }
590
591
    public function hasCategory(): bool
592
    {
593
        return null !== $this->category;
594
    }
595
596
    public function setCategory(?CLpCategory $category = null): self
597
    {
598
        $this->category = $category;
599
600
        return $this;
601
    }
602
603
    public function getAccumulateScormTime(): int
604
    {
605
        return $this->accumulateScormTime;
606
    }
607
608
    public function setAccumulateScormTime(int $accumulateScormTime): self
609
    {
610
        $this->accumulateScormTime = $accumulateScormTime;
611
612
        return $this;
613
    }
614
615
    public function getAccumulateWorkTime(): int
616
    {
617
        return $this->accumulateWorkTime;
618
    }
619
620
    public function setAccumulateWorkTime(int $accumulateWorkTime): self
621
    {
622
        $this->accumulateWorkTime = $accumulateWorkTime;
623
624
        return $this;
625
    }
626
627
    public function getMaxAttempts(): int
628
    {
629
        return $this->maxAttempts;
630
    }
631
632
    public function getNextLpId(): int
633
    {
634
        return $this->nextLpId;
635
    }
636
637
    public function setNextLpId(int $nextLpId): self
638
    {
639
        $this->nextLpId = $nextLpId;
640
641
        return $this;
642
    }
643
644
    public function getSubscribeUserByDate(): bool
645
    {
646
        return $this->subscribeUserByDate;
647
    }
648
649
    public function setSubscribeUserByDate(bool $subscribeUserByDate): self
650
    {
651
        $this->subscribeUserByDate = $subscribeUserByDate;
652
653
        return $this;
654
    }
655
656
    public function getDisplayNotAllowedLp(): bool
657
    {
658
        return $this->displayNotAllowedLp;
659
    }
660
661
    public function setDisplayNotAllowedLp(bool $displayNotAllowedLp): self
662
    {
663
        $this->displayNotAllowedLp = $displayNotAllowedLp;
664
665
        return $this;
666
    }
667
668
    /**
669
     * @return Collection<int, CLpItem>
670
     */
671
    public function getItems(): Collection
672
    {
673
        return $this->items;
674
    }
675
676
    public function getIid(): ?int
677
    {
678
        return $this->iid;
679
    }
680
681
    public function getSubscribeUsers(): int
682
    {
683
        return $this->subscribeUsers;
684
    }
685
686
    public function setSubscribeUsers(int $value): self
687
    {
688
        $this->subscribeUsers = $value;
689
690
        return $this;
691
    }
692
693
    /**
694
     * @return Collection<int, CForum>
695
     */
696
    public function getForums(): Collection
697
    {
698
        return $this->forums;
699
    }
700
701
    public function setForums(ArrayCollection|Collection $forums): self
702
    {
703
        $this->forums = $forums;
704
705
        return $this;
706
    }
707
708
    public function getAsset(): ?Asset
709
    {
710
        return $this->asset;
711
    }
712
713
    public function hasAsset(): bool
714
    {
715
        return null !== $this->asset;
716
    }
717
718
    public function setAsset(?Asset $asset): self
719
    {
720
        $this->asset = $asset;
721
722
        return $this;
723
    }
724
725
    public function getDuration(): ?int
726
    {
727
        return $this->duration;
728
    }
729
730
    public function setDuration(?int $duration): self
731
    {
732
        $this->duration = $duration;
733
734
        return $this;
735
    }
736
737
    public function getAutoForwardVideo(): bool
738
    {
739
        return $this->autoForwardVideo;
740
    }
741
742
    public function setAutoForwardVideo(bool $autoForwardVideo): self
743
    {
744
        $this->autoForwardVideo = $autoForwardVideo;
745
746
        return $this;
747
    }
748
749
    public function getProgress(): int
750
    {
751
        return $this->progress ?? 0;
752
    }
753
    public function setProgress(?int $progress): void
754
    {
755
        $this->progress = $progress;
756
    }
757
758
    public function getResourceIdentifier(): int|Uuid
759
    {
760
        return $this->getIid();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getIid() could return the type null which is incompatible with the type-hinted return Symfony\Component\Uid\Uuid|integer. Consider adding an additional type-check to rule them out.
Loading history...
761
    }
762
763
    public function getResourceName(): string
764
    {
765
        return $this->getTitle();
766
    }
767
768
    public function setResourceName(string $name): self
769
    {
770
        return $this->setTitle($name);
771
    }
772
}
773