Passed
Push — master ( 251179...3b9d17 )
by Julito
09:58
created

CQuiz::getPreventBackwards()   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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\Course;
11
use Chamilo\CoreBundle\Entity\ResourceInterface;
12
use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait;
13
use DateTime;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Doctrine\ORM\Event\LifecycleEventArgs;
17
use Doctrine\ORM\Mapping as ORM;
18
use Symfony\Component\Validator\Constraints as Assert;
19
20
/**
21
 * CQuiz.
22
 *
23
 * @ORM\Table(
24
 *     name="c_quiz",
25
 *     indexes={
26
 *         @ORM\Index(name="course", columns={"c_id"}),
27
 *         @ORM\Index(name="session_id", columns={"session_id"})
28
 *     }
29
 * )
30
 * @ORM\Entity
31
 */
32
class CQuiz extends AbstractResource implements ResourceInterface
33
{
34
    use ShowCourseResourcesInSessionTrait;
35
    public const ALL_ON_ONE_PAGE = 1;
36
    public const ONE_PER_PAGE = 2;
37
38
    /**
39
     * @ORM\Column(name="iid", type="integer")
40
     * @ORM\Id
41
     * @ORM\GeneratedValue
42
     */
43
    protected int $iid;
44
45
    /**
46
     * @ORM\Column(name="c_id", type="integer")
47
     */
48
    protected int $cId;
49
50
    /**
51
     * @Assert\NotBlank()
52
     * @ORM\Column(name="title", type="text", nullable=false)
53
     */
54
    protected string $title;
55
56
    /**
57
     * @ORM\Column(name="description", type="text", nullable=true)
58
     */
59
    protected ?string $description = null;
60
61
    /**
62
     * @ORM\Column(name="sound", type="string", length=255, nullable=true)
63
     */
64
    protected ?string $sound = null;
65
66
    /**
67
     * @ORM\Column(name="type", type="integer", nullable=false)
68
     */
69
    protected int $type;
70
71
    /**
72
     * @ORM\Column(name="random", type="integer", nullable=false)
73
     */
74
    protected int $random;
75
76
    /**
77
     * @ORM\Column(name="random_answers", type="boolean", nullable=false)
78
     */
79
    protected bool $randomAnswers;
80
81
    /**
82
     * @ORM\Column(name="active", type="boolean", nullable=false)
83
     */
84
    protected bool $active;
85
86
    /**
87
     * @ORM\Column(name="results_disabled", type="integer", nullable=false)
88
     */
89
    protected int $resultsDisabled;
90
91
    /**
92
     * @ORM\Column(name="access_condition", type="text", nullable=true)
93
     */
94
    protected ?string $accessCondition = null;
95
96
    /**
97
     * @ORM\Column(name="max_attempt", type="integer", nullable=false)
98
     */
99
    protected int $maxAttempt;
100
101
    /**
102
     * @ORM\Column(name="start_time", type="datetime", nullable=true)
103
     */
104
    protected ?DateTime $startTime = null;
105
106
    /**
107
     * @ORM\Column(name="end_time", type="datetime", nullable=true)
108
     */
109
    protected ?DateTime $endTime = null;
110
111
    /**
112
     * @ORM\Column(name="feedback_type", type="integer", nullable=false)
113
     */
114
    protected int $feedbackType;
115
116
    /**
117
     * @ORM\Column(name="expired_time", type="integer", nullable=false)
118
     */
119
    protected int $expiredTime;
120
121
    /**
122
     * @ORM\Column(name="session_id", type="integer", nullable=true)
123
     */
124
    protected ?int $sessionId = null;
125
126
    /**
127
     * @ORM\Column(name="propagate_neg", type="integer", nullable=false)
128
     */
129
    protected int $propagateNeg;
130
131
    /**
132
     * @ORm\Column(name="save_correct_answers", type="integer", nullable=true)
133
     */
134
    protected ?int $saveCorrectAnswers;
135
136
    /**
137
     * @ORM\Column(name="review_answers", type="integer", nullable=false)
138
     */
139
    protected int $reviewAnswers;
140
141
    /**
142
     * @ORM\Column(name="random_by_category", type="integer", nullable=false)
143
     */
144
    protected int $randomByCategory;
145
146
    /**
147
     * @ORM\Column(name="text_when_finished", type="text", nullable=true)
148
     */
149
    protected ?string $textWhenFinished = null;
150
151
    /**
152
     * @ORM\Column(name="display_category_name", type="integer", nullable=false)
153
     */
154
    protected int $displayCategoryName;
155
156
    /**
157
     * @ORM\Column(name="pass_percentage", type="integer", nullable=true)
158
     */
159
    protected ?int $passPercentage = null;
160
161
    /**
162
     * @ORM\Column(name="prevent_backwards", type="integer", nullable=false, options={"default":0})
163
     */
164
    protected int $preventBackwards;
165
166
    /**
167
     * @ORM\Column(name="question_selection_type", type="integer", nullable=true)
168
     */
169
    protected ?int $questionSelectionType = null;
170
171
    /**
172
     * @ORM\Column(name="hide_question_title", type="boolean", nullable=false)
173
     */
174
    protected bool $hideQuestionTitle;
175
176
    /**
177
     * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CExerciseCategory", cascade={"persist"})
178
     * @ORM\JoinColumn(name="exercise_category_id", referencedColumnName="id", onDelete="SET NULL")
179
     */
180
    protected ?CExerciseCategory $exerciseCategory = null;
181
182
    /**
183
     * @ORM\Column(name="show_previous_button", type="boolean", nullable=false, options={"default":1})
184
     */
185
    protected bool $showPreviousButton;
186
187
    /**
188
     * @ORM\Column(name="notifications", type="string", length=255, nullable=true)
189
     */
190
    protected ?string $notifications;
191
192
    /**
193
     * @ORM\Column(name="autolaunch", type="boolean", nullable=true, options={"default":0})
194
     */
195
    protected ?bool $autoLaunch;
196
197
    /**
198
     * @ORM\Column(name="page_result_configuration", type="array", nullable=true)
199
     */
200
    protected ?array $pageResultConfiguration;
201
202
    /**
203
     * @var Collection|CQuizRelQuestion[]
204
     *
205
     * @ORM\OneToMany(targetEntity="CQuizRelQuestion", mappedBy="quiz", cascade={"persist"}, orphanRemoval=true))
206
     */
207
    protected \Doctrine\Common\Collections\Collection $questions;
208
209
    /**
210
     * @var Collection|CQuizRelQuestionCategory[]
211
     *
212
     * @ORM\OneToMany(targetEntity="CQuizRelQuestionCategory", mappedBy="quiz", cascade={"persist"}))
213
     */
214
    protected \Doctrine\Common\Collections\Collection $questionsCategories;
215
216
    public function __construct()
217
    {
218
        $this->questionsCategories = new \Doctrine\Common\Collections\ArrayCollection();
219
        $this->hideQuestionTitle = false;
220
        $this->type = self::ONE_PER_PAGE;
221
        $this->showPreviousButton = true;
222
        $this->notifications = '';
223
        $this->autoLaunch = false;
224
        $this->preventBackwards = 0;
225
        $this->random = 0;
226
        $this->randomAnswers = false;
227
        $this->active = true;
228
        $this->resultsDisabled = 0;
229
        $this->maxAttempt = 1;
230
        $this->feedbackType = 0;
231
        $this->expiredTime = 0;
232
        $this->propagateNeg = 0;
233
        $this->saveCorrectAnswers = 0;
234
        $this->reviewAnswers = 0;
235
        $this->randomByCategory = 0;
236
        $this->displayCategoryName = 0;
237
        $this->pageResultConfiguration = null;
238
        $this->questions = new ArrayCollection();
239
    }
240
241
    public function __toString(): string
242
    {
243
        return $this->getTitle();
244
    }
245
246
    /**
247
     * @return Collection|CQuizRelQuestion[]
248
     */
249
    public function getQuestions()
250
    {
251
        return $this->questions;
252
    }
253
254
    public function setTitle(string $title): self
255
    {
256
        $this->title = $title;
257
258
        return $this;
259
    }
260
261
    public function getTitle(): string
262
    {
263
        return $this->title;
264
    }
265
266
    public function setDescription(string $description): self
267
    {
268
        $this->description = $description;
269
270
        return $this;
271
    }
272
273
    /**
274
     * Get description.
275
     *
276
     * @return string
277
     */
278
    public function getDescription()
279
    {
280
        return $this->description;
281
    }
282
283
    public function setSound(string $sound): self
284
    {
285
        $this->sound = $sound;
286
287
        return $this;
288
    }
289
290
    /**
291
     * Get sound.
292
     *
293
     * @return string
294
     */
295
    public function getSound()
296
    {
297
        return $this->sound;
298
    }
299
300
    public function setType(int $type): self
301
    {
302
        $this->type = $type;
303
304
        return $this;
305
    }
306
307
    public function getType(): int
308
    {
309
        return $this->type;
310
    }
311
312
    public function setRandom(int $random): self
313
    {
314
        $this->random = $random;
315
316
        return $this;
317
    }
318
319
    /**
320
     * Get random.
321
     *
322
     * @return int
323
     */
324
    public function getRandom()
325
    {
326
        return $this->random;
327
    }
328
329
    public function setRandomAnswers(bool $randomAnswers): self
330
    {
331
        $this->randomAnswers = $randomAnswers;
332
333
        return $this;
334
    }
335
336
    /**
337
     * Get randomAnswers.
338
     *
339
     * @return bool
340
     */
341
    public function getRandomAnswers()
342
    {
343
        return $this->randomAnswers;
344
    }
345
346
    public function setActive(bool $active): self
347
    {
348
        $this->active = $active;
349
350
        return $this;
351
    }
352
353
    /**
354
     * Get active.
355
     *
356
     * @return bool
357
     */
358
    public function getActive()
359
    {
360
        return $this->active;
361
    }
362
363
    public function setResultsDisabled(int $resultsDisabled): self
364
    {
365
        $this->resultsDisabled = $resultsDisabled;
366
367
        return $this;
368
    }
369
370
    /**
371
     * Get resultsDisabled.
372
     *
373
     * @return int
374
     */
375
    public function getResultsDisabled()
376
    {
377
        return $this->resultsDisabled;
378
    }
379
380
    /**
381
     * Set accessCondition.
382
     *
383
     * @return CQuiz
384
     */
385
    public function setAccessCondition(string $accessCondition)
386
    {
387
        $this->accessCondition = $accessCondition;
388
389
        return $this;
390
    }
391
392
    /**
393
     * Get accessCondition.
394
     *
395
     * @return string
396
     */
397
    public function getAccessCondition()
398
    {
399
        return $this->accessCondition;
400
    }
401
402
    /**
403
     * Set maxAttempt.
404
     *
405
     * @return CQuiz
406
     */
407
    public function setMaxAttempt(int $maxAttempt)
408
    {
409
        $this->maxAttempt = $maxAttempt;
410
411
        return $this;
412
    }
413
414
    /**
415
     * Get maxAttempt.
416
     *
417
     * @return int
418
     */
419
    public function getMaxAttempt()
420
    {
421
        return $this->maxAttempt;
422
    }
423
424
    /**
425
     * Set startTime.
426
     *
427
     * @return CQuiz
428
     */
429
    public function setStartTime(DateTime $startTime)
430
    {
431
        $this->startTime = $startTime;
432
433
        return $this;
434
    }
435
436
    /**
437
     * Get startTime.
438
     *
439
     * @return DateTime
440
     */
441
    public function getStartTime()
442
    {
443
        return $this->startTime;
444
    }
445
446
    /**
447
     * Set endTime.
448
     *
449
     * @return CQuiz
450
     */
451
    public function setEndTime(DateTime $endTime)
452
    {
453
        $this->endTime = $endTime;
454
455
        return $this;
456
    }
457
458
    /**
459
     * Get endTime.
460
     *
461
     * @return DateTime
462
     */
463
    public function getEndTime()
464
    {
465
        return $this->endTime;
466
    }
467
468
    /**
469
     * Set feedbackType.
470
     *
471
     * @return CQuiz
472
     */
473
    public function setFeedbackType(int $feedbackType)
474
    {
475
        $this->feedbackType = $feedbackType;
476
477
        return $this;
478
    }
479
480
    /**
481
     * Get feedbackType.
482
     *
483
     * @return int
484
     */
485
    public function getFeedbackType()
486
    {
487
        return $this->feedbackType;
488
    }
489
490
    /**
491
     * Set expiredTime.
492
     *
493
     * @return CQuiz
494
     */
495
    public function setExpiredTime(int $expiredTime)
496
    {
497
        $this->expiredTime = $expiredTime;
498
499
        return $this;
500
    }
501
502
    /**
503
     * Get expiredTime.
504
     *
505
     * @return int
506
     */
507
    public function getExpiredTime()
508
    {
509
        return $this->expiredTime;
510
    }
511
512
    /**
513
     * Set sessionId.
514
     *
515
     * @return CQuiz
516
     */
517
    public function setSessionId(int $sessionId)
518
    {
519
        $this->sessionId = $sessionId;
520
521
        return $this;
522
    }
523
524
    /**
525
     * Get sessionId.
526
     *
527
     * @return int
528
     */
529
    public function getSessionId()
530
    {
531
        return $this->sessionId;
532
    }
533
534
    /**
535
     * Set propagateNeg.
536
     *
537
     * @return CQuiz
538
     */
539
    public function setPropagateNeg(int $propagateNeg)
540
    {
541
        $this->propagateNeg = $propagateNeg;
542
543
        return $this;
544
    }
545
546
    /**
547
     * Get propagateNeg.
548
     *
549
     * @return int
550
     */
551
    public function getPropagateNeg()
552
    {
553
        return $this->propagateNeg;
554
    }
555
556
    /**
557
     * @return CQuiz
558
     */
559
    public function setSaveCorrectAnswers(int $saveCorrectAnswers)
560
    {
561
        $this->saveCorrectAnswers = $saveCorrectAnswers;
562
563
        return $this;
564
    }
565
566
    /**
567
     * @return int
568
     */
569
    public function getSaveCorrectAnswers()
570
    {
571
        return $this->saveCorrectAnswers;
572
    }
573
574
    /**
575
     * Set reviewAnswers.
576
     *
577
     * @return CQuiz
578
     */
579
    public function setReviewAnswers(int $reviewAnswers)
580
    {
581
        $this->reviewAnswers = $reviewAnswers;
582
583
        return $this;
584
    }
585
586
    /**
587
     * Get reviewAnswers.
588
     *
589
     * @return int
590
     */
591
    public function getReviewAnswers()
592
    {
593
        return $this->reviewAnswers;
594
    }
595
596
    /**
597
     * Set randomByCategory.
598
     *
599
     * @return CQuiz
600
     */
601
    public function setRandomByCategory(int $randomByCategory)
602
    {
603
        $this->randomByCategory = $randomByCategory;
604
605
        return $this;
606
    }
607
608
    /**
609
     * Get randomByCategory.
610
     *
611
     * @return int
612
     */
613
    public function getRandomByCategory()
614
    {
615
        return $this->randomByCategory;
616
    }
617
618
    /**
619
     * Set textWhenFinished.
620
     *
621
     * @return CQuiz
622
     */
623
    public function setTextWhenFinished(string $textWhenFinished)
624
    {
625
        $this->textWhenFinished = $textWhenFinished;
626
627
        return $this;
628
    }
629
630
    /**
631
     * Get textWhenFinished.
632
     *
633
     * @return string
634
     */
635
    public function getTextWhenFinished()
636
    {
637
        return $this->textWhenFinished;
638
    }
639
640
    /**
641
     * Set displayCategoryName.
642
     *
643
     * @return CQuiz
644
     */
645
    public function setDisplayCategoryName(int $displayCategoryName)
646
    {
647
        $this->displayCategoryName = $displayCategoryName;
648
649
        return $this;
650
    }
651
652
    /**
653
     * Get displayCategoryName.
654
     *
655
     * @return int
656
     */
657
    public function getDisplayCategoryName()
658
    {
659
        return $this->displayCategoryName;
660
    }
661
662
    /**
663
     * Set passPercentage.
664
     *
665
     * @return CQuiz
666
     */
667
    public function setPassPercentage(int $passPercentage)
668
    {
669
        $this->passPercentage = $passPercentage;
670
671
        return $this;
672
    }
673
674
    /**
675
     * Get passPercentage.
676
     *
677
     * @return int
678
     */
679
    public function getPassPercentage()
680
    {
681
        return $this->passPercentage;
682
    }
683
684
    /**
685
     * Set cId.
686
     *
687
     * @return CQuiz
688
     */
689
    public function setCId(int $cId)
690
    {
691
        $this->cId = $cId;
692
693
        return $this;
694
    }
695
696
    /**
697
     * Get cId.
698
     *
699
     * @return int
700
     */
701
    public function getCId()
702
    {
703
        return $this->cId;
704
    }
705
706
    public function getExerciseCategory(): ?CExerciseCategory
707
    {
708
        return $this->exerciseCategory;
709
    }
710
711
    public function setExerciseCategory(CExerciseCategory $exerciseCategory): self
712
    {
713
        $this->exerciseCategory = $exerciseCategory;
714
715
        return $this;
716
    }
717
718
    /**
719
     * @return int
720
     */
721
    public function getQuestionSelectionType()
722
    {
723
        return $this->questionSelectionType;
724
    }
725
726
    public function setQuestionSelectionType(int $questionSelectionType): self
727
    {
728
        $this->questionSelectionType = $questionSelectionType;
729
730
        return $this;
731
    }
732
733
    public function isHideQuestionTitle(): bool
734
    {
735
        return $this->hideQuestionTitle;
736
    }
737
738
    public function setHideQuestionTitle(bool $hideQuestionTitle): self
739
    {
740
        $this->hideQuestionTitle = $hideQuestionTitle;
741
742
        return $this;
743
    }
744
745
    public function isShowPreviousButton(): bool
746
    {
747
        return $this->showPreviousButton;
748
    }
749
750
    public function setShowPreviousButton(bool $showPreviousButton): self
751
    {
752
        $this->showPreviousButton = $showPreviousButton;
753
754
        return $this;
755
    }
756
757
    public function getNotifications(): string
758
    {
759
        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...
760
    }
761
762
    public function setNotifications(string $notifications): self
763
    {
764
        $this->notifications = $notifications;
765
766
        return $this;
767
    }
768
769
    /**
770
     * @return int
771
     */
772
    public function getIid()
773
    {
774
        return $this->iid;
775
    }
776
777
    public function getPreventBackwards(): int
778
    {
779
        return $this->preventBackwards;
780
    }
781
782
    public function setPreventBackwards(int $preventBackwards): self
783
    {
784
        $this->preventBackwards = $preventBackwards;
785
786
        return $this;
787
    }
788
789
    public function isAutoLaunch(): bool
790
    {
791
        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...
792
    }
793
794
    public function setAutoLaunch(bool $autoLaunch): self
795
    {
796
        $this->autoLaunch = $autoLaunch;
797
798
        return $this;
799
    }
800
801
    public function getPageResultConfiguration(): array
802
    {
803
        return $this->pageResultConfiguration;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->pageResultConfiguration could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
804
    }
805
806
    public function setPageResultConfiguration(?array $pageResultConfiguration): self
807
    {
808
        $this->pageResultConfiguration = $pageResultConfiguration;
809
810
        return $this;
811
    }
812
813
    /**
814
     * @ORM\PostPersist()
815
     */
816
    public function postPersist(LifecycleEventArgs $args): void
817
    {
818
    }
819
820
    /**
821
     * Returns the sum of question's ponderation.
822
     */
823
    public function getMaxScore(): int
824
    {
825
        $maxScore = 0;
826
        foreach ($this->questions as $relQuestion) {
827
            $maxScore += $relQuestion->getQuestion()->getPonderation();
828
        }
829
830
        return $maxScore;
831
    }
832
833
    public function getAutoLaunch(): ?bool
834
    {
835
        return $this->autoLaunch;
836
    }
837
838
    /**
839
     * @return CQuizRelQuestionCategory[]|Collection
840
     */
841
    public function getQuestionsCategories()
842
    {
843
        return $this->questionsCategories;
844
    }
845
846
    public function getResourceIdentifier(): int
847
    {
848
        return $this->getIid();
849
    }
850
851
    public function getResourceName(): string
852
    {
853
        return $this->getTitle();
854
    }
855
856
    public function setResourceName(string $name): self
857
    {
858
        return $this->setTitle($name);
859
    }
860
}
861