Passed
Pull Request — master (#5831)
by
unknown
07:35
created

CLp::setValidityInDays()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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