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; }
/** * Selecting question list depending in the exercise-category * relationship (category table in exercise settings) * * @param array $question_list * @param int $questionSelectionType * @return array */ public function getQuestionListWithCategoryListFilteredByCategorySettings($question_list, $questionSelectionType) { $result = array('question_list' => array(), 'category_with_questions_list' => array()); // Order/random categories $cat = new Testcategory(); // Setting category order. switch ($questionSelectionType) { case EX_Q_SELECTION_ORDERED: // 1 // 1 case EX_Q_SELECTION_RANDOM: // 2 // This options are not allowed here. break; case EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED: // 3 $categoriesAddedInExercise = $cat->getCategoryExerciseTree($this->id, $this->course['real_id'], 'title DESC', false, true); $questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list, $categoriesAddedInExercise); $question_list = $this->pickQuestionsPerCategory($categoriesAddedInExercise, $question_list, $questions_by_category, true, false); break; case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED: // 4 // 4 case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED_NO_GROUPED: // 7 $categoriesAddedInExercise = $cat->getCategoryExerciseTree($this->id, $this->course['real_id'], null, true, true); $questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list, $categoriesAddedInExercise); $question_list = $this->pickQuestionsPerCategory($categoriesAddedInExercise, $question_list, $questions_by_category, true, false); break; case EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_RANDOM: // 5 $categoriesAddedInExercise = $cat->getCategoryExerciseTree($this->id, $this->course['real_id'], 'title DESC', false, true); $questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list, $categoriesAddedInExercise); $question_list = $this->pickQuestionsPerCategory($categoriesAddedInExercise, $question_list, $questions_by_category, true, true); break; case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM: // 6 // 6 case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM_NO_GROUPED: $categoriesAddedInExercise = $cat->getCategoryExerciseTree($this->id, $this->course['real_id'], null, true, true); $questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list, $categoriesAddedInExercise); $question_list = $this->pickQuestionsPerCategory($categoriesAddedInExercise, $question_list, $questions_by_category, true, true); break; case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED_NO_GROUPED: // 7 break; case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM_NO_GROUPED: // 8 break; case EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED: // 9 $categoriesAddedInExercise = $cat->getCategoryExerciseTree($this->id, $this->course['real_id'], 'root ASC, lft ASC', false, true); $questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list, $categoriesAddedInExercise); $question_list = $this->pickQuestionsPerCategory($categoriesAddedInExercise, $question_list, $questions_by_category, true, false); break; case EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM: // 10 $categoriesAddedInExercise = $cat->getCategoryExerciseTree($this->id, $this->course['real_id'], 'root, lft ASC', false, true); $questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list, $categoriesAddedInExercise); $question_list = $this->pickQuestionsPerCategory($categoriesAddedInExercise, $question_list, $questions_by_category, true, true); break; } $result['question_list'] = isset($question_list) ? $question_list : array(); $result['category_with_questions_list'] = isset($questions_by_category) ? $questions_by_category : array(); // Adding category info in the category list with question list: if (!empty($questions_by_category)) { global $app; $em = $app['orm.em']; $repo = $em->getRepository('Entity\\CQuizCategory'); $newCategoryList = array(); foreach ($questions_by_category as $categoryId => $questionList) { $cat = new Testcategory($categoryId); $cat = (array) $cat; $cat['iid'] = $cat['id']; $cat['name'] = $cat['title']; $categoryParentInfo = null; if (!empty($cat['parent_id'])) { if (!isset($parentsLoaded[$cat['parent_id']])) { $categoryEntity = $em->find('Entity\\CQuizCategory', $cat['parent_id']); $parentsLoaded[$cat['parent_id']] = $categoryEntity; } else { $categoryEntity = $parentsLoaded[$cat['parent_id']]; } $path = $repo->getPath($categoryEntity); $index = 0; if ($this->categoryMinusOne) { //$index = 1; } /** @var Entity\CQuizCategory $categoryParent*/ foreach ($path as $categoryParent) { $visibility = $categoryParent->getVisibility(); if ($visibility == 0) { $categoryParentId = $categoryId; $categoryTitle = $cat['title']; if (count($path) > 1) { continue; } } else { $categoryParentId = $categoryParent->getIid(); $categoryTitle = $categoryParent->getTitle(); } $categoryParentInfo['id'] = $categoryParentId; $categoryParentInfo['iid'] = $categoryParentId; $categoryParentInfo['parent_path'] = null; $categoryParentInfo['title'] = $categoryTitle; $categoryParentInfo['name'] = $categoryTitle; $categoryParentInfo['parent_id'] = null; break; } } $cat['parent_info'] = $categoryParentInfo; $newCategoryList[$categoryId] = array('category' => $cat, 'question_list' => $questionList); } $result['category_with_questions_list'] = $newCategoryList; } return $result; }