Passed
Push — master ( af00ba...368e6c )
by
unknown
10:47
created

CLp::setProgress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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