Passed
Push — master ( 3b9d17...c5f69b )
by Julito
17:12
created

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