Completed
Push — master ( d9adeb...430d2c )
by
unknown
01:15 queued 37s
created

CQuiz::setPageResultConfiguration()   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
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
nc 1
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\ResourceInterface;
11
use Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface;
12
use Chamilo\CoreBundle\Entity\TrackEExercise;
13
use Chamilo\CourseBundle\Repository\CQuizRepository;
14
use DateTime;
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
use Doctrine\ORM\Mapping as ORM;
18
use Stringable;
19
use Symfony\Component\Serializer\Annotation\Groups;
20
use Symfony\Component\Uid\Uuid;
21
use Symfony\Component\Validator\Constraints as Assert;
22
23
/**
24
 * Course quizzes.
25
 */
26
#[ORM\Table(name: 'c_quiz')]
27
#[ORM\Entity(repositoryClass: CQuizRepository::class)]
28
class CQuiz extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface, Stringable
29
{
30
    public const ALL_ON_ONE_PAGE = 1;
31
    public const ONE_PER_PAGE = 2;
32
33
    #[Groups(['track_e_exercise:read'])]
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: 'title', type: 'text', nullable: false)]
41
    protected string $title;
42
43
    #[ORM\Column(name: 'description', type: 'text', nullable: true)]
44
    protected ?string $description = null;
45
46
    #[ORM\Column(name: 'sound', type: 'string', length: 255, nullable: true)]
47
    protected ?string $sound = null;
48
49
    #[ORM\Column(name: 'type', type: 'integer', nullable: false)]
50
    protected int $type;
51
52
    #[ORM\Column(name: 'random', type: 'integer', nullable: false)]
53
    protected int $random;
54
55
    #[ORM\Column(name: 'random_answers', type: 'boolean', nullable: false)]
56
    protected bool $randomAnswers;
57
58
    #[ORM\Column(name: 'active', type: 'integer', nullable: false)]
59
    protected int $active;
60
61
    #[ORM\Column(name: 'results_disabled', type: 'integer', nullable: false)]
62
    protected int $resultsDisabled;
63
64
    #[ORM\Column(name: 'access_condition', type: 'text', nullable: true)]
65
    protected ?string $accessCondition = null;
66
67
    #[ORM\Column(name: 'max_attempt', type: 'integer', nullable: false)]
68
    protected int $maxAttempt;
69
70
    #[ORM\Column(name: 'start_time', type: 'datetime', nullable: true)]
71
    protected ?DateTime $startTime = null;
72
73
    #[ORM\Column(name: 'end_time', type: 'datetime', nullable: true)]
74
    protected ?DateTime $endTime = null;
75
76
    #[ORM\Column(name: 'feedback_type', type: 'integer', nullable: false)]
77
    protected int $feedbackType;
78
79
    #[ORM\Column(name: 'expired_time', type: 'integer', nullable: false)]
80
    protected int $expiredTime;
81
82
    #[ORM\Column(name: 'propagate_neg', type: 'integer', nullable: false)]
83
    protected int $propagateNeg;
84
85
    #[ORM\Column(name: 'save_correct_answers', type: 'integer', nullable: true)]
86
    protected ?int $saveCorrectAnswers;
87
88
    #[ORM\Column(name: 'review_answers', type: 'integer', nullable: false)]
89
    protected int $reviewAnswers;
90
91
    #[ORM\Column(name: 'random_by_category', type: 'integer', nullable: false)]
92
    protected int $randomByCategory;
93
94
    #[ORM\Column(name: 'text_when_finished', type: 'text', nullable: true)]
95
    protected ?string $textWhenFinished = null;
96
97
    #[ORM\Column(name: 'text_when_finished_failure', type: 'text', nullable: true)]
98
    protected ?string $textWhenFinishedFailure = null;
99
100
    #[ORM\Column(name: 'display_category_name', type: 'integer', nullable: false)]
101
    protected int $displayCategoryName;
102
103
    #[ORM\Column(name: 'pass_percentage', type: 'integer', nullable: true)]
