Quiz: Fix max score shown in question list for teacher when using limited questions count with random selection - refs #3608

pull/3683/head
Angel Fernando Quiroz Campos 5 years ago committed by GitHub
parent 90df23f34f
commit f56b2a93db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      main/exercise/admin.php

@ -346,7 +346,7 @@ if ($inATest) {
$maxScoreAllQuestions = 0; $maxScoreAllQuestions = 0;
if ($showPagination === false) { if ($showPagination === false) {
$questionList = $objExercise->selectQuestionList(true, true); $questionList = $objExercise->selectQuestionList(true, $objExercise->random > 0 ? false : true);
if (!empty($questionList)) { if (!empty($questionList)) {
foreach ($questionList as $questionItemId) { foreach ($questionList as $questionItemId) {
$question = Question::read($questionItemId); $question = Question::read($questionItemId);
@ -371,16 +371,48 @@ if ($inATest) {
} }
$alert = ''; $alert = '';
if ($showPagination === false) { if ($showPagination === false) {
$originalSelectionType = $objExercise->questionSelectionType;
$objExercise->questionSelectionType = EX_Q_SELECTION_ORDERED;
$fullQuestionsScore = array_reduce(
$objExercise->selectQuestionList(true, true),
function ($acc, $questionId) {
$objQuestionTmp = Question::read($questionId);
return $acc + $objQuestionTmp->selectWeighting();
},
0
);
$objExercise->questionSelectionType = $originalSelectionType;
$alert .= sprintf( $alert .= sprintf(
get_lang('XQuestionsWithTotalScoreY'), get_lang('XQuestionsWithTotalScoreY'),
$nbrQuestions, $nbrQuestions,
$maxScoreAllQuestions $fullQuestionsScore
); );
} }
if ($objExercise->random > 0) { if ($objExercise->random > 0) {
$alert .= '<br />'.sprintf(get_lang('OnlyXQuestionsPickedRandomly'), $objExercise->random); $alert .= '<br />'.sprintf(get_lang('OnlyXQuestionsPickedRandomly'), $objExercise->random);
$alert .= sprintf(
'<br>'.get_lang('XQuestionsSelectedWithTotalScoreY'),
$objExercise->random,
$maxScoreAllQuestions
);
} }
if ($showPagination === false) {
if ($objExercise->questionSelectionType >= EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED) {
$alert .= sprintf(
'<br>'.get_lang('XQuestionsSelectedWithTotalScoreY'),
count($questionList),
$maxScoreAllQuestions
);
}
}
echo Display::return_message($alert, 'normal', false); echo Display::return_message($alert, 'normal', false);
} elseif (isset($_GET['newQuestion'])) { } elseif (isset($_GET['newQuestion'])) {
// we are in create a new question from question pool not in a test // we are in create a new question from question pool not in a test

Loading…
Cancel
Save