From c50d93b10b02dffccc8c94ba24415aad8de9fa9a Mon Sep 17 00:00:00 2001 From: Yannick VERHENNE Date: Sat, 26 Jul 2025 10:21:15 +0200 Subject: [PATCH 1/7] add-date-filter-to-pending.php --- main/exercise/pending.php | 41 ++++++++++++++--------- main/inc/ajax/model.ajax.php | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 15 deletions(-) diff --git a/main/exercise/pending.php b/main/exercise/pending.php index 2cc0d02a2ac..85ff56576a3 100644 --- a/main/exercise/pending.php +++ b/main/exercise/pending.php @@ -16,6 +16,8 @@ $questionTypeId = isset($_REQUEST['questionTypeId']) ? (int) $_REQUEST['questionTypeId'] : 0; $exportXls = isset($_REQUEST['export_xls']) && !empty($_REQUEST['export_xls']) ? (int) $_REQUEST['export_xls'] : 0; $action = $_REQUEST['a'] ?? null; +$startDate = isset($_REQUEST['start_date']) ? $_REQUEST['start_date'] : ''; +$endDate = isset($_REQUEST['end_date']) ? $_REQUEST['end_date'] : ''; api_block_anonymous_users(); @@ -170,6 +172,14 @@ function updateExerciseList(courseId) { } '; +$htmlHeadXtra[] = ''; + if ($exportXls) { ExerciseLib::exportPendingAttemptsToExcel($_REQUEST); } @@ -293,16 +303,27 @@ function updateExerciseList(courseId) { 4 => get_lang('Unclosed'), 5 => get_lang('Ongoing'), ]; - $form->addSelect('status', get_lang('Status'), $status); $questionType = [ 0 => get_lang('All'), 1 => get_lang('QuestionsWithNoAutomaticCorrection'), ]; - $form->addSelect('questionTypeId', get_lang('QuestionType'), $questionType); +$form->addElement( + 'text', + 'start_date', + get_lang('StartDate'), + ['id' => 'start_date', 'class' => 'datepicker', 'autocomplete' => 'off', 'style' => 'width:120px'] +); +$form->addElement( + 'text', + 'end_date', + get_lang('EndDate'), + ['id' => 'end_date', 'class' => 'datepicker', 'autocomplete' => 'off', 'style' => 'width:120px'] +); + $form->addButtonSearch(get_lang('Search'), 'pendingSubmit'); $content = $form->returnForm(); @@ -315,7 +336,9 @@ function updateExerciseList(courseId) { $url = api_get_path(WEB_AJAX_PATH). 'model.ajax.php?a=get_exercise_pending_results&filter_by_user='.$filter_user. - '&course_id='.$courseId.'&exercise_id='.$exerciseId.'&status='.$statusId.'&questionType='.$questionTypeId.'&showAttemptsInSessions='.$showAttemptsInSessions; + '&course_id='.$courseId.'&exercise_id='.$exerciseId.'&status='.$statusId.'&questionType='.$questionTypeId. + '&showAttemptsInSessions='.$showAttemptsInSessions. + '&start_date='.$startDate.'&end_date='.$endDate; $action_links = ''; $officialCodeInList = api_get_setting('show_official_code_exercise_result_list'); @@ -375,16 +398,6 @@ function updateExerciseList(courseId) { 'align' => 'left', 'search' => 'false', 'sortable' => 'false', - //'stype' => 'select', - //for the bottom bar - /*'searchoptions' => [ - 'defaultValue' => '', - 'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'), - ],*/ - //for the top bar - /*'editoptions' => [ - 'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'), - ],*/ ], [ 'name' => 'qualificator_fullname', @@ -427,8 +440,6 @@ function action_formatter(cellvalue, options, rowObject) { // rowObject is firstname,lastname,login,... get the third word var loginx = "'.api_htmlentities(sprintf(get_lang('LoginX'), ':::'), ENT_QUOTES).'"; var tabLoginx = loginx.split(/:::/); - // tabLoginx[0] is before and tabLoginx[1] is after ::: - // may be empty string but is defined return ""+cellvalue+""; }'; diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 40e6bcf15da..9dc6acc535c 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -6,6 +6,10 @@ require_once __DIR__.'/../global.inc.php'; +// --- FILTRES DATE --- +$search_start_date = isset($_REQUEST['start_date']) && !empty($_REQUEST['start_date']) ? $_REQUEST['start_date'] : null; +$search_end_date = isset($_REQUEST['end_date']) && !empty($_REQUEST['end_date']) ? $_REQUEST['end_date'] : null; + // 1. Setting variables needed by jqgrid $action = $_GET['a']; $page = (int) $_REQUEST['page']; //page @@ -662,6 +666,66 @@ function getWhereClause($col, $oper, $val) } } + case 'get_exercise_pending_results': + if ((false === api_is_teacher()) && (false === api_is_session_admin())) { + exit; + } + + $courseId = $_REQUEST['course_id'] ?? 0; + $exerciseId = $_REQUEST['exercise_id'] ?? 0; + $status = $_REQUEST['status'] ?? 0; + $questionType = $_REQUEST['questionType'] ?? 0; + $showAttemptsInSessions = $_REQUEST['showAttemptsInSessions'] ? true : false; + if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) { + $filter_user = (int) $_GET['filter_by_user']; + if (empty($whereCondition)) { + $whereCondition .= " te.exe_user_id = '$filter_user'"; + } else { + $whereCondition .= " AND te.exe_user_id = '$filter_user'"; + } + } + + if (isset($_GET['group_id_in_toolbar']) && !empty($_GET['group_id_in_toolbar'])) { + $groupIdFromToolbar = (int) $_GET['group_id_in_toolbar']; + if (!empty($groupIdFromToolbar)) { + if (empty($whereCondition)) { + $whereCondition .= " te.group_id = '$groupIdFromToolbar'"; + } else { + $whereCondition .= " AND group_id = '$groupIdFromToolbar'"; + } + } + } + + if (!empty($whereCondition)) { + $whereCondition = " AND $whereCondition"; + } + + if (!empty($courseId)) { + $whereCondition .= " AND te.c_id = $courseId"; + } + + // Filtrage sur la date de fin d'exercice (exe_date) +if (!empty($search_start_date)) { + $whereCondition .= " AND te.exe_date >= '".Database::escape_string($search_start_date)." 00:00:00'"; +} +if (!empty($search_end_date)) { + $whereCondition .= " AND te.exe_date <= '".Database::escape_string($search_end_date)." 23:59:59'"; +} + // ------------------------------- + $count = ExerciseLib::get_count_exam_results( + $exerciseId, + $whereCondition, + '', + false, + true, + $status, + $showAttemptsInSessions, + $questionType, + true + ); + + break; + if (!empty($_GET['group_id_in_toolbar'])) { $groupIdFromToolbar = (int) $_GET['group_id_in_toolbar']; if (!empty($groupIdFromToolbar)) { From ffc991dac1421f3e16cde920ddaa797502f4551d Mon Sep 17 00:00:00 2001 From: yverhenne <129364360+yverhenne@users.noreply.github.com> Date: Tue, 29 Jul 2025 14:01:47 +0200 Subject: [PATCH 2/7] Update model.ajax.php --- main/inc/ajax/model.ajax.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 9dc6acc535c..e2d28a0d95a 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -647,24 +647,6 @@ function getWhereClause($col, $oper, $val) true ); break; - case 'get_exercise_pending_results': - if ((false === api_is_teacher()) && (false === api_is_session_admin())) { - exit; - } - - $courseId = $_REQUEST['course_id'] ?? 0; - $exerciseId = $_REQUEST['exercise_id'] ?? 0; - $status = $_REQUEST['status'] ?? 0; - $questionType = $_REQUEST['questionType'] ?? 0; - $showAttemptsInSessions = (bool) $_REQUEST['showAttemptsInSessions']; - if (!empty($_GET['filter_by_user'])) { - $filter_user = (int) $_GET['filter_by_user']; - if (empty($whereCondition)) { - $whereCondition .= " te.exe_user_id = '$filter_user'"; - } else { - $whereCondition .= " AND te.exe_user_id = '$filter_user'"; - } - } case 'get_exercise_pending_results': if ((false === api_is_teacher()) && (false === api_is_session_admin())) { From e29822ed95addd68f9dda378487a6aae02c997c3 Mon Sep 17 00:00:00 2001 From: yverhenne <129364360+yverhenne@users.noreply.github.com> Date: Fri, 1 Aug 2025 13:54:19 +0200 Subject: [PATCH 3/7] Update pending.php --- main/exercise/pending.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main/exercise/pending.php b/main/exercise/pending.php index 85ff56576a3..46b4d5b164f 100644 --- a/main/exercise/pending.php +++ b/main/exercise/pending.php @@ -440,6 +440,8 @@ function action_formatter(cellvalue, options, rowObject) { // rowObject is firstname,lastname,login,... get the third word var loginx = "'.api_htmlentities(sprintf(get_lang('LoginX'), ':::'), ENT_QUOTES).'"; var tabLoginx = loginx.split(/:::/); + // tabLoginx[0] is before and tabLoginx[1] is after ::: + // may be empty string but is defined return ""+cellvalue+""; }'; From 6990c05a5dfac15a4fb6b979999c7ff824807926 Mon Sep 17 00:00:00 2001 From: yverhenne <129364360+yverhenne@users.noreply.github.com> Date: Fri, 1 Aug 2025 13:56:19 +0200 Subject: [PATCH 4/7] Update model.ajax.php --- main/inc/ajax/model.ajax.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index e2d28a0d95a..6e8dc5c5e6f 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -6,7 +6,7 @@ require_once __DIR__.'/../global.inc.php'; -// --- FILTRES DATE --- +// --- DATE FILTERS --- $search_start_date = isset($_REQUEST['start_date']) && !empty($_REQUEST['start_date']) ? $_REQUEST['start_date'] : null; $search_end_date = isset($_REQUEST['end_date']) && !empty($_REQUEST['end_date']) ? $_REQUEST['end_date'] : null; From 95619a15e6f6aa96171f9d5c6fc23974c281cfdc Mon Sep 17 00:00:00 2001 From: yverhenne <129364360+yverhenne@users.noreply.github.com> Date: Fri, 1 Aug 2025 14:06:07 +0200 Subject: [PATCH 5/7] Update model.ajax.php --- main/inc/ajax/model.ajax.php | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 6e8dc5c5e6f..98c726f3435 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -6,10 +6,6 @@ require_once __DIR__.'/../global.inc.php'; -// --- DATE FILTERS --- -$search_start_date = isset($_REQUEST['start_date']) && !empty($_REQUEST['start_date']) ? $_REQUEST['start_date'] : null; -$search_end_date = isset($_REQUEST['end_date']) && !empty($_REQUEST['end_date']) ? $_REQUEST['end_date'] : null; - // 1. Setting variables needed by jqgrid $action = $_GET['a']; $page = (int) $_REQUEST['page']; //page @@ -649,19 +645,20 @@ function getWhereClause($col, $oper, $val) break; case 'get_exercise_pending_results': - if ((false === api_is_teacher()) && (false === api_is_session_admin())) { - exit; - } - - $courseId = $_REQUEST['course_id'] ?? 0; - $exerciseId = $_REQUEST['exercise_id'] ?? 0; - $status = $_REQUEST['status'] ?? 0; - $questionType = $_REQUEST['questionType'] ?? 0; - $showAttemptsInSessions = $_REQUEST['showAttemptsInSessions'] ? true : false; - if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) { - $filter_user = (int) $_GET['filter_by_user']; - if (empty($whereCondition)) { - $whereCondition .= " te.exe_user_id = '$filter_user'"; + if ((false === api_is_teacher()) && (false === api_is_session_admin())) { + exit; + } + $search_start_date = isset($_REQUEST['start_date']) && !empty($_REQUEST['start_date']) ? $_REQUEST['start_date'] : null; + $search_end_date = isset($_REQUEST['end_date']) && !empty($_REQUEST['end_date']) ? $_REQUEST['end_date'] : null; + $courseId = $_REQUEST['course_id'] ?? 0; + $exerciseId = $_REQUEST['exercise_id'] ?? 0; + $status = $_REQUEST['status'] ?? 0; + $questionType = $_REQUEST['questionType'] ?? 0; + $showAttemptsInSessions = $_REQUEST['showAttemptsInSessions'] ? true : false; + if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) { + $filter_user = (int) $_GET['filter_by_user']; + if (empty($whereCondition)) { + $whereCondition .= " te.exe_user_id = '$filter_user'"; } else { $whereCondition .= " AND te.exe_user_id = '$filter_user'"; } From c54c91a43cd121a30d195bebe6c237f454267096 Mon Sep 17 00:00:00 2001 From: yverhenne <129364360+yverhenne@users.noreply.github.com> Date: Fri, 1 Aug 2025 14:15:28 +0200 Subject: [PATCH 6/7] Update model.ajax.php --- main/inc/ajax/model.ajax.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 98c726f3435..430c96bd48a 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -684,12 +684,12 @@ function getWhereClause($col, $oper, $val) } // Filtrage sur la date de fin d'exercice (exe_date) -if (!empty($search_start_date)) { - $whereCondition .= " AND te.exe_date >= '".Database::escape_string($search_start_date)." 00:00:00'"; -} -if (!empty($search_end_date)) { - $whereCondition .= " AND te.exe_date <= '".Database::escape_string($search_end_date)." 23:59:59'"; -} + if (!empty($search_start_date)) { + $whereCondition .= " AND te.exe_date >= '".Database::escape_string($search_start_date)." 00:00:00'"; + } + if (!empty($search_end_date)) { + $whereCondition .= " AND te.exe_date <= '".Database::escape_string($search_end_date)." 23:59:59'"; + } // ------------------------------- $count = ExerciseLib::get_count_exam_results( $exerciseId, From 69f753ed7e0a314c9b3332c276458ad304ff95fc Mon Sep 17 00:00:00 2001 From: Nicolas Ducoulombier Date: Mon, 4 Aug 2025 09:10:58 +0200 Subject: [PATCH 7/7] Quiz: #fix indentation and remove duplicated and unused code after break --- main/inc/ajax/model.ajax.php | 53 +++++++----------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 430c96bd48a..4362031f90e 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -659,53 +659,12 @@ function getWhereClause($col, $oper, $val) $filter_user = (int) $_GET['filter_by_user']; if (empty($whereCondition)) { $whereCondition .= " te.exe_user_id = '$filter_user'"; - } else { - $whereCondition .= " AND te.exe_user_id = '$filter_user'"; - } - } - - if (isset($_GET['group_id_in_toolbar']) && !empty($_GET['group_id_in_toolbar'])) { - $groupIdFromToolbar = (int) $_GET['group_id_in_toolbar']; - if (!empty($groupIdFromToolbar)) { - if (empty($whereCondition)) { - $whereCondition .= " te.group_id = '$groupIdFromToolbar'"; } else { - $whereCondition .= " AND group_id = '$groupIdFromToolbar'"; + $whereCondition .= " AND te.exe_user_id = '$filter_user'"; } } - } - - if (!empty($whereCondition)) { - $whereCondition = " AND $whereCondition"; - } - - if (!empty($courseId)) { - $whereCondition .= " AND te.c_id = $courseId"; - } - - // Filtrage sur la date de fin d'exercice (exe_date) - if (!empty($search_start_date)) { - $whereCondition .= " AND te.exe_date >= '".Database::escape_string($search_start_date)." 00:00:00'"; - } - if (!empty($search_end_date)) { - $whereCondition .= " AND te.exe_date <= '".Database::escape_string($search_end_date)." 23:59:59'"; - } - // ------------------------------- - $count = ExerciseLib::get_count_exam_results( - $exerciseId, - $whereCondition, - '', - false, - true, - $status, - $showAttemptsInSessions, - $questionType, - true - ); - break; - - if (!empty($_GET['group_id_in_toolbar'])) { + if (isset($_GET['group_id_in_toolbar']) && !empty($_GET['group_id_in_toolbar'])) { $groupIdFromToolbar = (int) $_GET['group_id_in_toolbar']; if (!empty($groupIdFromToolbar)) { if (empty($whereCondition)) { @@ -724,6 +683,14 @@ function getWhereClause($col, $oper, $val) $whereCondition .= " AND te.c_id = $courseId"; } + // Filtrage sur la date de fin d'exercice (exe_date) + if (!empty($search_start_date)) { + $whereCondition .= " AND te.exe_date >= '".Database::escape_string($search_start_date)." 00:00:00'"; + } + if (!empty($search_end_date)) { + $whereCondition .= " AND te.exe_date <= '".Database::escape_string($search_end_date)." 23:59:59'"; + } + $count = ExerciseLib::get_count_exam_results( $exerciseId, $whereCondition,