104
    protected ?int $passPercentage = null;
105
106
    #[ORM\Column(name: 'prevent_backwards', type: 'integer', nullable: false, options: ['default' => 0])]
107
    protected int $preventBackwards;
108
109
    #[ORM\Column(name: 'question_selection_type', type: 'integer', nullable: true)]
110
    protected ?int $questionSelectionType = null;
111
112
    #[ORM\Column(name: 'hide_question_number', type: 'integer', nullable: false, options: ['default' => 0])]
113
    protected int $hideQuestionNumber;
114
115
    #[ORM\Column(name: 'hide_question_title', type: 'boolean', nullable: false)]
116
    protected bool $hideQuestionTitle;
117
118
    #[ORM\ManyToOne(targetEntity: CQuizCategory::class, cascade: ['persist'])]
119
    #[ORM\JoinColumn(name: 'quiz_category_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
120
    protected ?CQuizCategory $quizCategory = null;
121
122
    #[ORM\Column(name: 'show_previous_button', type: 'boolean', nullable: false, options: ['default' => 1])]
123
    protected bool $showPreviousButton;
124
125
    #[ORM\Column(name: 'notifications', type: 'string', length: 255, nullable: true)]
126
    protected ?string $notifications;
127
128
    #[ORM\Column(name: 'autolaunch', type: 'boolean', nullable: true, options: ['default' => 0])]
129
    protected ?bool $autoLaunch;
130
131
    #[ORM\Column(name: 'hide_attempts_table', type: 'boolean', nullable: false, options: ['default' => 0])]
132
    protected bool $hideAttemptsTable;
133
134
    #[ORM\Column(name: 'page_result_configuration', type: 'array')]
135
    protected array $pageResultConfiguration = [];
136
137
    /**
138
     * @var Collection<int, CQuizRelQuestion>
139
     */
140
    #[ORM\OneToMany(mappedBy: 'quiz', targetEntity: CQuizRelQuestion::class, cascade: ['persist'], orphanRemoval: true)]
141
    protected Collection $questions;
142
143
    /**
144
     * @var Collection<int, CQuizRelQuestionCategory>
145
     */
146
    #[ORM\OneToMany(mappedBy: 'quiz', targetEntity: CQuizRelQuestionCategory::class, cascade: ['persist'])]
147
    protected Collection $questionsCategories;
148
149
    /**
150
     * @var Collection<int, TrackEExercise>
151
     */
152
    #[ORM\OneToMany(mappedBy: 'quiz', targetEntity: TrackEExercise::class)]
153
    protected Collection $attempts;
154
155
    #[ORM\Column(name: 'duration', type: 'integer', nullable: true)]
156
    protected ?int $duration = null;
157
158
    public function __construct()
159
    {
160
        $this->questions = new ArrayCollection();
161
        $this->questionsCategories = new ArrayCollection();
162
        $this->hideQuestionTitle = false;
163
        $this->hideQuestionNumber = 0;
164
        $this->type = self::ONE_PER_PAGE;
165
        $this->showPreviousButton = true;
166
        $this->notifications = '';
167
        $this->autoLaunch = false;
168
        $this->preventBackwards = 0;
169
        $this->random = 0;
170
        $this->randomAnswers = false;
171
        $this->active = 1;
172
        $this->resultsDisabled = 0;
173
        $this->maxAttempt = 1;
174
        $this->feedbackType = 0;
175
        $this->expiredTime = 0;
176
        $this->propagateNeg = 0;
177
        $this->saveCorrectAnswers = 0;
178
        $this->reviewAnswers = 0;
179
        $this->randomByCategory = 0;
180
        $this->displayCategoryName = 0;
181
        $this->hideAttemptsTable = false;
182
        $this->pageResultConfiguration = [];
183
        $this->attempts = new ArrayCollection();
184
        $this->hideAttemptsTable = false;
185
    }
186
187
    public function __toString(): string
188
    {
189
        return $this->getTitle();
190
    }
191
192
    /**
193
     * @return ArrayCollection<int, CQuizRelQuestion>
194
     */
