Fix exercise max score (when setting LP prerequisites) see #2189

pull/2487/head
jmontoyaa 7 years ago
parent 751894b60b
commit 0df6764e7f
  1. 22
      main/exercise/exercise.class.php
  2. 3
      main/lp/learnpath.class.php

@ -7483,14 +7483,13 @@ class Exercise
if ($this->random > 0 && $this->randomByCat == 0) {
$numberRandomQuestions = $this->random;
$questionScoreList = array();
for ($i = 1; $i <= count($questionList); $i++) {
if (isset($questionList[$i])) {
$tmpobj_question = Question::read($questionList[$i]);
if (is_object($tmpobj_question)) {
$questionScoreList[] = $tmpobj_question->weighting;
}
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++) {
@ -7499,16 +7498,17 @@ class Exercise
} elseif ($this->random > 0 && $this->randomByCat > 0) {
// test is random by category
// get the $numberRandomQuestions best score question of each category
$numberRandomQuestions = $this->random;
$tab_categories_scores = array();
for ($i = 1; $i <= count($questionList); $i++) {
$question_category_id = TestCategory::getCategoryForQuestion($questionList[$i]);
foreach ($questionList as $questionId) {
$question_category_id = TestCategory::getCategoryForQuestion($questionId);
if (!is_array($tab_categories_scores[$question_category_id])) {
$tab_categories_scores[$question_category_id] = array();
}
$tmpobj_question = Question::read($questionList[$i]);
$tab_categories_scores[$question_category_id][] = $tmpobj_question->weighting;
$tmpobj_question = Question::read($questionId);
if (is_object($tmpobj_question)) {
$tab_categories_scores[$question_category_id][] = $tmpobj_question->weighting;
}
}
// here we've got an array with first key, the category_id, second key, score of question for this cat

@ -9428,10 +9428,9 @@ class learnpath
if ($item['item_type'] == TOOL_QUIZ) {
// lets update max_score Quiz information depending of the Quiz Advanced properties
$tmp_obj_lp_item = new LpItem($course_id, $item['id']);
$tmp_obj_exercice = new Exercise();
$tmp_obj_exercice = new Exercise($course_id);
$tmp_obj_exercice->read($tmp_obj_lp_item->path);
$tmp_obj_lp_item->max_score = $tmp_obj_exercice->get_max_score();
$tmp_obj_lp_item->update_in_bdd();
$item['max_score'] = $tmp_obj_lp_item->max_score;

Loading…
Cancel
Save