/** * 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, $this->course['real_id'], 'title 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_RANDOM_QUESTIONS_ORDERED: // 4 // 4 case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED_NO_GROUPED: // 7 $categoriesAddedInExercise = $cat->getCategoryExerciseTree($this, $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, $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, $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, $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, $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)) { /*$em = Database::getManager(); $repo = $em->getRepository('ChamiloCoreBundle:CQuizCategory');*/ $newCategoryList = array(); foreach ($questions_by_category as $categoryId => $questionList) { $cat = new TestCategory($categoryId); $cat = (array) $cat; $cat['iid'] = $cat['id']; //*$cat['name'] = $cat['name']; $categoryParentInfo = null; // Parent is not set no loop here if (!empty($cat['parent_id'])) { if (!isset($parentsLoaded[$cat['parent_id']])) { $categoryEntity = $em->find('ChamiloCoreBundle: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 \Chamilo\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; }