195
    public function getQuestions(): Collection
196
    {
197
        return $this->questions instanceof ArrayCollection ?
198
            $this->questions :
199
            new ArrayCollection($this->questions->toArray());
200
    }
201
202
    public function setTitle(string $title): self
203
    {
204
        $this->title = $title;
205
206
        return $this;
207
    }
208
209
    public function getTitle(): string
210
    {
211
        return $this->title;
212
    }
213
214
    public function setDescription(string $description): self
215
    {
216
        $this->description = $description;
217
218
        return $this;
219
    }
220
221
    /**
222
     * Get description.
223
     *
224
     * @return string
225
     */
226
    public function getDescription()
227
    {
228
        return $this->description;
229
    }
230
231
    public function setSound(string $sound): self
232
    {
233
        $this->sound = $sound;
234
235
        return $this;
236
    }
237
238
    public function getSound(): ?string
239
    {
240
        return $this->sound;
241
    }
242
243
    public function setType(int $type): self
244
    {
245
        $this->type = $type;
246
247
        return $this;
248
    }
249
250
    public function getType(): int
251
    {
252
        return $this->type;
253
    }
254
255
    public function setRandom(int $random): self
256
    {
257
        $this->random = $random;
258
259
        return $this;
260
    }
261
262
    /**
263
     * Get random.
264
     *
265
     * @return int
266
     */
267
    public function getRandom()
268
    {
269
        return $this->random;
270
    }
271
272
    public function setRandomAnswers(bool $randomAnswers): self
273
    {
274
        $this->randomAnswers = $randomAnswers;
275
276
        return $this;
277
    }
278
279
    public function getRandomAnswers(): bool
280
    {
281
        return $this->randomAnswers;
282
    }
283
284
    public function setActive(int $active): self
285
    {
286
        $this->active = $active;
287
288
        return $this;
289
    }
290
291
    public function getActive(): int
292
    {
293
        return $this->active;
294
    }
295
296
    public function setResultsDisabled(int $resultsDisabled): self
297
    {
298
        $this->resultsDisabled = $resultsDisabled;
299
300
        return $this;
301
    }
302
303
    public function getResultsDisabled(): int
304
    {
305
        return $this->resultsDisabled;
306
    }
307
308
    public function setAccessCondition(string $accessCondition): self
309
    {
310
        $this->accessCondition = $accessCondition;
311
312
        return $this;
313
    }
314
315
    public function getAccessCondition(): ?string
316
    {
317
        return $this->accessCondition;
318
    }
319
320
    public function setMaxAttempt(int $maxAttempt): self
321
    {
322
        $this->maxAttempt = $maxAttempt;
323
324
        return $this;
325
    }
326
327
    public function getMaxAttempt(): int
328
    {
329
        return $this->maxAttempt;
330
    }
331
332
    public function setStartTime(?DateTime $startTime): self
333
    {
334
        $this->startTime = $startTime;
335
336
        return $this;
337
    }
338
339
    public function getStartTime(): ?DateTime
340
    {
341
        return $this->startTime;
342
    }
343
344
    public function setEndTime(?DateTime $endTime): self
345
    {
346
        $this->endTime = $endTime;
347
348
        return $this;
349
    }
350
351
    public function getEndTime(): ?DateTime
352
    {
353
        return $this->endTime;
354
    }
355
356
    public function setFeedbackType(int $feedbackType): self
357
    {
358
        $this->feedbackType = $feedbackType;
359
360
        return $this;
361
    }
362
363
    public function getFeedbackType(): int
364
    {
365
        return $this->feedbackType;
366
    }
367
368
    public function setExpiredTime(int $expiredTime): self
369
    {
370
        $this->expiredTime = $expiredTime;
371
372
        return $this;
373
    }
374
375
    public function getExpiredTime(): int
376
    {
377
        return $this->expiredTime;
378
    }
379
380
    public function setPropagateNeg(int $propagateNeg): self
