From af7225d387e6567edaa287f1be35ee34e3e91196 Mon Sep 17 00:00:00 2001 From: lcubas Date: Tue, 24 Nov 2020 01:23:11 -0500 Subject: [PATCH 1/5] Tests: Show list of courses where a question is used --- main/exercise/admin.php | 1 + main/inc/lib/exercise.lib.php | 59 +++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/main/exercise/admin.php b/main/exercise/admin.php index 92173137a6..95bafefa3c 100755 --- a/main/exercise/admin.php +++ b/main/exercise/admin.php @@ -422,6 +422,7 @@ if ($newQuestion || $editQuestion) { echo ''; } else { require 'question_admin.inc.php'; + ExerciseLib::showExtraInfoWhereQuestionUsed($objQuestion->iid); } } } diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 04b93e8527..d72ce5f68e 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -1647,6 +1647,65 @@ HOTSPOT; return $nbrAnswers; } + public static function showExtraInfoWhereQuestionUsed($exerciseId) + { + $sql = "SELECT q.title quiz_title, + c.title course_title, + s.name session_name, + q.iid as quiz_id, + q.c_id, + q.session_id + FROM c_quiz q, + c_quiz_rel_question qq, + course c, + session s + WHERE q.c_id = c.id AND + (q.session_id = s.id OR q.session_id = 0) AND + qq.exercice_id = q.iid AND + qq.question_id = $exerciseId + GROUP BY qq.iid"; + + $result = []; + $html = ""; + + $sqlResult = Database::query($sql); + + if (Database::num_rows($sqlResult) >= 2) { + while ($row = Database::fetch_array($sqlResult, 'ASSOC')) { + $tmp = []; + $tmp[0] = $row['course_title']; + $tmp[1] = $row['session_name']; + $tmp[2] = $row['quiz_title']; + $urlToQuiz = api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&exerciseId='.$row['quiz_id']; + $tmp[3] = Display::url('Link to the questions list of that test', $urlToQuiz); + if ((int) $row['session_id'] == 0) { + $tmp[1] = '-'; + } + + $result[] = $tmp; + } + + $headers = [ + get_lang('Course'), + get_lang('Session'), + get_lang('Quiz'), + get_lang('Link') + ]; + + $title = Display::div( + 'This question is used in the following tests:', + [ + 'class' => 'section-title', + 'style' => 'margin-top: 25px; border-bottom: none' + ] + ); + + $html = $title . Display::table($headers, $result); + } + + echo $html; + } + /** * @param int $exeId * From af8c8b7515d0dd4499aaec430c43b2e6878046d4 Mon Sep 17 00:00:00 2001 From: lcubas Date: Tue, 24 Nov 2020 11:17:50 -0500 Subject: [PATCH 2/5] Tests: Create vlang var for the text of a list of test where a question is used --- main/inc/lib/exercise.lib.php | 4 ++-- main/lang/english/trad4all.inc.php | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index d72ce5f68e..a99805e01e 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -1689,11 +1689,11 @@ HOTSPOT; get_lang('Course'), get_lang('Session'), get_lang('Quiz'), - get_lang('Link') + get_lang('LinkToTheQuestionListOfThatTest') ]; $title = Display::div( - 'This question is used in the following tests:', + get_lang('QuestionUsedInTheFollowingTests'), [ 'class' => 'section-title', 'style' => 'margin-top: 25px; border-bottom: none' diff --git a/main/lang/english/trad4all.inc.php b/main/lang/english/trad4all.inc.php index 2b6a2fde82..150fb7c7ea 100644 --- a/main/lang/english/trad4all.inc.php +++ b/main/lang/english/trad4all.inc.php @@ -5832,7 +5832,7 @@ $Item = "Item"; $ConfigureDashboardPlugin = "Configure Dashboard Plugin"; $EditBlocks = "Edit blocks"; $Never = "Never"; -$YourAccountIsActiveYouCanLoginAndCheckYourCourses = "Dear user, +$YourAccountIsActiveYouCanLoginAndCheckYourCourses = "Dear user, Your account has now been activated on the platform. Please login and enjoy your courses."; $SessionFields = "Session fields"; @@ -8006,11 +8006,11 @@ $SpecificDate = "Specific dispatch date"; $BaseDate = "Dispatch based on the session's start/end dates"; $AfterOrBefore = "After or before"; $Before = "Before"; -$ScheduleAnnouncementDescription = "This form allows scheduling announcements to be sent automatically to the students who are taking a course in a session. +$ScheduleAnnouncementDescription = "This form allows scheduling announcements to be sent automatically to the students who are taking a course in a session. -There are two types of announcements that can be sent: +There are two types of announcements that can be sent: -Specific date: In this case a specific day is selected to make the announcement. +Specific date: In this case a specific day is selected to make the announcement. Based on the start / end date of the session: in this case the number of days to pass before sending the announcement must be indicated. And those days can be associated to before or after the start / end date. For example: 3 days after the start date."; $MandatorySurveyNoAnswered = "A mandatory survey is waiting your answer. To enter the course, you must first complete the survey."; @@ -8703,4 +8703,6 @@ $ToInvoice = "To invoice"; $LearningPathItemByAuthor = "LP item by author"; $DeleteExerciseAttempts = "Delete also the exercise attempts. If not check then the exercise results will still be available in the exercise tool."; $ExerciseCategoriesRadarMode = "Only show a radar of scores by category, instead of a table of categories. Do not show individual scores or feedback."; -?> \ No newline at end of file +$QuestionUsedInTheFollowingTests = "This question is used in the following tests:"; +$LinkToTheQuestionListOfThatTest = "Link to the questions list of that test"; +?> From 8a43a283112762b858ffb0654390f517053eba10 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Fri, 27 Nov 2020 14:18:47 +0100 Subject: [PATCH 3/5] Update language terms --- main/lang/english/trad4all.inc.php | 13 ++++++++----- main/lang/french/trad4all.inc.php | 3 +++ main/lang/spanish/trad4all.inc.php | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/main/lang/english/trad4all.inc.php b/main/lang/english/trad4all.inc.php index d2756a6145..c12bafcc01 100644 --- a/main/lang/english/trad4all.inc.php +++ b/main/lang/english/trad4all.inc.php @@ -5832,7 +5832,7 @@ $Item = "Item"; $ConfigureDashboardPlugin = "Configure Dashboard Plugin"; $EditBlocks = "Edit blocks"; $Never = "Never"; -$YourAccountIsActiveYouCanLoginAndCheckYourCourses = "Dear user, +$YourAccountIsActiveYouCanLoginAndCheckYourCourses = "Dear user, Your account has now been activated on the platform. Please login and enjoy your courses."; $SessionFields = "Session fields"; @@ -8006,11 +8006,11 @@ $SpecificDate = "Specific dispatch date"; $BaseDate = "Dispatch based on the session's start/end dates"; $AfterOrBefore = "After or before"; $Before = "Before"; -$ScheduleAnnouncementDescription = "This form allows scheduling announcements to be sent automatically to the students who are taking a course in a session. +$ScheduleAnnouncementDescription = "This form allows scheduling announcements to be sent automatically to the students who are taking a course in a session. -There are two types of announcements that can be sent: +There are two types of announcements that can be sent: -Specific date: In this case a specific day is selected to make the announcement. +Specific date: In this case a specific day is selected to make the announcement. Based on the start / end date of the session: in this case the number of days to pass before sending the announcement must be indicated. And those days can be associated to before or after the start / end date. For example: 3 days after the start date."; $MandatorySurveyNoAnswered = "A mandatory survey is waiting your answer. To enter the course, you must first complete the survey."; @@ -8710,4 +8710,7 @@ $PriceUpdated = "Price updated"; $RemoveSelected = "Remove selected authors"; $DeletedAuthors = "Authors have been removed"; $HideCategoryTable = "Hide category table"; -?> +$XQuestionsSelectedWithTotalScoreY = "Only %d questions will be selected based on the test configuration, for a total score of %s."; +$QuestionAlsoUsedInTheFollowingTests = "This question is also used in the following tests"; +$LinkToTestEdition = "Link to test edition"; +?> \ No newline at end of file diff --git a/main/lang/french/trad4all.inc.php b/main/lang/french/trad4all.inc.php index 9e132771f9..2359c2a44d 100644 --- a/main/lang/french/trad4all.inc.php +++ b/main/lang/french/trad4all.inc.php @@ -8642,4 +8642,7 @@ $PriceUpdated = "Prix mis à jour"; $RemoveSelected = "Retirer les auteurs sélectionnés"; $DeletedAuthors = "Les auteurs ont été retirés"; $HideCategoryTable = "Cacher le tableau de catégories"; +$XQuestionsSelectedWithTotalScoreY = "Seules %d questions seront sélectionnées d'après la configuration de l'exercice, pour un score total de %s."; +$QuestionAlsoUsedInTheFollowingTests = "Question utilisée également dans les exercices suivants"; +$LinkToTestEdition = "Lien vers l'édition de l'exercice"; ?> \ No newline at end of file diff --git a/main/lang/spanish/trad4all.inc.php b/main/lang/spanish/trad4all.inc.php index 45f97debc0..17730312b4 100644 --- a/main/lang/spanish/trad4all.inc.php +++ b/main/lang/spanish/trad4all.inc.php @@ -8738,4 +8738,7 @@ $PriceUpdated = "Precio actualizado"; $RemoveSelected = "Eliminar autores seleccionados"; $DeletedAuthors = "Los autores han sido eliminados"; $HideCategoryTable = "Esconder la tabla de categorías"; +$XQuestionsSelectedWithTotalScoreY = "Solo se seleccionarán %d preguntas según la configuración del ejercicio, para una puntuación total de %s."; +$QuestionAlsoUsedInTheFollowingTests = "Esta pregunta se usa también en los ejercicios siguientes"; +$LinkToTestEdition = "Vínculo a la edición del ejercicio"; ?> \ No newline at end of file From c07904be42b4f3fb0fd3ae5b705b97491a403d60 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Fri, 27 Nov 2020 14:46:53 +0100 Subject: [PATCH 4/5] Internal: Filter variable, change tables alias, add exclusion test ID and change language variables in showExtraInfoWhereQuestionUsed - refs #3580 --- main/inc/lib/exercise.lib.php | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 26210e611b..6634108fec 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -1647,22 +1647,34 @@ HOTSPOT; return $nbrAnswers; } - public static function showExtraInfoWhereQuestionUsed($exerciseId) + /** + * Get an HTML string with the list of exercises where the given question + * is being used + * @param int $questionId The iid of the question being observed + * @param int $excludeTestId If defined, exclude this (current) test from the list of results + * @return string An HTML string containing a div and a table + */ + public static function showTestsWhereQuestionIsUsed(int $questionId, int $excludeTestId = 0) { - $sql = "SELECT q.title quiz_title, + $questionId = (int) $questionId; + $sql = "SELECT qz.title quiz_title, c.title course_title, s.name session_name, - q.iid as quiz_id, - q.c_id, - q.session_id - FROM c_quiz q, + qz.iid as quiz_id, + qz.c_id, + qz.session_id + FROM c_quiz qz, c_quiz_rel_question qq, course c, session s - WHERE q.c_id = c.id AND - (q.session_id = s.id OR q.session_id = 0) AND - qq.exercice_id = q.iid AND - qq.question_id = $exerciseId + WHERE qz.c_id = c.id AND + (qz.session_id = s.id OR qz.session_id = 0) AND + qq.exercice_id = qz.iid AND "; + if (!empty($excludeTestId)) { + $excludeTestId = (int) $excludeTestId; + $sql .= " qz.iid != $excludeTestId AND "; + } + $sql .= " qq.question_id = $questionId GROUP BY qq.iid"; $result = []; @@ -1670,14 +1682,14 @@ HOTSPOT; $sqlResult = Database::query($sql); - if (Database::num_rows($sqlResult) >= 2) { + if (Database::num_rows($sqlResult) != 0) { while ($row = Database::fetch_array($sqlResult, 'ASSOC')) { $tmp = []; $tmp[0] = $row['course_title']; $tmp[1] = $row['session_name']; $tmp[2] = $row['quiz_title']; $urlToQuiz = api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&exerciseId='.$row['quiz_id']; - $tmp[3] = Display::url('Link to the questions list of that test', $urlToQuiz); + $tmp[3] = ''.Display::return_icon('quiz.png', get_lang('Edit')).''; if ((int) $row['session_id'] == 0) { $tmp[1] = '-'; } @@ -1689,11 +1701,11 @@ HOTSPOT; get_lang('Course'), get_lang('Session'), get_lang('Quiz'), - get_lang('LinkToTheQuestionListOfThatTest') + get_lang('LinkToTestEdition') ]; $title = Display::div( - get_lang('QuestionUsedInTheFollowingTests'), + get_lang('QuestionAlsoUsedInTheFollowingTests'), [ 'class' => 'section-title', 'style' => 'margin-top: 25px; border-bottom: none' From e9a6fbc4e22f62ee37f0b222edbf629f3d6a8da9 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Fri, 27 Nov 2020 14:48:52 +0100 Subject: [PATCH 5/5] Exercise: Add reset option to remove test in-session context - refs #3580 --- main/exercise/admin.php | 6 +++++- main/inc/lib/exercise.lib.php | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main/exercise/admin.php b/main/exercise/admin.php index 95bafefa3c..2978f73a3c 100755 --- a/main/exercise/admin.php +++ b/main/exercise/admin.php @@ -49,6 +49,10 @@ require_once __DIR__.'/../inc/global.inc.php'; $current_course_tool = TOOL_QUIZ; $this_section = SECTION_COURSES; +if ($_GET['r'] == 1) { + Exercise::cleanSessionVariables(); +} + // Access control api_protect_course_script(true); @@ -422,7 +426,7 @@ if ($newQuestion || $editQuestion) { echo ''; } else { require 'question_admin.inc.php'; - ExerciseLib::showExtraInfoWhereQuestionUsed($objQuestion->iid); + ExerciseLib::showTestsWhereQuestionIsUsed($objQuestion->iid, $objExercise->selectId()); } } } diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 6634108fec..e81b672478 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -1688,7 +1688,8 @@ HOTSPOT; $tmp[0] = $row['course_title']; $tmp[1] = $row['session_name']; $tmp[2] = $row['quiz_title']; - $urlToQuiz = api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&exerciseId='.$row['quiz_id']; + // Send do other test with r=1 to reset current test session variables + $urlToQuiz = api_get_path(WEB_CODE_PATH).'exercise/admin.php?'.api_get_cidreq().'&exerciseId='.$row['quiz_id'].'&r=1'; $tmp[3] = ''.Display::return_icon('quiz.png', get_lang('Edit')).''; if ((int) $row['session_id'] == 0) { $tmp[1] = '-';