function get_validated_question_list() { $tabres = array(); $isRandomByCategory = $this->isRandomByCat(); if ($isRandomByCategory == 0) { if ($this->isRandom()) { $tabres = $this->selectRandomList(); } else { $tabres = $this->selectQuestionList(); } } else { if ($this->isRandom()) { // USE question categories // get questions by category for this exercice // we have to choice $objExercise->random question in each array values of $tabCategoryQuestions // key of $tabCategoryQuestions are the categopy id (0 for not in a category) // value is the array of question id of this category $questionList = array(); $tabCategoryQuestions = Testcategory::getQuestionsByCat($this->id); $isRandomByCategory = $this->selectRandomByCat(); // on tri les categories en fonction du terme entre [] en tete de la description de la categorie /* * ex de catégories : * [biologie] Maitriser les mecanismes de base de la genetique * [biologie] Relier les moyens de depenses et les agents infectieux * [biologie] Savoir ou est produite l'enrgie dans les cellules et sous quelle forme * [chimie] Classer les molles suivant leur pouvoir oxydant ou reacteur * [chimie] Connaître la denition de la theoie acide/base selon Brönsted * [chimie] Connaître les charges des particules * On veut dans l'ordre des groupes definis par le terme entre crochet au debut du titre de la categorie */ // If test option is Grouped By Categories if ($isRandomByCategory == 2) { $tabCategoryQuestions = Testcategory::sortTabByBracketLabel($tabCategoryQuestions); } while (list($cat_id, $tabquestion) = each($tabCategoryQuestions)) { $number_of_random_question = $this->random; if ($this->random == -1) { $number_of_random_question = count($this->questionList); } $questionList = array_merge($questionList, Testcategory::getNElementsFromArray($tabquestion, $number_of_random_question)); } // shuffle the question list if test is not grouped by categories if ($isRandomByCategory == 1) { shuffle($questionList); // or not } $tabres = $questionList; } else { // Problem, random by category has been selected and we have no $this->isRandom nnumber of question selected // Should not happened } } return $tabres; }
/** * Select N values from the questions per category array * * @param array $question_list * @param array $questions_by_category per category * @param array how many questions per category * @param bool $randomizeQuestions * @param bool flat result * * @return array */ private function pickQuestionsPerCategory($categoriesAddedInExercise, $question_list, &$questions_by_category, $flatResult = true, $randomizeQuestions = false) { $addAll = true; $categoryCountArray = array(); // Getting how many questions will be selected per category. if (!empty($categoriesAddedInExercise)) { $addAll = false; // Parsing question according the category rel exercise settings foreach ($categoriesAddedInExercise as $category_info) { $category_id = $category_info['category_id']; if (isset($questions_by_category[$category_id])) { // How many question will be picked from this category. $count = $category_info['count_questions']; // -1 means all questions if ($count == -1) { $categoryCountArray[$category_id] = 999; } else { $categoryCountArray[$category_id] = $count; } } } } if (!empty($questions_by_category)) { $temp_question_list = array(); foreach ($questions_by_category as $category_id => &$categoryQuestionList) { if (isset($categoryCountArray) && !empty($categoryCountArray)) { if (isset($categoryCountArray[$category_id])) { $numberOfQuestions = $categoryCountArray[$category_id]; } else { $numberOfQuestions = 0; } } if ($addAll) { $numberOfQuestions = 999; } if (!empty($numberOfQuestions)) { $elements = Testcategory::getNElementsFromArray($categoryQuestionList, $numberOfQuestions, $randomizeQuestions); if (!empty($elements)) { $temp_question_list[$category_id] = $elements; $categoryQuestionList = $elements; } } } if (!empty($temp_question_list)) { if ($flatResult) { $temp_question_list = ArrayClass::array_flatten($temp_question_list); } $question_list = $temp_question_list; } } return $question_list; }