381
    {
382
        $this->propagateNeg = $propagateNeg;
383
384
        return $this;
385
    }
386
387
    /**
388
     * Get propagateNeg.
389
     */
390
    public function getPropagateNeg(): int
391
    {
392
        return $this->propagateNeg;
393
    }
394
395
    public function setSaveCorrectAnswers(int $saveCorrectAnswers): self
396
    {
397
        $this->saveCorrectAnswers = $saveCorrectAnswers;
398
399
        return $this;
400
    }
401
402
    public function getSaveCorrectAnswers(): ?int
403
    {
404
        return $this->saveCorrectAnswers;
405
    }
406
407
    public function setReviewAnswers(int $reviewAnswers): self
408
    {
409
        $this->reviewAnswers = $reviewAnswers;
410
411
        return $this;
412
    }
413
414
    /**
415
     * Get reviewAnswers.
416
     */
417
    public function getReviewAnswers(): int
418
    {
419
        return $this->reviewAnswers;
420
    }
421
422
    public function setRandomByCategory(int $randomByCategory): self
423
    {
424
        $this->randomByCategory = $randomByCategory;
425
426
        return $this;
427
    }
428
429
    /**
430
     * Get randomByCategory.
431
     */
432
    public function getRandomByCategory(): int
433
    {
434
        return $this->randomByCategory;
435
    }
436
437
    /**
438
     * Set text to display to user when they succeed to the test or, when no pass percentage has been set, when the
439
     * test is finished.
440
     */
441
    public function setTextWhenFinished(string $textWhenFinished): self
442
    {
443
        $this->textWhenFinished = $textWhenFinished;
444
445
        return $this;
446
    }
447
448
    /**
449
     * Get text to display to user when they succeed to the test or, when no pass percentage has been set, when the
450
     * test is finished.
451
     */
452
    public function getTextWhenFinished(): ?string
453
    {
454
        return $this->textWhenFinished;
455
    }
456
457
    /**
458
     * Set text to display to user when they fail to the test (when pass percentage has been set).
459
     */
460
    public function setTextWhenFinishedFailure(?string $textWhenFinished): self
461
    {
462
        $this->textWhenFinishedFailure = $textWhenFinished;
463
464
        return $this;
465
    }
466
467
    /**
468
     * Get text to display to user when they fail to the test (when pass percentage has been set).
469
     */
470
    public function getTextWhenFinishedFailure(): ?string
471
    {
472
        if (empty($this->textWhenFinishedFailure)) {
473
            return '';
474
        }
475
476
        return $this->textWhenFinishedFailure;
477
    }
478
479
    public function setDisplayCategoryName(int $displayCategoryName): self
480
    {
481
        $this->displayCategoryName = $displayCategoryName;
482
483
        return $this;
484
    }
485
486
    /**
487
     * Get displayCategoryName.
488
     */
489
    public function getDisplayCategoryName(): int
490
    {
491
        return $this->displayCategoryName;
492
    }
493
494
    public function setPassPercentage(int $passPercentage): self
495
    {
496
        $this->passPercentage = $passPercentage;
497
498
        return $this;
499
    }
500
501
    /**
502
     * Get passPercentage.
503
     */
504
    public function getPassPercentage(): ?int
505
    {
506
        return $this->passPercentage;
507
    }
508
509
    public function getQuizCategory(): ?CQuizCategory
510
    {
511
        return $this->quizCategory;
512
    }
513
514
    public function setQuizCategory(CQuizCategory $quizCategory): self
515
    {
516
        $this->quizCategory = $quizCategory;
517
518
        return $this;
519
    }
520
521
    public function getQuestionSelectionType(): ?int
522
    {
523
        return $this->questionSelectionType;
524
    }
525
526
    public function setQuestionSelectionType(int $questionSelectionType): self
527
    {
528
        $this->questionSelectionType = $questionSelectionType;
529
530
        return $this;
531
    }
532
533
    public function isHideQuestionTitle(): bool
534
    {
535
        return $this->hideQuestionTitle;
536
    }
