Completed
Push — master ( 3681fe...d1b22d )
by Julito
12:24
created

CQuiz::getQuestions()   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
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CourseBundle\Entity;
6
7
use Chamilo\CoreBundle\Entity\AbstractResource;
8
use Chamilo\CoreBundle\Entity\Course;
9
use Chamilo\CoreBundle\Entity\ResourceInterface;
10
use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\ORM\Event\LifecycleEventArgs;
13
use Doctrine\ORM\Mapping as ORM;
14
use Symfony\Component\Validator\Constraints as Assert;
15
16
/**
17
 * CQuiz.
18
 *
19
 * @ORM\Table(
20
 *  name="c_quiz",
21
 *  indexes={
22
 *      @ORM\Index(name="course", columns={"c_id"}),
23
 *      @ORM\Index(name="session_id", columns={"session_id"})
24
 *  }
25
 * )
26
 * @ORM\Entity
27
 */
28
class CQuiz extends AbstractResource implements ResourceInterface
29
{
30
    use ShowCourseResourcesInSessionTrait;
31
32
    /**
33
     * @var int
34
     *
35
     * @ORM\Column(name="iid", type="integer")
36
     * @ORM\Id
37
     * @ORM\GeneratedValue
38
     */
39
    protected $iid;
40
41
    /**
42
     * @var int
43
     *
44
     * @ORM\Column(name="c_id", type="integer")
45
     */
46
    protected $cId;
47
48
    /**
49
     * @var string
50
     * @Assert\NotBlank()
51
     * @ORM\Column(name="title", type="text", nullable=false)
52
     */
53
    protected $title;
54
55
    /**
56
     * @var string
57
     *
58
     * @ORM\Column(name="description", type="text", nullable=true)
59
     */
60
    protected $description;
61
62
    /**
63
     * @var string
64
     *
65
     * @ORM\Column(name="sound", type="string", length=255, nullable=true)
66
     */
67
    protected $sound;
68
69
    /**
70
     * @var int
71
     *
72
     * @ORM\Column(name="type", type="integer", nullable=false)
73
     */
74
    protected $type;
75
76
    /**
77
     * @var int
78
     *
79
     * @ORM\Column(name="random", type="integer", nullable=false)
80
     */
81
    protected $random;
82
83
    /**
84
     * @var bool
85
     *
86
     * @ORM\Column(name="random_answers", type="boolean", nullable=false)
87
     */
88
    protected $randomAnswers;
89
90
    /**
91
     * @var bool
92
     *
93
     * @ORM\Column(name="active", type="boolean", nullable=false)
94
     */
95
    protected $active;
96
97
    /**
98
     * @var int
99
     *
100
     * @ORM\Column(name="results_disabled", type="integer", nullable=false)
101
     */
102
    protected $resultsDisabled;
103
104
    /**
105
     * @var string
106
     *
107
     * @ORM\Column(name="access_condition", type="text", nullable=true)
108
     */
109
    protected $accessCondition;
110
111
    /**
112
     * @var int
113
     *
114
     * @ORM\Column(name="max_attempt", type="integer", nullable=false)
115
     */
116
    protected $maxAttempt;
117
118
    /**
119
     * @var \DateTime
120
     *
121
     * @ORM\Column(name="start_time", type="datetime", nullable=true)
122
     */
123
    protected $startTime;
124
125
    /**
126
     * @var \DateTime
127
     *
128
     * @ORM\Column(name="end_time", type="datetime", nullable=true)
129
     */
130
    protected $endTime;
131
132
    /**
133
     * @var int
134
     *
135
     * @ORM\Column(name="feedback_type", type="integer", nullable=false)
136
     */
137
    protected $feedbackType;
138
139
    /**
140
     * @var int
141
     *
142
     * @ORM\Column(name="expired_time", type="integer", nullable=false)
143
     */
144
    protected $expiredTime;
145
146
    /**
147
     * @var int
148
     *
149
     * @ORM\Column(name="session_id", type="integer", nullable=true)
150
     */
151
    protected $sessionId;
152
153
    /**
154
     * @var int
155
     *
156
     * @ORM\Column(name="propagate_neg", type="integer", nullable=false)
157
     */
158
    protected $propagateNeg;
159
160
    /**
161
     * @var int
162
     *
163
     * @ORm\Column(name="save_correct_answers", type="integer", nullable=true)
164
     */
165
    protected $saveCorrectAnswers;
166
167
    /**
168
     * @var int
169
     *
170
     * @ORM\Column(name="review_answers", type="integer", nullable=false)
171
     */
172
    protected $reviewAnswers;
173
174
    /**
175
     * @var int
176
     *
177
     * @ORM\Column(name="random_by_category", type="integer", nullable=false)
178
     */
179
    protected $randomByCategory;
180
181
    /**
182
     * @var string
183
     *
184
     * @ORM\Column(name="text_when_finished", type="text", nullable=true)
185
     */
186
    protected $textWhenFinished;
187
188
    /**
189
     * @var int
190
     *
191
     * @ORM\Column(name="display_category_name", type="integer", nullable=false)
192
     */
193
    protected $displayCategoryName;
194
195
    /**
196
     * @var int
197
     *
198
     * @ORM\Column(name="pass_percentage", type="integer", nullable=true)
199
     */
200
    protected $passPercentage;
201
202
    /**
203
     * @var int
204
     *
205
     * @ORM\Column(name="prevent_backwards", type="integer", nullable=false, options={"default":0})
206
     */
207
    protected $preventBackwards;
208
209
    /**
210
     * @var int
211
     *
212
     * @ORM\Column(name="question_selection_type", type="integer", nullable=true)
213
     */
214
    protected $questionSelectionType;
215
216
    /**
217
     * @var bool
218
     *
219
     * @ORM\Column(name="hide_question_title", type="boolean", nullable=true)
220
     */
221
    protected $hideQuestionTitle;
222
223
    /**
224
     * @var CExerciseCategory
225
     *
226
     * @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CExerciseCategory", cascade={"persist"})
227
     * @ORM\JoinColumn(name="exercise_category_id", referencedColumnName="id", onDelete="SET NULL")
228
     */
229
    protected $exerciseCategory;
230
231
    /**
232
     * @var bool
233
     *
234
     * @ORM\Column(name="show_previous_button", type="boolean", nullable=true, options={"default":1})
235
     */
236
    protected $showPreviousButton;
237
238
    /**
239
     * @var string
240
     *
241
     * @ORM\Column(name="notifications", type="string", length=255, nullable=true)
242
     */
243
    protected $notifications;
244
245
    /**
246
     * @var bool
247
     *
248
     * @ORM\Column(name="autolaunch", type="boolean", nullable=true, options={"default":0})
249
     */
250
    protected $autoLaunch;
251
252
    /**
253
     * @var int
254
     *
255
     * @ORM\Column(name="page_result_configuration", type="array", nullable=true)
256
     */
257
    protected $pageResultConfiguration;
258
259
    /**
260
     * @var CQuizRelQuestion[]|ArrayCollection
261
     *
262
     * @ORM\OneToMany(targetEntity="Chamilo\CourseBundle\Entity\CQuizRelQuestion", mappedBy="quiz", cascade={"persist"}, orphanRemoval=true))
263
     */
264
    protected $questions;
265
266
    /**
267
     * CQuiz constructor.
268
     */
269
    public function __construct()
270
    {
271
        $this->hideQuestionTitle = false;
272
        $this->type = ONE_PER_PAGE;
273
        $this->showPreviousButton = true;
274
        $this->notifications = '';
275
        $this->autoLaunch = 0;
0 ignored issues
show
Documentation Bug introduced by
The property $autoLaunch was declared of type boolean, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
276
        $this->preventBackwards = 0;
277
        $this->random = 0;
278
        $this->randomAnswers = false;
279
        $this->active = true;
280
        $this->resultsDisabled = 0;
281
        $this->maxAttempt = 1;
282
        $this->feedbackType = 0;
283
        $this->expiredTime = 0;
284
        $this->propagateNeg = 0;
285
        $this->saveCorrectAnswers = false;
0 ignored issues
show
Documentation Bug introduced by
The property $saveCorrectAnswers was declared of type integer, but false is of type false. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
286
        $this->reviewAnswers = 0;
287
        $this->randomByCategory = 0;
288
        $this->displayCategoryName = 0;
289
        $this->questions = new ArrayCollection();
290
    }
291
292
    public function __toString(): string
293
    {
294
        return $this->getTitle();
295
    }
296
297
    /**
298
     * @return CQuizRelQuestion[]|ArrayCollection
299
     */
300
    public function getQuestions()
301
    {
302
        return $this->questions;
303
    }
304
305
    /**
306
     * Set title.
307
     *
308
     * @param string $title
309
     *
310
     * @return CQuiz
311
     */
312
    public function setTitle($title)
313
    {
314
        $this->title = $title;
315
316
        return $this;
317
    }
318
319
    /**
320
     * Get title.
321
     *
322
     * @return string
323
     */
324
    public function getTitle()
325
    {
326
        return (string) $this->title;
327
    }
328
329
    /**
330
     * Set description.
331
     *
332
     * @param string $description
333
     *
334
     * @return CQuiz
335
     */
336
    public function setDescription($description)
337
    {
338
        $this->description = $description;
339
340
        return $this;
341
    }
342
343
    /**
344
     * Get description.
345
     *
346
     * @return string
347
     */
348
    public function getDescription()
349
    {
350
        return $this->description;
351
    }
352
353
    /**
354
     * Set sound.
355
     *
356
     * @param string $sound
357
     *
358
     * @return CQuiz
359
     */
360
    public function setSound($sound)
361
    {
362
        $this->sound = $sound;
363
364
        return $this;
365
    }
366
367
    /**
368
     * Get sound.
369
     *
370
     * @return string
371
     */
372
    public function getSound()
373
    {
374
        return $this->sound;
375
    }
376
377
    /**
378
     * Set type.
379
     */
380
    public function setType(int $type): self
381
    {
382
        $this->type = $type;
383
384
        return $this;
385
    }
386
387
    /**
388
     * Get type.
389
     */
390
    public function getType(): int
391
    {
392
        return $this->type;
393
    }
394
395
    /**
396
     * Set random.
397
     *
398
     * @param int $random
399
     *
400
     * @return CQuiz
401
     */
402
    public function setRandom($random)
403
    {
404
        $this->random = $random;
405
406
        return $this;
407
    }
408
409
    /**
410
     * Get random.
411
     *
412
     * @return int
413
     */
414
    public function getRandom()
415
    {
416
        return $this->random;
417
    }
418
419
    /**
420
     * Set randomAnswers.
421
     *
422
     * @param bool $randomAnswers
423
     *
424
     * @return CQuiz
425
     */
426
    public function setRandomAnswers($randomAnswers)
427
    {
428
        $this->randomAnswers = $randomAnswers;
429
430
        return $this;
431
    }
432
433
    /**
434
     * Get randomAnswers.
435
     *
436
     * @return bool
437
     */
438
    public function getRandomAnswers()
439
    {
440
        return $this->randomAnswers;
441
    }
442
443
    /**
444
     * Set active.
445
     *
446
     * @param bool $active
447
     *
448
     * @return CQuiz
449
     */
450
    public function setActive($active)
451
    {
452
        $this->active = $active;
453
454
        return $this;
455
    }
456
457
    /**
458
     * Get active.
459
     *
460
     * @return bool
461
     */
462
    public function getActive()
463
    {
464
        return $this->active;
465
    }
466
467
    /**
468
     * Set resultsDisabled.
469
     *
470
     * @param int $resultsDisabled
471
     *
472
     * @return CQuiz
473
     */
474
    public function setResultsDisabled($resultsDisabled)
475
    {
476
        $this->resultsDisabled = $resultsDisabled;
477
478
        return $this;
479
    }
480
481
    /**
482
     * Get resultsDisabled.
483
     *
484
     * @return int
485
     */
486
    public function getResultsDisabled()
487
    {
488
        return $this->resultsDisabled;
489
    }
490
491
    /**
492
     * Set accessCondition.
493
     *
494
     * @param string $accessCondition
495
     *
496
     * @return CQuiz
497
     */
498
    public function setAccessCondition($accessCondition)
499
    {
500
        $this->accessCondition = $accessCondition;
501
502
        return $this;
503
    }
504
505
    /**
506
     * Get accessCondition.
507
     *
508
     * @return string
509
     */
510
    public function getAccessCondition()
511
    {
512
        return $this->accessCondition;
513
    }
514
515
    /**
516
     * Set maxAttempt.
517
     *
518
     * @param int $maxAttempt
519
     *
520
     * @return CQuiz
521
     */
522
    public function setMaxAttempt($maxAttempt)
523
    {
524
        $this->maxAttempt = $maxAttempt;
525
526
        return $this;
527
    }
528
529
    /**
530
     * Get maxAttempt.
531
     *
532
     * @return int
533
     */
534
    public function getMaxAttempt()
535
    {
536
        return $this->maxAttempt;
537
    }
538
539
    /**
540
     * Set startTime.
541
     *
542
     * @param \DateTime $startTime
543
     *
544
     * @return CQuiz
545
     */
546
    public function setStartTime($startTime)
547
    {
548
        $this->startTime = $startTime;
549
550
        return $this;
551
    }
552
553
    /**
554
     * Get startTime.
555
     *
556
     * @return \DateTime
557
     */
558
    public function getStartTime()
559
    {
560
        return $this->startTime;
561
    }
562
563
    /**
564
     * Set endTime.
565
     *
566
     * @param \DateTime $endTime
567
     *
568
     * @return CQuiz
569
     */
570
    public function setEndTime($endTime)
571
    {
572
        $this->endTime = $endTime;
573
574
        return $this;
575
    }
576
577
    /**
578
     * Get endTime.
579
     *
580
     * @return \DateTime
581
     */
582
    public function getEndTime()
583
    {
584
        return $this->endTime;
585
    }
586
587
    /**
588
     * Set feedbackType.
589
     *
590
     * @param int $feedbackType
591
     *
592
     * @return CQuiz
593
     */
594
    public function setFeedbackType($feedbackType)
595
    {
596
        $this->feedbackType = $feedbackType;
597
598
        return $this;
599
    }
600
601
    /**
602
     * Get feedbackType.
603
     *
604
     * @return int
605
     */
606
    public function getFeedbackType()
607
    {
608
        return $this->feedbackType;
609
    }
610
611
    /**
612
     * Set expiredTime.
613
     *
614
     * @param int $expiredTime
615
     *
616
     * @return CQuiz
617
     */
618
    public function setExpiredTime($expiredTime)
619
    {
620
        $this->expiredTime = $expiredTime;
621
622
        return $this;
623
    }
624
625
    /**
626
     * Get expiredTime.
627
     *
628
     * @return int
629
     */
630
    public function getExpiredTime()
631
    {
632
        return $this->expiredTime;
633
    }
634
635
    /**
636
     * Set sessionId.
637
     *
638
     * @param int $sessionId
639
     *
640
     * @return CQuiz
641
     */
642
    public function setSessionId($sessionId)
643
    {
644
        $this->sessionId = $sessionId;
645
646
        return $this;
647
    }
648
649
    /**
650
     * Get sessionId.
651
     *
652
     * @return int
653
     */
654
    public function getSessionId()
655
    {
656
        return $this->sessionId;
657
    }
658
659
    /**
660
     * Set propagateNeg.
661
     *
662
     * @param int $propagateNeg
663
     *
664
     * @return CQuiz
665
     */
666
    public function setPropagateNeg($propagateNeg)
667
    {
668
        $this->propagateNeg = $propagateNeg;
669
670
        return $this;
671
    }
672
673
    /**
674
     * Get propagateNeg.
675
     *
676
     * @return int
677
     */
678
    public function getPropagateNeg()
679
    {
680
        return $this->propagateNeg;
681
    }
682
683
    /**
684
     * @param int $saveCorrectAnswers
685
     *
686
     * @return CQuiz
687
     */
688
    public function setSaveCorrectAnswers($saveCorrectAnswers)
689
    {
690
        $this->saveCorrectAnswers = $saveCorrectAnswers;
691
692
        return $this;
693
    }
694
695
    /**
696
     * @return int
697
     */
698
    public function getSaveCorrectAnswers()
699
    {
700
        return $this->saveCorrectAnswers;
701
    }
702
703
    /**
704
     * Set reviewAnswers.
705
     *
706
     * @param int $reviewAnswers
707
     *
708
     * @return CQuiz
709
     */
710
    public function setReviewAnswers($reviewAnswers)
711
    {
712
        $this->reviewAnswers = $reviewAnswers;
713
714
        return $this;
715
    }
716
717
    /**
718
     * Get reviewAnswers.
719
     *
720
     * @return int
721
     */
722
    public function getReviewAnswers()
723
    {
724
        return $this->reviewAnswers;
725
    }
726
727
    /**
728
     * Set randomByCategory.
729
     *
730
     * @param int $randomByCategory
731
     *
732
     * @return CQuiz
733
     */
734
    public function setRandomByCategory($randomByCategory)
735
    {
736
        $this->randomByCategory = $randomByCategory;
737
738
        return $this;
739
    }
740
741
    /**
742
     * Get randomByCategory.
743
     *
744
     * @return int
745
     */
746
    public function getRandomByCategory()
747
    {
748
        return $this->randomByCategory;
749
    }
750
751
    /**
752
     * Set textWhenFinished.
753
     *
754
     * @param string $textWhenFinished
755
     *
756
     * @return CQuiz
757
     */
758
    public function setTextWhenFinished($textWhenFinished)
759
    {
760
        $this->textWhenFinished = $textWhenFinished;
761
762
        return $this;
763
    }
764
765
    /**
766
     * Get textWhenFinished.
767
     *
768
     * @return string
769
     */
770
    public function getTextWhenFinished()
771
    {
772
        return $this->textWhenFinished;
773
    }
774
775
    /**
776
     * Set displayCategoryName.
777
     *
778
     * @param int $displayCategoryName
779
     *
780
     * @return CQuiz
781
     */
782
    public function setDisplayCategoryName($displayCategoryName)
783
    {
784
        $this->displayCategoryName = $displayCategoryName;
785
786
        return $this;
787
    }
788
789
    /**
790
     * Get displayCategoryName.
791
     *
792
     * @return int
793
     */
794
    public function getDisplayCategoryName()
795
    {
796
        return $this->displayCategoryName;
797
    }
798
799
    /**
800
     * Set passPercentage.
801
     *
802
     * @param int $passPercentage
803
     *
804
     * @return CQuiz
805
     */
806
    public function setPassPercentage($passPercentage)
807
    {
808
        $this->passPercentage = $passPercentage;
809
810
        return $this;
811
    }
812
813
    /**
814
     * Get passPercentage.
815
     *
816
     * @return int
817
     */
818
    public function getPassPercentage()
819
    {
820
        return $this->passPercentage;
821
    }
822
823
    /**
824
     * Set cId.
825
     *
826
     * @param int $cId
827
     *
828
     * @return CQuiz
829
     */
830
    public function setCId($cId)
831
    {
832
        $this->cId = $cId;
833
834
        return $this;
835
    }
836
837
    /**
838
     * Get cId.
839
     *
840
     * @return int
841
     */
842
    public function getCId()
843
    {
844
        return $this->cId;
845
    }
846
847
    /**
848
     * @return CExerciseCategory
849
     */
850
    public function getExerciseCategory(): ?CExerciseCategory
851
    {
852
        return $this->exerciseCategory;
853
    }
854
855
    public function setExerciseCategory(CExerciseCategory $exerciseCategory): self
856
    {
857
        $this->exerciseCategory = $exerciseCategory;
858
859
        return $this;
860
    }
861
862
    /**
863
     * @return int
864
     */
865
    public function getQuestionSelectionType()
866
    {
867
        return $this->questionSelectionType;
868
    }
869
870
    /**
871
     * @param int $questionSelectionType
872
     *
873
     * @return CQuiz
874
     */
875
    public function setQuestionSelectionType($questionSelectionType)
876
    {
877
        $this->questionSelectionType = $questionSelectionType;
878
879
        return $this;
880
    }
881
882
    /**
883
     * @return bool
884
     */
885
    public function isHideQuestionTitle()
886
    {
887
        return $this->hideQuestionTitle;
888
    }
889
890
    /**
891
     * @param bool $hideQuestionTitle
892
     *
893
     * @return CQuiz
894
     */
895
    public function setHideQuestionTitle($hideQuestionTitle)
896
    {
897
        $this->hideQuestionTitle = $hideQuestionTitle;
898
899
        return $this;
900
    }
901
902
    public function isShowPreviousButton(): bool
903
    {
904
        return $this->showPreviousButton;
905
    }
906
907
    public function setShowPreviousButton(bool $showPreviousButton): self
908
    {
909
        $this->showPreviousButton = $showPreviousButton;
910
911
        return $this;
912
    }
913
914
    public function getNotifications(): string
915
    {
916
        return $this->notifications;
917
    }
918
919
    public function setNotifications(string $notifications): self
920
    {
921
        $this->notifications = $notifications;
922
923
        return $this;
924
    }
925
926
    /**
927
     * @return int
928
     */
929
    public function getIid()
930
    {
931
        return $this->iid;
932
    }
933
934
    public function getPreventBackwards(): int
935
    {
936
        return $this->preventBackwards;
937
    }
938
939
    public function setPreventBackwards(int $preventBackwards): self
940
    {
941
        $this->preventBackwards = $preventBackwards;
942
943
        return $this;
944
    }
945
946
    public function isAutoLaunch(): bool
947
    {
948
        return $this->autoLaunch;
949
    }
950
951
    public function setAutoLaunch(bool $autoLaunch): self
952
    {
953
        $this->autoLaunch = $autoLaunch;
954
955
        return $this;
956
    }
957
958
    public function getPageResultConfiguration(): int
959
    {
960
        return $this->pageResultConfiguration;
961
    }
962
963
    public function setPageResultConfiguration(int $pageResultConfiguration): self
964
    {
965
        $this->pageResultConfiguration = $pageResultConfiguration;
966
967
        return $this;
968
    }
969
970
    /**
971
     * @ORM\PostPersist()
972
     */
973
    public function postPersist(LifecycleEventArgs $args)
974
    {
975
    }
976
977
    /**
978
     * Returns the sum of question's ponderation.
979
     */
980
    public function getMaxScore(): int
981
    {
982
        $maxScore = 0;
983
        foreach ($this->questions as $relQuestion) {
984
            $maxScore += $relQuestion->getQuestion()->getPonderation();
985
        }
986
987
        return $maxScore;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $maxScore could return the type double which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
988
    }
989
990
    /**
991
     * Resource identifier.
992
     */
993
    public function getResourceIdentifier(): int
994
    {
995
        return $this->getIid();
996
    }
997
998
    public function getResourceName(): string
999
    {
1000
        return $this->getTitle();
1001
    }
1002
1003
    public function setResourceName(string $name): self
1004
    {
1005
        return $this->setTitle($name);
1006
    }
1007
}
1008