|
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
|
|
|
/** |
|
104
|
|
|
* @param CourseBuilder $courseBuilder |
|
105
|
|
|
*/ |
|
106
|
|
|
public function addPicture(CourseBuilder $courseBuilder) |
|
107
|
|
|
{ |
|
108
|
|
|
if (!empty($this->picture)) { |
|
109
|
|
|
$courseInfo = $courseBuilder->course->info; |
|
|
|
|
|
|
110
|
|
|
$courseId = $courseInfo['real_id']; |
|
111
|
|
|
$courseCode = $courseInfo['code']; |
|
112
|
|
|
$questionId = $this->source_id; |
|
113
|
|
|
$question = \Question::read($questionId, $courseId); |
|
114
|
|
|
$pictureId = $question->getPictureId(); |
|
115
|
|
|
// Add the picture document in the builder |
|
116
|
|
|
if (!empty($pictureId)) { |
|
117
|
|
|
$itemsToAdd[] = $pictureId; |
|
|
|
|
|
|
118
|
|
|
// Add the "images" folder needed for correct restore |
|
119
|
|
|
$documentData = \DocumentManager::get_document_data_by_id($pictureId, $courseCode, true); |
|
|
|
|
|
|
120
|
|
|
if ($documentData) { |
|
|
|
|
|
|
121
|
|
|
if (isset($documentData['parents'])) { |
|
122
|
|
|
foreach ($documentData['parents'] as $parent) { |
|
123
|
|
|
$itemsToAdd[] = $parent['id']; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
// Add the picture |
|
129
|
|
|
$courseBuilder->build_documents(api_get_session_id(), $courseId, false, $itemsToAdd); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Add an answer to this QuizQuestion. |
|
136
|
|
|
* |
|
137
|
|
|
* @param int $answer_id |
|
138
|
|
|
* @param string $answer_text |
|
139
|
|
|
* @param string $correct |
|
140
|
|
|
* @param string $comment |
|
141
|
|
|
* @param string $ponderation |
|
142
|
|
|
* @param string $position |
|
143
|
|
|
* @param string $hotspot_coordinates |
|
144
|
|
|
* @param string $hotspot_type |
|
145
|
|
|
*/ |
|
146
|
|
|
public function add_answer( |
|
147
|
|
|
$answer_id, |
|
148
|
|
|
$answer_text, |
|
149
|
|
|
$correct, |
|
150
|
|
|
$comment, |
|
151
|
|
|
$ponderation, |
|
152
|
|
|
$position, |
|
153
|
|
|
$hotspot_coordinates, |
|
154
|
|
|
$hotspot_type |
|
155
|
|
|
) { |
|
156
|
|
|
$answer = []; |
|
157
|
|
|
$answer['id'] = $answer_id; |
|
158
|
|
|
$answer['answer'] = $answer_text; |
|
159
|
|
|
$answer['correct'] = $correct; |
|
160
|
|
|
$answer['comment'] = $comment; |
|
161
|
|
|
$answer['ponderation'] = $ponderation; |
|
162
|
|
|
$answer['position'] = $position; |
|
163
|
|
|
$answer['hotspot_coordinates'] = $hotspot_coordinates; |
|
164
|
|
|
$answer['hotspot_type'] = $hotspot_type; |
|
165
|
|
|
$this->answers[] = $answer; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param QuizQuestionOption $option |
|
170
|
|
|
*/ |
|
171
|
|
|
public function add_option($option) |
|
172
|
|
|
{ |
|
173
|
|
|
$this->question_options[$option->obj->id] = $option; |
|
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Show this question. |
|
178
|
|
|
*/ |
|
179
|
|
|
public function show() |
|
180
|
|
|
{ |
|
181
|
|
|
parent::show(); |
|
182
|
|
|
echo $this->question; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|