537
538
    public function setHideQuestionTitle(bool $hideQuestionTitle): self
539
    {
540
        $this->hideQuestionTitle = $hideQuestionTitle;
541
542
        return $this;
543
    }
544
545
    public function isShowPreviousButton(): bool
546
    {
547
        return $this->showPreviousButton;
548
    }
549
550
    public function setShowPreviousButton(bool $showPreviousButton): self
551
    {
552
        $this->showPreviousButton = $showPreviousButton;
553
554
        return $this;
555
    }
556
557
    public function getNotifications(): string
558
    {
559
        return $this->notifications;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->notifications 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...
560
    }
561
562
    public function setNotifications(string $notifications): self
563
    {
564
        $this->notifications = $notifications;
565
566
        return $this;
567
    }
568
569
    public function getIid(): ?int
570
    {
571
        return $this->iid;
572
    }
573
574
    public function getPreventBackwards(): int
575
    {
576
        return $this->preventBackwards;
577
    }
578
579
    public function setPreventBackwards(int $preventBackwards): self
580
    {
581
        $this->preventBackwards = $preventBackwards;
582
583
        return $this;
584
    }
585
586
    public function isAutoLaunch(): bool
587
    {
588
        return $this->autoLaunch;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->autoLaunch could return the type null which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
589
    }
590
591
    public function setAutoLaunch(bool $autoLaunch): self
592
    {
593
        $this->autoLaunch = $autoLaunch;
594
595
        return $this;
596
    }
597
598
    public function getPageResultConfiguration(): array
599
    {
600
        return $this->pageResultConfiguration;
601
    }
602
603
    public function setPageResultConfiguration(array $pageResultConfiguration): self
604
    {
605
        $this->pageResultConfiguration = $pageResultConfiguration;
606
607
        return $this;
608
    }
609
610
    /**
611
     * Returns the sum of question's ponderation.
612
     */
613
    public function getMaxScore(): int
614
    {
615
        $maxScore = 0;
616
        foreach ($this->questions as $relQuestion) {
617
            $maxScore += $relQuestion->getQuestion()->getPonderation();
618
        }
619
620
        return $maxScore;
621
    }
622
623
    public function getAutoLaunch(): ?bool
624
    {
625
        return $this->autoLaunch;
626
    }
627
628
    public function getHideQuestionNumber(): ?int
629
    {
630
        return $this->hideQuestionNumber;
631
    }
632
633
    public function setHideQuestionNumber(int $hideQuestionNumber): self
634
    {
635
        $this->hideQuestionNumber = $hideQuestionNumber;
636
637
        return $this;
638
    }
639
640
    public function isHideAttemptsTable(): bool
641
    {
642
        return $this->hideAttemptsTable;
643
    }
644
645
    public function setHideAttemptsTable(bool $hideAttemptsTable): self
646
    {
647
        $this->hideAttemptsTable = $hideAttemptsTable;
648
649
        return $this;
650
    }
651
652
    /**
653
     * @return Collection<int, CQuizRelQuestionCategory>
654
     */
655
    public function getQuestionsCategories(): Collection
656
    {
657
        return $this->questionsCategories instanceof ArrayCollection ?
658
            $this->questionsCategories :
659
            new ArrayCollection($this->questionsCategories->toArray());
660
    }
661
662
    public function getDuration(): ?int
663
    {
664
        return $this->duration;
665
    }
666
667
    public function setDuration(?int $duration): self
668
    {
669
        $this->duration = $duration;
670
671
        return $this;
672
    }
673
674
    public function getResourceIdentifier(): int|Uuid
675
    {
676
        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...
677
    }
678
679
    public function getResourceName(): string
680
    {
681
        return $this->getTitle();
682
    }
683
684
    public function setResourceName(string $name): self
685
    {
686
        return $this->setTitle($name);
687
    }
688
689
    /**
690
     * @return Collection<int, TrackEExercise>
691
     */
692
    public function getAttempts(): Collection
693
    {
694
        return $this->attempts;
695
    }
696
}
697