From dd051695d71cb7e69969d6b3644a5b1ee79bedfb Mon Sep 17 00:00:00 2001 From: Julio Date: Thu, 12 May 2016 12:03:25 +0200 Subject: [PATCH] Add new exercise option: RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT If number of attempts is reached then show score and answer. Otherwise just show only scores. see BT#11202 --- main/exercice/exercise.class.php | 46 +++++++++++++++++++++++++++---- main/exercice/exercise_submit.php | 16 +++++------ main/exercice/overview.php | 27 ++++++++++++++++-- main/exercice/result.php | 4 +-- main/inc/lib/api.lib.php | 1 + main/inc/lib/exercise.lib.php | 27 ++++++++++++++++++ 6 files changed, 103 insertions(+), 18 deletions(-) diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 33a61274bc..7dc65b0fdf 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -1945,11 +1945,41 @@ class Exercise // Type of results display on the final page $radios_results_disabled = array(); - $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id'=>'result_disabled_0')); - $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()')); - $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id'=>'result_disabled_2')); + $radios_results_disabled[] = $form->createElement( + 'radio', + 'results_disabled', + null, + get_lang('ShowScoreAndRightAnswer'), + '0', + array('id' => 'result_disabled_0') + ); + $radios_results_disabled[] = $form->createElement( + 'radio', + 'results_disabled', + null, + get_lang('DoNotShowScoreNorRightAnswer'), + '1', + array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()') + ); + $radios_results_disabled[] = $form->createElement( + 'radio', + 'results_disabled', + null, + get_lang('OnlyShowScore'), + '2', + array('id' => 'result_disabled_2') + ); //$radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ExamModeWithFinalScoreShowOnlyFinalScoreWithCategoriesIfAvailable'), '3', array('id'=>'result_disabled_3','onclick' => 'check_results_disabled()')); + $radios_results_disabled[] = $form->createElement( + 'radio', + 'results_disabled', + null, + get_lang('ShowScoreEveryAttemptShowAnswersLastAttempt'), + '4', + array('id' => 'result_disabled_4') + ); + $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), ''); // Type of questions disposition on page @@ -7720,7 +7750,7 @@ class Exercise $exercise_content = null; - //Hide results + // Hide results $show_results = false; $show_only_score = false; @@ -7728,7 +7758,13 @@ class Exercise $show_results = true; } - if (in_array($this->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) { + $showScoreOptions = [ + RESULT_DISABLE_SHOW_SCORE_ONLY, + RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES, + RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT + ]; + + if (in_array($this->results_disabled, $showScoreOptions)) { $show_only_score = true; } diff --git a/main/exercice/exercise_submit.php b/main/exercice/exercise_submit.php index b7c95ac9e8..7082a27bbc 100755 --- a/main/exercice/exercise_submit.php +++ b/main/exercice/exercise_submit.php @@ -104,10 +104,10 @@ if (api_is_allowed_to_edit(null, true) && isset($_GET['preview']) && $_GET['prev /** @var \Exercise $exerciseInSession */ $exerciseInSession = Session::read('objExercise'); - if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSession->id != $_GET['exerciseId'])) { // Construction of Exercise $objExercise = new Exercise(); + Session::write('firstTime', true); if ($debug) {error_log('1. Setting the $objExercise variable'); }; Session::erase('questionList'); @@ -127,7 +127,6 @@ if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSessi } else { Session::write('firstTime', false); } - //2. Checking if $objExercise is set if (!isset($objExercise) && isset($exerciseInSession)) { if ($debug) { error_log('2. Loading $objExercise from session'); }; @@ -238,12 +237,14 @@ if ($objExercise->selectAttempts() > 0) { if ($origin == 'learnpath') { Display :: display_reduced_header(); } else { - Display :: display_header($nameTools,'Exercises'); + Display :: display_header(get_lang('Exercises')); } echo $attempt_html; - if ($origin != 'learnpath') - Display :: display_footer(); + + if ($origin != 'learnpath') { + Display:: display_footer(); + } exit; } } @@ -451,9 +452,8 @@ if ($time_control) { //Sends the exercise form when the expired time is finished } // if the user has submitted the form - -$exercise_title = $objExercise->selectTitle(); -$exercise_sound = $objExercise->selectSound(); +$exercise_title = $objExercise->selectTitle(); +$exercise_sound = $objExercise->selectSound(); //in LP's is enabled the "remember question" feature? diff --git a/main/exercice/overview.php b/main/exercice/overview.php index 3da12d6234..4971cc271f 100755 --- a/main/exercice/overview.php +++ b/main/exercice/overview.php @@ -169,6 +169,13 @@ if ($current_browser == 'Internet Explorer') { $btn_class = ''; } +$blockShowAnswers = false; +if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) { + if (count($attempts) < $objExercise->attempts ) { + $blockShowAnswers = true; + } +} + if (!empty($attempts)) { $i = $counter; foreach ($attempts as $attempt_result) { @@ -213,7 +220,8 @@ if (!empty($attempts)) { array( RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS, RESULT_DISABLE_SHOW_SCORE_ONLY, - RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES + RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES, + RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT ) )) { $row['result'] = $score; @@ -223,23 +231,36 @@ if (!empty($attempts)) { $objExercise->results_disabled, array( RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS, - RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES + RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES, + RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT ) ) || ( $objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY && $objExercise->feedback_type == EXERCISE_FEEDBACK_TYPE_END) ) { + if ($blockShowAnswers) { + $attempt_link = ''; + } + $row['attempt_link'] = $attempt_link; } $my_attempt_array[] = $row; $i--; } + $header_names = []; $table = new HTML_Table(array('class' => 'table table-striped table-hover')); - //Hiding score and answer + // Hiding score and answer switch ($objExercise->results_disabled) { + case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT: + if ($blockShowAnswers) { + $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('IP'), get_lang('Score')); + } else { + $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('IP'), get_lang('Score'), get_lang('Details')); + } + break; case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS: case RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES: $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('IP'), get_lang('Score'), get_lang('Details')); diff --git a/main/exercice/result.php b/main/exercice/result.php index 21865c30d3..32a47bdc00 100755 --- a/main/exercice/result.php +++ b/main/exercice/result.php @@ -28,10 +28,10 @@ if (empty($id)) { $is_allowedToEdit = api_is_allowed_to_edit(null,true) || $is_courseTutor; -//Getting results from the exe_id. This variable also contain all the information about the exercise +// Getting results from the exe_id. This variable also contain all the information about the exercise $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id); -//No track info +// No track info if (empty($track_exercise_info)) { api_not_allowed($show_headers); } diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index a091f7360c..6982e57f1d 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -456,6 +456,7 @@ define('RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS', 0); //show score and ex define('RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS', 1); //Do not show score nor answers define('RESULT_DISABLE_SHOW_SCORE_ONLY', 2); //Show score only define('RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES', 3); //Show final score only with categories +define('RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT', 4); //Show final score only with categories define('EXERCISE_MAX_NAME_SIZE', 80); diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 0086bd96f9..50ec457016 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -3483,6 +3483,32 @@ HOTSPOT; $show_only_score = false; } + if ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) { + $show_only_score = true; + if ($objExercise->attempts > 0) { + $attempts = Event::getExerciseResultsByUser( + api_get_user_id(), + $objExercise->id, + api_get_course_int_id(), + api_get_session_id(), + $exercise_stat_info['orig_lp_id'], + $exercise_stat_info['orig_lp_item_id'], + 'desc' + ); + + if ($attempts) { + $numberAttempts = count($attempts); + if ($save_user_result) { + $numberAttempts++; + } + if ($numberAttempts >= $objExercise->attempts) { + $show_results = true; + $show_only_score = false; + }; + } + } + } + if ($show_results || $show_only_score) { $user_info = api_get_user_info($exercise_stat_info['exe_user_id']); //Shows exercise header @@ -3497,6 +3523,7 @@ HOTSPOT; ); } + // Display text when test is finished #4074 and for LP #4227 $end_of_message = $objExercise->selectTextWhenFinished(); if (!empty($end_of_message)) {