1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | namespace Chamilo\CourseBundle\Component\CourseCopy\Resources; |
||
5 | |||
6 | use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder; |
||
7 | |||
8 | /** |
||
9 | * Exercises questions backup script |
||
10 | * Class QuizQuestion. |
||
11 | * |
||
12 | * @author Bart Mollet <[email protected]> |
||
13 | * |
||
14 | * @package chamilo.backup |
||
15 | */ |
||
16 | class QuizQuestion extends Resource |
||
17 | { |
||
18 | /** |
||
19 | * The question. |
||
20 | */ |
||
21 | public $question; |
||
22 | |||
23 | /** |
||
24 | * The description. |
||
25 | */ |
||
26 | public $description; |
||
27 | |||
28 | /** |
||
29 | * Ponderation. |
||
30 | */ |
||
31 | public $ponderation; |
||
32 | |||
33 | /** |
||
34 | * Type. |
||
35 | */ |
||
36 | public $quiz_type; |
||
37 | |||
38 | /** |
||
39 | * Position. |
||
40 | */ |
||
41 | public $position; |
||
42 | |||
43 | /** |
||
44 | * Level. |
||
45 | */ |
||
46 | public $level; |
||
47 | |||
48 | /** |
||
49 | * Answers. |
||
50 | */ |
||
51 | public $answers; |
||
52 | |||
53 | /** |
||
54 | * Picture. |
||
55 | */ |
||
56 | public $picture; |
||
57 | public $extra; |
||
58 | |||
59 | /** |
||
60 | * @var int the question category if any, 0 by default |
||
61 | */ |
||
62 | public $question_category; |
||
63 | |||
64 | /** |
||
65 | * QuizQuestion constructor. |
||
66 | * |
||
67 | * @param int $id |
||
68 | * @param string $question |
||
69 | * @param string $description |
||
70 | * @param int $ponderation |
||
71 | * @param $type |
||
72 | * @param $position |
||
73 | * @param string $picture |
||
74 | * @param $level |
||
75 | * @param $extra |
||
76 | * @param int $question_category |
||
77 | */ |
||
78 | public function __construct( |
||
79 | $id, |
||
80 | $question, |
||
81 | $description, |
||
82 | $ponderation, |
||
83 | $type, |
||
84 | $position, |
||
85 | $picture, |
||
86 | $level, |
||
87 | $extra, |
||
88 | $question_category = 0 |
||
89 | ) { |
||
90 | parent::__construct($id, RESOURCE_QUIZQUESTION); |
||
91 | $this->question = $question; |
||
92 | $this->description = $description; |
||
93 | $this->ponderation = $ponderation; |
||
94 | $this->quiz_type = $type; |
||
95 | $this->position = $position; |
||
96 | $this->level = $level; |
||
97 | $this->answers = []; |
||
98 | $this->extra = $extra; |
||
99 | $this->question_category = $question_category; |
||
100 | $this->picture = $picture; |
||
101 | } |
||
102 | |||
103 | public function addPicture(CourseBuilder $courseBuilder) |
||
104 | { |
||
105 | if (!empty($this->picture)) { |
||
106 | $courseInfo = $courseBuilder->course->info; |
||
107 | $courseId = $courseInfo['real_id']; |
||
108 | $courseCode = $courseInfo['code']; |
||
109 | $questionId = $this->source_id; |
||
110 | $question = \Question::read($questionId, $courseInfo); |
||
111 | $pictureId = $question->getPictureId(); |
||
112 | // Add the picture document in the builder |
||
113 | if (!empty($pictureId)) { |
||
114 | $itemsToAdd[] = $pictureId; |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
115 | // Add the "images" folder needed for correct restore |
||
116 | $documentData = \DocumentManager::get_document_data_by_id($pictureId, $courseCode, true); |
||
117 | if ($documentData) { |
||
0 ignored issues
–
show
The expression
$documentData of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using
Loading history...
|
|||
118 | if (isset($documentData['parents'])) { |
||
119 | foreach ($documentData['parents'] as $parent) { |
||
120 | $itemsToAdd[] = $parent['id']; |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | |||
125 | // Add the picture |
||
126 | $courseBuilder->build_documents(api_get_session_id(), $courseId, false, $itemsToAdd); |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Add an answer to this QuizQuestion. |
||
133 | * |
||
134 | * @param int $answer_id |
||
135 | * @param string $answer_text |
||
136 | * @param string $correct |
||
137 | * @param string $comment |
||
138 | * @param string $ponderation |
||
139 | * @param string $position |
||
140 | * @param string $hotspot_coordinates |
||
141 | * @param string $hotspot_type |
||
142 | */ |
||
143 | public function add_answer( |
||
144 | $answer_id, |
||
145 | $answer_text, |
||
146 | $correct, |
||
147 | $comment, |
||
148 | $ponderation, |
||
149 | $position, |
||
150 | $hotspot_coordinates, |
||
151 | $hotspot_type |
||
152 | ) { |
||
153 | $answer = []; |
||
154 | $answer['id'] = $answer_id; |
||
155 | $answer['answer'] = $answer_text; |
||
156 | $answer['correct'] = $correct; |
||
157 | $answer['comment'] = $comment; |
||
158 | $answer['ponderation'] = $ponderation; |
||
159 | $answer['position'] = $position; |
||
160 | $answer['hotspot_coordinates'] = $hotspot_coordinates; |
||
161 | $answer['hotspot_type'] = $hotspot_type; |
||
162 | $this->answers[] = $answer; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * @param QuizQuestionOption $option |
||
167 | */ |
||
168 | public function add_option($option) |
||
169 | { |
||
170 | $this->question_options[$option->obj->id] = $option; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Show this question. |
||
175 | */ |
||
176 | public function show() |
||
177 | { |
||
178 | parent::show(); |
||
179 | echo $this->question; |
||
180 | } |
||
181 | } |
||
182 |