diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index 5eaa4756b0..d35097e2fd 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -1500,18 +1500,18 @@ class Exercise $propagate_neg = (int) $this->propagate_neg; $saveCorrectAnswers = isset($this->saveCorrectAnswers) && $this->saveCorrectAnswers ? 1 : 0; $review_answers = isset($this->review_answers) && $this->review_answers ? 1 : 0; - $randomByCat = intval($this->randomByCat); + $randomByCat = (int) $this->randomByCat; $text_when_finished = $this->text_when_finished; - $display_category_name = intval($this->display_category_name); - $pass_percentage = intval($this->pass_percentage); + $display_category_name = (int) $this->display_category_name; + $pass_percentage = (int) $this->pass_percentage; $session_id = $this->sessionId; // If direct we do not show results - $results_disabled = intval($this->results_disabled); + $results_disabled = (int) $this->results_disabled; if ($feedback_type == EXERCISE_FEEDBACK_TYPE_DIRECT) { $results_disabled = 0; } - $expired_time = intval($this->expired_time); + $expired_time = (int) $this->expired_time; // Exercise already exists if ($id) { @@ -1947,7 +1947,6 @@ class Exercise '2', ['id' => 'result_disabled_2'] ); - $radios_results_disabled[] = $form->createElement( 'radio', 'results_disabled', @@ -1956,6 +1955,14 @@ class Exercise '4', ['id' => 'result_disabled_4'] ); + $radios_results_disabled[] = $form->createElement( + 'radio', + 'results_disabled', + null, + get_lang('DontShowScoreOnlyWhenUserFinishesAllAttemptsButShowFeedbackEachAttempt'), + '5', + ['id' => 'result_disabled_5', 'onclick' => 'check_results_disabled()'] + ); $form->addGroup( $radios_results_disabled, @@ -2026,6 +2033,7 @@ class Exercise null, [get_lang('FeedbackType'), get_lang('FeedbackDisplayOptions')] ); + $radios_results_disabled = []; $radios_results_disabled[] = $form->createElement( 'radio', @@ -2051,6 +2059,7 @@ class Exercise '2', ['id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()'] ); + $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), ''); // Type of questions disposition on page @@ -2090,6 +2099,9 @@ class Exercise '2', ['id' => 'result_disabled_2', 'onclick' => 'check_results_disabled()'] ); + + $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), ''); + $result_disable_group = $form->addGroup( $radios_results_disabled, null, @@ -3494,7 +3506,6 @@ class Exercise if ($debug) { error_log('Start answer loop '); } - for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { $answer = $objAnswerTmp->selectAnswer($answerId); $answerComment = $objAnswerTmp->selectComment($answerId); @@ -4630,7 +4641,7 @@ class Exercise if ($debug) { error_log('Showing questions $from '.$from); } - if ($from == 'exercise_result') { + if ($from === 'exercise_result') { //display answers (if not matching type, or if the answer is correct) if (!in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE]) || $answerCorrect @@ -4761,7 +4772,6 @@ class Exercise // force to show whether the choice is correct or not $showTotalScoreAndUserChoicesInLastAttempt = true; - ExerciseShowFunctions::display_hotspot_answer( $feedback_type, ++$correctAnswerId, @@ -4961,7 +4971,6 @@ class Exercise if ($debug) { error_log('Showing questions $from '.$from); } - switch ($answerType) { case UNIQUE_ANSWER: case UNIQUE_ANSWER_IMAGE: diff --git a/main/exercise/exercise_show.php b/main/exercise/exercise_show.php index 7024c6a20c..b294a18fd1 100755 --- a/main/exercise/exercise_show.php +++ b/main/exercise/exercise_show.php @@ -88,22 +88,29 @@ $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; $courseInfo = api_get_course_info(); $sessionId = api_get_session_id(); -$is_allowedToEdit = api_is_allowed_to_edit(null, true) || + +$is_allowedToEdit = + api_is_allowed_to_edit(null, true) || api_is_course_tutor() || api_is_session_admin() || api_is_drh() || api_is_student_boss(); + + if (!empty($sessionId) && !$is_allowedToEdit) { if (api_is_course_session_coach( $currentUserId, api_get_course_int_id(), $sessionId )) { - if (!api_coach_can_edit_view_results(api_get_course_int_id(), $sessionId) - ) { + if (!api_coach_can_edit_view_results(api_get_course_int_id(), $sessionId)) { api_not_allowed($printHeaders); } } +} else { + if (!$is_allowedToEdit) { + api_not_allowed($printHeaders); + } } $allowCoachFeedbackExercises = api_get_setting('allow_coach_feedback_exercises') === 'true'; @@ -122,7 +129,8 @@ if (empty($objExercise)) { $objExercise->read($exercise_id); } $feedback_type = $objExercise->feedback_type; -//Only users can see their own results + +// Only users can see their own results if (!$is_allowedToEdit) { if ($student_id != $currentUserId) { api_not_allowed($printHeaders); @@ -230,43 +238,47 @@ $showTotalScoreAndUserChoicesInLastAttempt = true; if (!empty($track_exercise_info)) { // if the results_disabled of the Quiz is 1 when block the script $result_disabled = $track_exercise_info['results_disabled']; - - if ($result_disabled == RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS) { - $show_results = false; - } elseif ($result_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY) { - $show_results = false; - $show_only_total_score = true; - if ($origin != 'learnpath') { - if ($currentUserId == $student_id) { - echo Display::return_message( - get_lang('ThankYouForPassingTheTest'), - 'warning', - false - ); - } - } - } elseif ($result_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) { - $attempts = Event::getExerciseResultsByUser( - $currentUserId, - $objExercise->id, - api_get_course_int_id(), - api_get_session_id(), - $track_exercise_info['orig_lp_id'], - $track_exercise_info['orig_lp_item_id'], - 'desc' - ); - $numberAttempts = count($attempts); - if ($numberAttempts >= $track_exercise_info['max_attempt']) { - $show_results = true; - $show_only_total_score = true; - // Attempt reach max so show score/feedback now - $showTotalScoreAndUserChoicesInLastAttempt = true; - } else { - $show_results = true; + switch ($result_disabled) { + case RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS: + $show_results = false; + break; + case RESULT_DISABLE_SHOW_SCORE_ONLY: + $show_results = false; $show_only_total_score = true; - // Last attempt not reach don't show score/feedback - $showTotalScoreAndUserChoicesInLastAttempt = false; - } + if ($origin != 'learnpath') { + if ($currentUserId == $student_id) { + echo Display::return_message( + get_lang('ThankYouForPassingTheTest'), + 'warning', + false + ); + } + } + break; + case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK: + case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT: + $attempts = Event::getExerciseResultsByUser( + $currentUserId, + $objExercise->id, + api_get_course_int_id(), + api_get_session_id(), + $track_exercise_info['orig_lp_id'], + $track_exercise_info['orig_lp_item_id'], + 'desc' + ); + $numberAttempts = count($attempts); + if ($numberAttempts >= $track_exercise_info['max_attempt']) { + $show_results = true; + $show_only_total_score = true; + // Attempt reach max so show score/feedback now + $showTotalScoreAndUserChoicesInLastAttempt = true; + } else { + $show_results = true; + $show_only_total_score = true; + // Last attempt not reach don't show score/feedback + $showTotalScoreAndUserChoicesInLastAttempt = false; + } + break; } } else { echo Display::return_message(get_lang('CantViewResults'), 'warning'); @@ -369,6 +381,10 @@ if (!empty($maxEditors) && count($questionList) > $maxEditors) { } $objExercise->export = $action === 'export'; +$arrid = []; +$arrmarks = []; +$strids = ''; +$marksid = ''; $countPendingQuestions = 0; foreach ($questionList as $questionId) { @@ -388,7 +404,6 @@ foreach ($questionList as $questionId) { // Start buffer ob_start(); - if ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { $choice = []; } diff --git a/main/exercise/exercise_submit.php b/main/exercise/exercise_submit.php index b42c4973ea..e93db8597e 100755 --- a/main/exercise/exercise_submit.php +++ b/main/exercise/exercise_submit.php @@ -732,7 +732,7 @@ if ($formSent && isset($_POST)) { exit; } else { if ($debug) { - error_log('10. Redirecting to exercise_show.php'); + error_log('10. Redirecting to exercise_result.php'); } header("Location: exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id"); exit; diff --git a/main/exercise/fill_blanks.class.php b/main/exercise/fill_blanks.class.php index 0a9d99e49d..b879e844b7 100755 --- a/main/exercise/fill_blanks.class.php +++ b/main/exercise/fill_blanks.class.php @@ -1195,7 +1195,12 @@ class FillBlanks extends Question $result = ''; $listStudentAnswerInfo = self::getAnswerInfo($answer, true); - if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) { + if (in_array($resultsDisabled, [ + RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT, + RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK + ] + ) + ) { $resultsDisabled = true; if ($showTotalScoreAndUserChoices) { $resultsDisabled = false; @@ -1257,15 +1262,19 @@ class FillBlanks extends Question $showTotalScoreAndUserChoices = false ) { $hideExpectedAnswer = false; - if ($feedbackType == 0 && $resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY) { - $hideExpectedAnswer = true; - } - - if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) { - $hideExpectedAnswer = true; - if ($showTotalScoreAndUserChoices) { - $hideExpectedAnswer = false; - } + switch ($resultsDisabled) { + case RESULT_DISABLE_SHOW_SCORE_ONLY: + if ($feedbackType == 0) { + $hideExpectedAnswer = true; + } + break; + case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK: + case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT: + $hideExpectedAnswer = true; + if ($showTotalScoreAndUserChoices) { + $hideExpectedAnswer = false; + } + break; } $style = 'feedback-green'; diff --git a/main/exercise/freeanswer.class.php b/main/exercise/freeanswer.class.php index be571782d7..bedd15027b 100755 --- a/main/exercise/freeanswer.class.php +++ b/main/exercise/freeanswer.class.php @@ -61,7 +61,7 @@ class FreeAnswer extends Question $header = parent::return_header($exercise, $counter, $score); $header .= '
| '.get_lang("Answer").' | +'.get_lang('Answer').' |
|---|---|
| '; $course_id = api_get_course_int_id(); @@ -613,15 +626,19 @@ class ExerciseShowFunctions $showTotalScoreAndUserChoices ) { $hide_expected_answer = false; - if ($feedback_type == 0 && ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ONLY)) { - $hide_expected_answer = true; - } - - if ($resultsDisabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) { - $hide_expected_answer = true; - if ($showTotalScoreAndUserChoices) { - $hide_expected_answer = false; - } + switch ($resultsDisabled) { + case RESULT_DISABLE_SHOW_SCORE_ONLY: + if ($feedback_type == 0) { + $hide_expected_answer = true; + } + break; + case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK: + case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT: + $hide_expected_answer = true; + if ($showTotalScoreAndUserChoices) { + $hide_expected_answer = false; + } + break; } echo ' | |
| '; @@ -690,14 +707,14 @@ class ExerciseShowFunctions * @param $exe_id * @param $questionId * @param null $questionScore - * @param int $results_disabled + * @param int $resultsDisabled */ public static function displayAnnotationAnswer( $feedback_type, $exe_id, $questionId, $questionScore = null, - $results_disabled = 0 + $resultsDisabled = 0 ) { $comments = Event::get_comments($exe_id, $questionId); if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { diff --git a/main/lang/english/trad4all.inc.php b/main/lang/english/trad4all.inc.php index 8614183792..8373f1f976 100644 --- a/main/lang/english/trad4all.inc.php +++ b/main/lang/english/trad4all.inc.php @@ -8336,4 +8336,5 @@ $NumberOfVisits = "Number of visits"; $FormationUnit = "Formation unit"; $GlobalProgress = "Global progress"; $AttestationOfAttendance = "Attestation of attendance"; +$DontShowScoreOnlyWhenUserFinishesAllAttemptsButShowFeedbackEachAttempt = "Do not show the score (only when user finishes all attempts) but show feedback for each attempt."; ?> \ No newline at end of file |