Learnpath: Fix prerequisite on test with random questions shows wrong maximum - refs GH#3612

Author: @BorjaSanchezBeezNest
pull/4546/head
Borja Sánchez 3 years ago committed by GitHub
parent 84350f397c
commit 93cab61758
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      main/exercise/admin.php
  2. 26
      main/exercise/exercise.class.php

@ -381,7 +381,8 @@ if ($inATest) {
$originalSelectionType = $objExercise->questionSelectionType; $originalSelectionType = $objExercise->questionSelectionType;
$objExercise->questionSelectionType = EX_Q_SELECTION_ORDERED; $objExercise->questionSelectionType = EX_Q_SELECTION_ORDERED;
$fullQuestionsScore = array_reduce( $outMaxScore = 0;
$outMaxScore = array_reduce(
$objExercise->selectQuestionList(true, true), $objExercise->selectQuestionList(true, true),
function ($acc, $questionId) { function ($acc, $questionId) {
$objQuestionTmp = Question::read($questionId); $objQuestionTmp = Question::read($questionId);
@ -396,7 +397,7 @@ if ($inATest) {
$alert .= sprintf( $alert .= sprintf(
get_lang('XQuestionsWithTotalScoreY'), get_lang('XQuestionsWithTotalScoreY'),
$nbrQuestions, $nbrQuestions,
$fullQuestionsScore $outMaxScore
); );
} }
if ($objExercise->random > 0) { if ($objExercise->random > 0) {

@ -8312,27 +8312,11 @@ class Exercise
*/ */
public function get_max_score() public function get_max_score()
{ {
$out_max_score = 0; $outMaxScore = 0;
// list of question's id !!! the array key start at 1 !!! // list of question's id !!! the array key start at 1 !!!
$questionList = $this->selectQuestionList(true); $questionList = $this->selectQuestionList(true);
// test is randomQuestions - see field random of test if ($this->random > 0 && $this->randomByCat > 0) {
if ($this->random > 0 && 0 == $this->randomByCat) {
$numberRandomQuestions = $this->random;
$questionScoreList = [];
foreach ($questionList as $questionId) {
$tmpobj_question = Question::read($questionId);
if (is_object($tmpobj_question)) {
$questionScoreList[] = $tmpobj_question->weighting;
}
}
rsort($questionScoreList);
// add the first $numberRandomQuestions value of score array to get max_score
for ($i = 0; $i < min($numberRandomQuestions, count($questionScoreList)); $i++) {
$out_max_score += $questionScoreList[$i];
}
} elseif ($this->random > 0 && $this->randomByCat > 0) {
// test is random by category // test is random by category
// get the $numberRandomQuestions best score question of each category // get the $numberRandomQuestions best score question of each category
$numberRandomQuestions = $this->random; $numberRandomQuestions = $this->random;
@ -8352,18 +8336,18 @@ class Exercise
foreach ($tab_categories_scores as $tab_scores) { foreach ($tab_categories_scores as $tab_scores) {
rsort($tab_scores); rsort($tab_scores);
for ($i = 0; $i < min($numberRandomQuestions, count($tab_scores)); $i++) { for ($i = 0; $i < min($numberRandomQuestions, count($tab_scores)); $i++) {
$out_max_score += $tab_scores[$i]; $outMaxScore += $tab_scores[$i];
} }
} }
} else { } else {
// standard test, just add each question score // standard test, just add each question score
foreach ($questionList as $questionId) { foreach ($questionList as $questionId) {
$question = Question::read($questionId, $this->course); $question = Question::read($questionId, $this->course);
$out_max_score += $question->weighting; $outMaxScore += $question->weighting;
} }
} }
return $out_max_score; return $outMaxScore;
} }
/** /**

Loading…
Cancel
Save