Skip to content

Commit

Permalink
Exercises: add HideCorrectAnsweredQuestions BT#17786
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Feb 8, 2021
1 parent 1e4a035 commit d2af08e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 11 additions & 5 deletions main/exercise/exercise.class.php
Expand Up @@ -2206,6 +2206,12 @@ public function createForm($form, $type = 'full')
null,
get_lang('HideCategoryTable')
),
$form->createElement(
'checkbox',
'hide_correct_answered_questions',
null,
get_lang('HideCorrectAnsweredQuestions')
),
];
$form->addGroup($group, null, get_lang('ResultsConfigurationPage'));
}
Expand Down Expand Up @@ -3719,7 +3725,6 @@ public function manage_answer(
if ($answerType == ORAL_EXPRESSION) {
$exe_info = Event::get_exercise_results_by_attempt($exeId);
$exe_info = isset($exe_info[$exeId]) ? $exe_info[$exeId] : null;

$objQuestionTmp->initFile(
api_get_session_id(),
isset($exe_info['exe_user_id']) ? $exe_info['exe_user_id'] : api_get_user_id(),
Expand Down Expand Up @@ -8327,10 +8332,11 @@ public function setPageResultConfiguration($values)
$pageConfig = api_get_configuration_value('allow_quiz_results_page_config');
if ($pageConfig) {
$params = [
'hide_expected_answer' => isset($values['hide_expected_answer']) ? $values['hide_expected_answer'] : '',
'hide_question_score' => isset($values['hide_question_score']) ? $values['hide_question_score'] : '',
'hide_total_score' => isset($values['hide_total_score']) ? $values['hide_total_score'] : '',
'hide_category_table' => isset($values['hide_category_table']) ? $values['hide_category_table'] : '',
'hide_expected_answer' => $values['hide_expected_answer'] ?? '',
'hide_question_score' => $values['hide_question_score'] ?? '',
'hide_total_score' => $values['hide_total_score'] ?? '',
'hide_category_table' => $values['hide_category_table'] ?? '',
'hide_correct_answered_questions' => $values['hide_correct_answered_questions'] ?? '',
];
$type = Type::getType('array');
$platform = Database::getManager()->getConnection()->getDatabasePlatform();
Expand Down
10 changes: 10 additions & 0 deletions main/inc/lib/exercise.lib.php
Expand Up @@ -4941,6 +4941,16 @@ public static function displayQuestionListByAttempt(
}

$contents = ob_get_clean();

// Hide correct answers
if ($scorePassed && !api_is_allowed_to_edit(false, true)) {
// Skip correct answers.
$hide = (int) $objExercise->getPageConfigurationAttribute('hide_correct_answered_questions');
if (1 === $hide) {
continue;
}
}

$question_content = '';
if ($show_results) {
$question_content = '<div class="question_row_answer">';
Expand Down

0 comments on commit d2af08e

Please sign in to comment.