Skip to content

Commit 12da449

Browse files
authored
Quiz: #add date filter to pending exercises (#6526)
Author: @yverhenne
1 parent 3bcb5a2 commit 12da449

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed

main/exercise/pending.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
$questionTypeId = isset($_REQUEST['questionTypeId']) ? (int) $_REQUEST['questionTypeId'] : 0;
1717
$exportXls = isset($_REQUEST['export_xls']) && !empty($_REQUEST['export_xls']) ? (int) $_REQUEST['export_xls'] : 0;
1818
$action = $_REQUEST['a'] ?? null;
19+
$startDate = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : '';
20+
$endDate = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : '';
1921

2022
api_block_anonymous_users();
2123

@@ -170,6 +172,14 @@ function updateExerciseList(courseId) {
170172
}
171173
</script>';
172174

175+
$htmlHeadXtra[] = '<script>
176+
$(function() {
177+
$(".datepicker").datepicker({
178+
dateFormat: "yy-mm-dd"
179+
});
180+
});
181+
</script>';
182+
173183
if ($exportXls) {
174184
ExerciseLib::exportPendingAttemptsToExcel($_REQUEST);
175185
}
@@ -293,16 +303,27 @@ function updateExerciseList(courseId) {
293303
4 => get_lang('Unclosed'),
294304
5 => get_lang('Ongoing'),
295305
];
296-
297306
$form->addSelect('status', get_lang('Status'), $status);
298307

299308
$questionType = [
300309
0 => get_lang('All'),
301310
1 => get_lang('QuestionsWithNoAutomaticCorrection'),
302311
];
303-
304312
$form->addSelect('questionTypeId', get_lang('QuestionType'), $questionType);
305313

314+
$form->addElement(
315+
'text',
316+
'start_date',
317+
get_lang('StartDate'),
318+
['id' => 'start_date', 'class' => 'datepicker', 'autocomplete' => 'off', 'style' => 'width:120px']
319+
);
320+
$form->addElement(
321+
'text',
322+
'end_date',
323+
get_lang('EndDate'),
324+
['id' => 'end_date', 'class' => 'datepicker', 'autocomplete' => 'off', 'style' => 'width:120px']
325+
);
326+
306327
$form->addButtonSearch(get_lang('Search'), 'pendingSubmit');
307328
$content = $form->returnForm();
308329

@@ -315,7 +336,9 @@ function updateExerciseList(courseId) {
315336

316337
$url = api_get_path(WEB_AJAX_PATH).
317338
'model.ajax.php?a=get_exercise_pending_results&filter_by_user='.$filter_user.
318-
'&course_id='.$courseId.'&exercise_id='.$exerciseId.'&status='.$statusId.'&questionType='.$questionTypeId.'&showAttemptsInSessions='.$showAttemptsInSessions;
339+
'&course_id='.$courseId.'&exercise_id='.$exerciseId.'&status='.$statusId.'&questionType='.$questionTypeId.
340+
'&showAttemptsInSessions='.$showAttemptsInSessions.
341+
'&start_date='.$startDate.'&end_date='.$endDate;
319342
$action_links = '';
320343

321344
$officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
@@ -375,16 +398,6 @@ function updateExerciseList(courseId) {
375398
'align' => 'left',
376399
'search' => 'false',
377400
'sortable' => 'false',
378-
//'stype' => 'select',
379-
//for the bottom bar
380-
/*'searchoptions' => [
381-
'defaultValue' => '',
382-
'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'),
383-
],*/
384-
//for the top bar
385-
/*'editoptions' => [
386-
'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'),
387-
],*/
388401
],
389402
[
390403
'name' => 'qualificator_fullname',

main/inc/ajax/model.ajax.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,17 +643,19 @@ function getWhereClause($col, $oper, $val)
643643
true
644644
);
645645
break;
646+
646647
case 'get_exercise_pending_results':
647648
if ((false === api_is_teacher()) && (false === api_is_session_admin())) {
648649
exit;
649650
}
650-
651+
$search_start_date = isset($_REQUEST['start_date']) && !empty($_REQUEST['start_date']) ? $_REQUEST['start_date'] : null;
652+
$search_end_date = isset($_REQUEST['end_date']) && !empty($_REQUEST['end_date']) ? $_REQUEST['end_date'] : null;
651653
$courseId = $_REQUEST['course_id'] ?? 0;
652654
$exerciseId = $_REQUEST['exercise_id'] ?? 0;
653655
$status = $_REQUEST['status'] ?? 0;
654656
$questionType = $_REQUEST['questionType'] ?? 0;
655-
$showAttemptsInSessions = (bool) $_REQUEST['showAttemptsInSessions'];
656-
if (!empty($_GET['filter_by_user'])) {
657+
$showAttemptsInSessions = $_REQUEST['showAttemptsInSessions'] ? true : false;
658+
if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) {
657659
$filter_user = (int) $_GET['filter_by_user'];
658660
if (empty($whereCondition)) {
659661
$whereCondition .= " te.exe_user_id = '$filter_user'";
@@ -662,7 +664,7 @@ function getWhereClause($col, $oper, $val)
662664
}
663665
}
664666

665-
if (!empty($_GET['group_id_in_toolbar'])) {
667+
if (isset($_GET['group_id_in_toolbar']) && !empty($_GET['group_id_in_toolbar'])) {
666668
$groupIdFromToolbar = (int) $_GET['group_id_in_toolbar'];
667669
if (!empty($groupIdFromToolbar)) {
668670
if (empty($whereCondition)) {
@@ -681,6 +683,14 @@ function getWhereClause($col, $oper, $val)
681683
$whereCondition .= " AND te.c_id = $courseId";
682684
}
683685

686+
// Filtrage sur la date de fin d'exercice (exe_date)
687+
if (!empty($search_start_date)) {
688+
$whereCondition .= " AND te.exe_date >= '".Database::escape_string($search_start_date)." 00:00:00'";
689+
}
690+
if (!empty($search_end_date)) {
691+
$whereCondition .= " AND te.exe_date <= '".Database::escape_string($search_end_date)." 23:59:59'";
692+
}
693+
684694
$count = ExerciseLib::get_count_exam_results(
685695
$exerciseId,
686696
$whereCondition,

0 commit comments

Comments
 (0)