From d9b46e6cf0b9ea68b66916597b8e2e01740266b9 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 12 May 2020 18:13:30 -0500 Subject: [PATCH 1/6] Quiz: Add answer-saving procedure check before starting the quiz #3226 Add $_configuration['quiz_check_button_enable'] conf setting --- main/exercise/overview.php | 62 +++++++++++++++++++++++++++++ main/inc/ajax/exercise.ajax.php | 3 ++ main/install/configuration.dist.php | 2 + 3 files changed, 67 insertions(+) diff --git a/main/exercise/overview.php b/main/exercise/overview.php index b15f710a0d..55343773c9 100755 --- a/main/exercise/overview.php +++ b/main/exercise/overview.php @@ -151,6 +151,20 @@ $exercise_url_button = Display::url( ['class' => 'btn btn-success btn-large'] ); +$btnCheck = ''; +$quizCheckButtonEnabled = api_get_configuration_value('quiz_check_button_enable'); + +if ($quizCheckButtonEnabled) { + $btnCheck = ''.PHP_EOL + .Display::toolbarButton( + get_lang('TestYourBrowser'), + '#', + 'check', + 'info', + ['role' => 'button', 'id' => 'quiz-check-request-button'] + ); +} + //3. Checking visibility of the exercise (overwrites the exercise button) $visible_return = $objExercise->is_visible( $learnpath_id, @@ -423,6 +437,14 @@ $isLimitReached = ExerciseLib::isQuestionsLimitPerDayReached( ); if (!empty($exercise_url_button) && !$isLimitReached) { + if ($quizCheckButtonEnabled) { + $html .= Display::div( + $btnCheck, + ['class' => 'exercise_overview_options'] + ); + $html .= '
'; + } + $html .= Display::div( Display::div( $exercise_url_button, @@ -453,6 +475,46 @@ if ($certificateBlock) { $html .= PHP_EOL.$certificateBlock; } +if ($quizCheckButtonEnabled) { + $quizCheckRequestUrl = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=browser_test'; + $params = http_build_query( + [ + 'exe_id' => 0, + 'exerciseId' => $exercise_id, + 'learnpath_id' => $learnpath_id, + 'learnpath_item_id' => $learnpath_item_id, + 'learnpath_item_view_id' => $learnpathItemViewId, + 'reminder' => '0', + 'type' => 'simple', + 'question_id' => 0, + 'choice[0]' => 0, + ] + ).'&'.api_get_cidreq(); + + $html .= ""; +} + echo $html; Display::display_footer(); diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index 33205aa7dd..dc2aa6baac 100755 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -791,6 +791,9 @@ switch ($action) { header('Content-Type: application/json'); echo json_encode($result); break; + case 'browser_test': + echo 'ok'; + break; default: echo ''; } diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index 4a640a3794..9e89f54c83 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -589,6 +589,8 @@ $_configuration['send_all_emails_to'] = [ //$_configuration['quiz_generate_certificate_ending'] = false; // Allow the teacher to rate the open, oral expression and annotation question types with a decimal score. //$_configuration['quiz_open_question_decimal_score'] = false; +// Add answer-saving procedure check before starting the quiz +//$_configuration['quiz_check_button_enable'] = false; // Hide search form in session list //$_configuration['hide_search_form_in_session_list'] = false; From 55a3be511554ba57bb5c8ce7c474b09d1d3f57fb Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 26 May 2020 11:23:36 -0500 Subject: [PATCH 2/6] Minor - Set faked IDs in request #3226 --- main/exercise/overview.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main/exercise/overview.php b/main/exercise/overview.php index 55343773c9..20b2e76dab 100755 --- a/main/exercise/overview.php +++ b/main/exercise/overview.php @@ -479,15 +479,15 @@ if ($quizCheckButtonEnabled) { $quizCheckRequestUrl = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=browser_test'; $params = http_build_query( [ - 'exe_id' => 0, + 'exe_id' => 1, 'exerciseId' => $exercise_id, 'learnpath_id' => $learnpath_id, 'learnpath_item_id' => $learnpath_item_id, 'learnpath_item_view_id' => $learnpathItemViewId, 'reminder' => '0', 'type' => 'simple', - 'question_id' => 0, - 'choice[0]' => 0, + 'question_id' => 23, + 'choice[23]' => 45, ] ).'&'.api_get_cidreq(); From 9bb635536288ae4b79e1db74b2a5803420db4290 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 26 May 2020 12:04:45 -0500 Subject: [PATCH 3/6] Add second request with sleep - refs #3226 --- main/exercise/overview.php | 71 ++++++++++++++++++++++----------- main/inc/ajax/exercise.ajax.php | 4 ++ 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/main/exercise/overview.php b/main/exercise/overview.php index 20b2e76dab..24c6cfd019 100755 --- a/main/exercise/overview.php +++ b/main/exercise/overview.php @@ -155,14 +155,11 @@ $btnCheck = ''; $quizCheckButtonEnabled = api_get_configuration_value('quiz_check_button_enable'); if ($quizCheckButtonEnabled) { - $btnCheck = ''.PHP_EOL - .Display::toolbarButton( - get_lang('TestYourBrowser'), - '#', - 'check', - 'info', - ['role' => 'button', 'id' => 'quiz-check-request-button'] - ); + $btnCheck = Display::button( + 'quiz_check_request_button', + Display::returnFontAwesomeIcon('check', '', true).' '.get_lang('TestYourBrowser'), + ['type' => 'button', 'role' => 'button', 'id' => 'quiz-check-request-button', 'class' => 'btn btn-info'] + ).PHP_EOL.''; } //3. Checking visibility of the exercise (overwrites the exercise button) @@ -493,23 +490,51 @@ if ($quizCheckButtonEnabled) { $html .= ""; diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index dc2aa6baac..cd04f10956 100755 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -792,6 +792,10 @@ switch ($action) { echo json_encode($result); break; case 'browser_test': + if (isset($_POST['sleep'])) { + sleep(2); + } + echo 'ok'; break; default: From 4bd8fef0dd6b98edc59622625b222465223f76be Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 26 May 2020 12:09:58 -0500 Subject: [PATCH 4/6] Validate quiz_check_button_enable request #3226 --- main/inc/ajax/exercise.ajax.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main/inc/ajax/exercise.ajax.php b/main/inc/ajax/exercise.ajax.php index cd04f10956..536296a70f 100755 --- a/main/inc/ajax/exercise.ajax.php +++ b/main/inc/ajax/exercise.ajax.php @@ -792,11 +792,16 @@ switch ($action) { echo json_encode($result); break; case 'browser_test': - if (isset($_POST['sleep'])) { - sleep(2); + $quizCheckButtonEnabled = api_get_configuration_value('quiz_check_button_enable'); + + if ($quizCheckButtonEnabled) { + if (isset($_POST['sleep'])) { + sleep(2); + } + + echo 'ok'; } - echo 'ok'; break; default: echo ''; From ae6430b4c6378f124655d85df9a63e07e35614a8 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 26 May 2020 12:51:35 -0500 Subject: [PATCH 5/6] Minor - rename lang var #3226 --- main/exercise/overview.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/exercise/overview.php b/main/exercise/overview.php index 24c6cfd019..9f21ada92e 100755 --- a/main/exercise/overview.php +++ b/main/exercise/overview.php @@ -524,13 +524,13 @@ if ($quizCheckButtonEnabled) { btnStart.show(); } else { - txtResult.text(\"".get_lang('QuizBrowserCheckNO')."\").addClass('text-danger').show(); + txtResult.text(\"".get_lang('QuizBrowserCheckKO')."\").addClass('text-danger').show(); } btnTest.prop('disabled', false); }, function () { - txtResult.text(\"".get_lang('QuizBrowserCheckNO')."\").addClass('text-danger').show(); + txtResult.text(\"".get_lang('QuizBrowserCheckKO')."\").addClass('text-danger').show(); btnTest.prop('disabled', false); } From 5d066ec22563c6f2e8a99551d50590bca45ea2e0 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Wed, 27 May 2020 09:37:03 -0500 Subject: [PATCH 6/6] Quiz: Don't block start button with test #3226 --- main/exercise/overview.php | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/main/exercise/overview.php b/main/exercise/overview.php index 9f21ada92e..47df402c9d 100755 --- a/main/exercise/overview.php +++ b/main/exercise/overview.php @@ -157,9 +157,16 @@ $quizCheckButtonEnabled = api_get_configuration_value('quiz_check_button_enable' if ($quizCheckButtonEnabled) { $btnCheck = Display::button( 'quiz_check_request_button', - Display::returnFontAwesomeIcon('check', '', true).' '.get_lang('TestYourBrowser'), - ['type' => 'button', 'role' => 'button', 'id' => 'quiz-check-request-button', 'class' => 'btn btn-info'] - ).PHP_EOL.''; + Display::returnFontAwesomeIcon('spinner', '', true, 'fa-spin hidden').' '.get_lang('TestYourBrowser'), + [ + 'type' => 'button', + 'role' => 'button', + 'id' => 'quiz-check-request-button', + 'class' => 'btn btn-default', + 'data-loading-text' => get_lang('Loading'), + 'autocomplete' => 'off', + ] + ).PHP_EOL.''; } //3. Checking visibility of the exercise (overwrites the exercise button) @@ -490,14 +497,14 @@ if ($quizCheckButtonEnabled) { $html .= "";