/
question_list_admin.inc.php
executable file
·373 lines (336 loc) · 14.6 KB
/
question_list_admin.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* Code library for HotPotatoes integration.
*
* @package chamilo.exercise
*
* @author Olivier Brouckaert & Julio Montoya & Hubert Borderiou 21-10-2011 (Question by category)
* QUESTION LIST ADMINISTRATION
*
* This script allows to manage the question list
* It is included from the script admin.php
*/
$limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
// deletes a question from the exercise (not from the data base)
if ($deleteQuestion) {
if ($limitTeacherAccess && !api_is_platform_admin()) {
exit;
}
// if the question exists
if ($objQuestionTmp = Question::read($deleteQuestion)) {
$objQuestionTmp->delete($exerciseId);
// if the question has been removed from the exercise
if ($objExercise->removeFromList($deleteQuestion)) {
$nbrQuestions--;
}
}
// destruction of the Question object
unset($objQuestionTmp);
}
$ajax_url = api_get_path(WEB_AJAX_PATH)."exercise.ajax.php?".api_get_cidreq()."&exercise_id=".intval($exerciseId);
?>
<div id="dialog-confirm"
title="<?php echo get_lang('ConfirmYourChoice'); ?>"
style="display:none;">
<p>
<?php echo get_lang('AreYouSureToDelete'); ?>
</p>
</div>
<script>
$(function () {
$("#dialog:ui-dialog").dialog("destroy");
$("#dialog-confirm").dialog({
autoOpen: false,
show: "blind",
resizable: false,
height: 150,
modal: false
});
$(".opener").click(function () {
var targetUrl = $(this).attr("href");
$("#dialog-confirm").dialog({
modal: true,
buttons: {
"<?php echo get_lang("Yes"); ?>": function () {
location.href = targetUrl;
$(this).dialog("close");
},
"<?php echo get_lang("No"); ?>": function () {
$(this).dialog("close");
}
}
});
$("#dialog-confirm").dialog("open");
return false;
});
var stop = false;
$("#question_list h3").click(function (event) {
if (stop) {
event.stopImmediatePropagation();
event.preventDefault();
stop = false;
}
});
/* We can add links in the accordion header */
$(".btn-actions .edition a.btn").click(function () {
//Avoid the redirecto when selecting the delete button
if (this.id.indexOf('delete') == -1) {
newWind = window.open(this.href, "_self");
newWind.focus();
return false;
}
});
$("#question_list").accordion({
icons: null,
heightStyle: "content",
active: false, // all items closed by default
collapsible: true,
header: ".header_operations",
beforeActivate: function (e, ui) {
var data = ui.newHeader.data();
if (typeof data === 'undefined') {
return;
}
var exerciseId = data.exercise || 0,
questionId = data.question || 0;
if (!questionId || !exerciseId) {
return;
}
var $pnlQuestion = $('#pnl-question-' + questionId);
if ($pnlQuestion.html().trim().length) {
return;
}
$pnlQuestion.html('<span class="fa fa-spinner fa-spin fa-3x fa-fw" aria-hidden="true"></span>');
$.get('<?php echo api_get_path(WEB_AJAX_PATH); ?>exercise.ajax.php?<?php echo api_get_cidreq(); ?>', {
a: 'show_question',
exercise: exerciseId,
question: questionId
}, function (response) {
$pnlQuestion.html(response)
});
}
})
.sortable({
cursor: "move", // works?
update: function (event, ui) {
var order = $(this).sortable("serialize") + "&a=update_question_order&exercise_id=<?php echo $exerciseId; ?>";
$.post("<?php echo $ajax_url; ?>", order, function (result) {
$("#message").html(result);
});
},
axis: "y",
placeholder: "ui-state-highlight", //defines the yellow highlight
handle: ".moved", //only the class "moved"
stop: function () {
stop = true;
}
});
});
</script>
<?php
//we filter the type of questions we can add
Question::display_type_menu($objExercise);
// Re sets the question list
$objExercise->setQuestionList();
echo '<div id="message"></div>';
$token = Security::get_token();
//deletes a session when using don't know question type (ugly fix)
Session::erase('less_answer');
// If we are in a test
$inATest = isset($exerciseId) && $exerciseId > 0;
if (!$inATest) {
echo "<div class='alert alert-warning'>".get_lang('ChoiceQuestionType')."</div>";
} else {
if ($nbrQuestions) {
// In the building exercise mode show question list ordered as is.
$objExercise->setCategoriesGrouping(false);
// In building mode show all questions not render by teacher order.
$objExercise->questionSelectionType = EX_Q_SELECTION_ORDERED;
$alloQuestionOrdering = true;
$showPagination = api_get_configuration_value('show_question_pagination');
if (!empty($showPagination) && $nbrQuestions > $showPagination) {
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$lenght = api_get_configuration_value('question_pagination_lenght');
$url = api_get_self().'?'.api_get_cidreq();
// Use pagination for exercise with more than 200 questions.
$alloQuestionOrdering = false;
$start = ($page - 1) * $lenght;
$questionList = $objExercise->getQuestionForTeacher($start, $lenght);
$paginator = new Knp\Component\Pager\Paginator();
$pagination = $paginator->paginate([]);
$pagination->setTotalItemCount($nbrQuestions);
$pagination->setItemNumberPerPage($lenght);
$pagination->setCurrentPageNumber($page);
$pagination->renderer = function ($data) use ($url) {
$render = '<ul class="pagination">';
for ($i = 1; $i <= $data['pageCount']; $i++) {
//foreach ($data['pagesInRange'] as $page) {
$page = (int) $i;
$pageContent = '<li><a href="'.$url.'&page='.$page.'">'.$page.'</a></li>';
if ($data['current'] == $page) {
$pageContent = '<li class="active"><a href="#" >'.$page.'</a></li>';
}
$render .= $pageContent;
}
$render .= '</ul>';
return $render;
};
echo $pagination;
} else {
// Classic order
$questionList = $objExercise->selectQuestionList(true, true);
}
echo '
<div class="row hidden-xs">
<div class="col-sm-5"><strong>'.get_lang('Questions').'</strong></div>
<div class="col-sm-1 text-center"><strong>'.get_lang('Type').'</strong></div>
<div class="col-sm-2"><strong>'.get_lang('Category').'</strong></div>
<div class="col-sm-1 text-right"><strong>'.get_lang('Difficulty').'</strong></div>
<div class="col-sm-1 text-right"><strong>'.get_lang('MaximumScore').'</strong></div>
<div class="col-sm-2 text-right"><strong>'.get_lang('Actions').'</strong></div>
</div>
<div id="question_list">
';
$category_list = TestCategory::getListOfCategoriesNameForTest($objExercise->id, false);
if (is_array($questionList)) {
foreach ($questionList as $id) {
//To avoid warning messages
if (!is_numeric($id)) {
continue;
}
/** @var Question $objQuestionTmp */
$objQuestionTmp = Question::read($id);
$clone_link = Display::url(
Display::return_icon(
'cd.png',
get_lang('Copy'),
[],
ICON_SIZE_TINY
),
api_get_self().'?'.api_get_cidreq().'&clone_question='.$id,
['class' => 'btn btn-default btn-sm']
);
$edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered())
? Display::span(
Display::return_icon(
'edit_na.png',
get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'),
[],
ICON_SIZE_TINY
),
['class' => 'btn btn-default btn-sm']
)
: Display::url(
Display::return_icon(
'edit.png',
get_lang('Modify'),
[],
ICON_SIZE_TINY
),
api_get_self().'?'.api_get_cidreq().'&'
.http_build_query([
'type' => $objQuestionTmp->selectType(),
'myid' => 1,
'editQuestion' => $id,
]),
['class' => 'btn btn-default btn-sm']
);
$delete_link = null;
if ($objExercise->edit_exercise_in_lp == true) {
$delete_link = Display::url(
Display::return_icon(
'delete.png',
get_lang('RemoveFromTest'),
[],
ICON_SIZE_TINY
),
api_get_self().'?'.api_get_cidreq().'&'
.http_build_query([
'exerciseId' => $exerciseId,
'deleteQuestion' => $id,
]),
[
'id' => "delete_$id",
'class' => 'opener btn btn-default btn-sm',
]
);
}
if ($limitTeacherAccess && !api_is_platform_admin()) {
$delete_link = '';
}
$btnActions = implode(
PHP_EOL,
[$edit_link, $clone_link, $delete_link]
);
$title = Security::remove_XSS($objQuestionTmp->selectTitle());
$title = strip_tags($title);
$move = ' ';
if ($alloQuestionOrdering) {
$move = Display::returnFontAwesomeIcon('arrows moved', 1, true);
}
// Question name
$questionName =
'<a href="#" title = "'.Security::remove_XSS($title).'">
'.$move.' '.cut($title, 42).'
</a>';
// Question type
list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
$questionType = Display::return_icon($typeImg, $typeExpl);
// Question category
$txtQuestionCat = Security::remove_XSS(
TestCategory::getCategoryNameForQuestion($objQuestionTmp->id)
);
if (empty($txtQuestionCat)) {
$txtQuestionCat = "-";
}
// Question level
$txtQuestionLevel = $objQuestionTmp->level;
if (empty($objQuestionTmp->level)) {
$txtQuestionLevel = '-';
}
$questionLevel = $txtQuestionLevel;
// Question score
$questionScore = $objQuestionTmp->selectWeighting();
echo '
<div id="question_id_list_'.$id.'">
<div class="header_operations" data-exercise="'.$objExercise->selectId().'"
data-question="'.$id.'">
<div class="row">
<div class="question col-sm-5 col-xs-12">'
.$questionName.'
</div>
<div class="type text-center col-sm-1 col-xs-12">
<span class="visible-xs-inline">'.get_lang('Type').' </span>'
.$questionType.'
</div>
<div class="category col-sm-2 col-xs-12" title="'.$txtQuestionCat.'">
<span class="visible-xs-inline">'.get_lang('Category').' </span>'
.cut($txtQuestionCat, 42).'
</div>
<div class="level text-right col-sm-1 col-xs-6">
<span class="visible-xs-inline">'.get_lang('Difficulty').' </span>'
.$questionLevel.'
</div>
<div class="score text-right col-sm-1 col-xs-6">
<span class="visible-xs-inline">'.get_lang('Score').' </span>'
.$questionScore.'
</div>
<div class="btn-actions text-right col-sm-2 col-xs-6">
<div class="edition">'.$btnActions.'</div>
</div>
</div>
</div>
<div class="question-list-description-block" id="pnl-question-'.$id.'">
</div>
</div>
';
unset($objQuestionTmp);
}
}
} else {
echo Display::return_message(get_lang('NoQuestion'), 'warning');
}
echo '</div>'; //question list div
}