From 79078610bb53bb3dce7172f33d1613324cc8b4d6 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 17 May 2016 15:47:26 -0500 Subject: [PATCH] Fix getNumberOfQuestionRandomByCategory and getNumberMaxQuestionByCat --- main/exercice/TestCategory.php | 45 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/main/exercice/TestCategory.php b/main/exercice/TestCategory.php index 36c7647d776..82de0f2c0cb 100644 --- a/main/exercice/TestCategory.php +++ b/main/exercice/TestCategory.php @@ -455,17 +455,20 @@ public static function getNumberOfQuestionRandomByCategory($exerciseId, $in_nbra { $nbquestionresult = 0; $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); - for ($i=0; $i < count($tabcatid); $i++) { - if ($tabcatid[$i] > 0 && $tabcatid[$i] > 0) { // 0 = no category for this questio - $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]); - if ($nbQuestionInThisCat > $in_nbrandom) { - $nbquestionresult += $in_nbrandom; - } - else { - $nbquestionresult += $nbQuestionInThisCat; - } - } - } + + foreach ($tabcatid as $category) { + if (empty($category['id'])) { + continue; + } + + $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $category['id']); + + if ($nbQuestionInThisCat > $in_nbrandom) { + $nbquestionresult += $in_nbrandom; + } else { + $nbquestionresult += $nbQuestionInThisCat; + } + } return $nbquestionresult; } @@ -701,14 +704,18 @@ public static function getNumberMaxQuestionByCat($exerciseId) $res_num_max = 0; // foreach question $tabcatid = TestCategory::getListOfCategoriesIDForTest($exerciseId); - for ($i=0; $i < count($tabcatid); $i++) { - if ($tabcatid[$i] > 0) { // 0 = no category for this question - $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $tabcatid[$i]); - if ($nbQuestionInThisCat > $res_num_max) { - $res_num_max = $nbQuestionInThisCat; - } - } - } + + foreach ($tabcatid as $category) { + if (empty($category['id'])) { + continue; + } + + $nbQuestionInThisCat = TestCategory::getNumberOfQuestionsInCategoryForTest($exerciseId, $category['id']); + + if ($nbQuestionInThisCat > $res_num_max) { + $res_num_max = $nbQuestionInThisCat; + } + } return $res_num_max; }