|
|
|
|
@ -48,6 +48,7 @@ define('EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM_NO_GROUPED', 8); |
|
|
|
|
|
|
|
|
|
define('EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED', 9); |
|
|
|
|
define('EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM', 10); |
|
|
|
|
define('EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_SUB_CAT_RANDOM_QUESTIONS_RANDOM', 11); |
|
|
|
|
$debug = false; //All exercise scripts should depend in this debug variable |
|
|
|
|
|
|
|
|
|
class Exercise |
|
|
|
|
@ -872,7 +873,20 @@ class Exercise |
|
|
|
|
$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); |
|
|
|
|
// Added new parameter in order to randomize sub categories see BT#6943 |
|
|
|
|
/* |
|
|
|
|
@todo this should be false but because there's a new option called EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_SUB_CAT_RANDOM_QUESTIONS_RANDOM |
|
|
|
|
I'm leaving this with true because there could be a lot of exercise already set with this behaviour. |
|
|
|
|
*/ |
|
|
|
|
$subCategoryShuffle = true; |
|
|
|
|
$categoriesAddedInExercise = $cat->getCategoryExerciseTree($this->id, $this->course['real_id'], 'root, lft ASC', false, true, $subCategoryShuffle); |
|
|
|
|
$questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list, $categoriesAddedInExercise, $courseId); |
|
|
|
|
$question_list = $this->pickQuestionsPerCategory($categoriesAddedInExercise, $question_list, $questions_by_category, true, true); |
|
|
|
|
break; |
|
|
|
|
case EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_SUB_CAT_RANDOM_QUESTIONS_RANDOM: |
|
|
|
|
// Added new parameter in order to randomize sub categories see BT#6943 |
|
|
|
|
$subCategoryShuffle = true; |
|
|
|
|
$categoriesAddedInExercise = $cat->getCategoryExerciseTree($this->id, $this->course['real_id'], 'root, lft ASC', false, true, $subCategoryShuffle); |
|
|
|
|
$questions_by_category = Testcategory::getQuestionsByCat($this->id, $question_list, $categoriesAddedInExercise, $courseId); |
|
|
|
|
$question_list = $this->pickQuestionsPerCategory($categoriesAddedInExercise, $question_list, $questions_by_category, true, true); |
|
|
|
|
break; |
|
|
|
|
@ -882,21 +896,30 @@ class Exercise |
|
|
|
|
$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)) { |
|
|
|
|
$newCategoryList = $this->fillQuestionByCategoryArray($questions_by_category); |
|
|
|
|
$result['category_with_questions_list'] = $newCategoryList; |
|
|
|
|
} |
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param array $questions_by_category |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
function fillQuestionByCategoryArray($questions_by_category) |
|
|
|
|
{ |
|
|
|
|
global $app; |
|
|
|
|
$em = $app['orm.em']; |
|
|
|
|
$repo = $em->getRepository('Entity\CQuizCategory'); |
|
|
|
|
|
|
|
|
|
$newCategoryList = array(); |
|
|
|
|
|
|
|
|
|
if (!empty($questions_by_category)) { |
|
|
|
|
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'])) { |
|
|
|
|
@ -946,9 +969,8 @@ class Exercise |
|
|
|
|
'question_list' => $questionList |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
$result['category_with_questions_list'] = $newCategoryList; |
|
|
|
|
} |
|
|
|
|
return $result; |
|
|
|
|
return $newCategoryList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -1847,6 +1869,7 @@ class Exercise |
|
|
|
|
*/ |
|
|
|
|
EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED => get_lang('OrderedCategoriesByParentWithQuestionsOrdered'), |
|
|
|
|
EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM => get_lang('OrderedCategoriesByParentWithQuestionsRandom'), |
|
|
|
|
//EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_SUB_CAT_RANDOM_QUESTIONS_RANDOM => get_lang('OrderedCategoriesByParentWithRandomSubCategoriesWithQuestionsRandom'), |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$form->addElement( |
|
|
|
|
@ -5488,15 +5511,16 @@ class Exercise |
|
|
|
|
if (!empty($distribution)) { |
|
|
|
|
$dataTracking = $distribution->getDataTracking(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($dataTracking)) { |
|
|
|
|
$questionList = explode(',', $dataTracking); |
|
|
|
|
if (!empty($questionList)) { |
|
|
|
|
//shuffle($questionList); |
|
|
|
|
} |
|
|
|
|
/*$this->categoryWithQuestionList = TestCategory::getCategoriesFromQuestionList( |
|
|
|
|
$questionList, |
|
|
|
|
$this->course_id |
|
|
|
|
);*/ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->setMediaList($questionList, $this->course_id); |
|
|
|
|
@ -6014,11 +6038,22 @@ class Exercise |
|
|
|
|
|
|
|
|
|
$categoryList = Session::read('categoryList'); |
|
|
|
|
|
|
|
|
|
// Use session too boost performance the variable is deleted in exercise_result.php |
|
|
|
|
// @todo Use session too boost performance the variable is deleted in exercise_result.php |
|
|
|
|
$categoryList = null; |
|
|
|
|
|
|
|
|
|
if (empty($categoryList)) { |
|
|
|
|
$categoryList = $this->getListOfCategoriesWithQuestionForTest(); |
|
|
|
|
|
|
|
|
|
// Old behaviour when sub categories are static. |
|
|
|
|
//$categoryList = $this->getListOfCategoriesWithQuestionForTest(); |
|
|
|
|
|
|
|
|
|
// Generating category list from the question list, because subcategories can be randomized! |
|
|
|
|
$questionByCategory = TestCategory::getCategoriesFromQuestionList( |
|
|
|
|
$questionList, |
|
|
|
|
$this->course_id |
|
|
|
|
); |
|
|
|
|
$categoryListFromQuestionList = $this->fillQuestionByCategoryArray($questionByCategory); |
|
|
|
|
$categoryList = $this->getListOfCategoriesWithQuestionForTest($categoryListFromQuestionList); |
|
|
|
|
|
|
|
|
|
Session::write('categoryList', $categoryList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -6049,8 +6084,8 @@ class Exercise |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Count the number of answered, unanswered and 'for review' questions - see BT#6523 |
|
|
|
|
$numa = count(array_flip(array_merge($exercise_result,$remindList))); |
|
|
|
|
$numu = count($questionListFlatten)-$numa; |
|
|
|
|
$numa = count(array_flip(array_merge($exercise_result, $remindList))); |
|
|
|
|
$numu = count($questionListFlatten) - $numa; |
|
|
|
|
$numr = count($remindList); |
|
|
|
|
$html .= Display::label(sprintf(get_lang('AnsweredZ'),'a'), 'success').'<br />'.Display::label(sprintf(get_lang('UnansweredZ'),'b')).'<br />'. |
|
|
|
|
$reviewAnswerLabel.$currentAnswerLabel. |
|
|
|
|
@ -6064,12 +6099,11 @@ class Exercise |
|
|
|
|
return $html; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param array media question array |
|
|
|
|
* @return array question list (flatten not grouped by Medias) |
|
|
|
|
*/ |
|
|
|
|
public function getListOfCategoriesWithQuestionForTest() |
|
|
|
|
public function getListOfCategoriesWithQuestionForTest($categoryList = null) |
|
|
|
|
{ |
|
|
|
|
$newMediaList = array(); |
|
|
|
|
$mediaQuestions = $this->getMediaList(); |
|
|
|
|
@ -6082,7 +6116,10 @@ class Exercise |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (empty($categoryList)) { |
|
|
|
|
$categoryList = $this->categoryWithQuestionList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$categoriesWithQuestion = array(); |
|
|
|
|
|
|
|
|
|
if (!empty($categoryList)) { |
|
|
|
|
@ -6192,7 +6229,8 @@ class Exercise |
|
|
|
|
$selectionType, |
|
|
|
|
array( |
|
|
|
|
EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED, |
|
|
|
|
EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM |
|
|
|
|
EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM, |
|
|
|
|
EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_SUB_CAT_RANDOM_QUESTIONS_RANDOM |
|
|
|
|
) |
|
|
|
|
)) { |
|
|
|
|
$useRootAsCategoryTitle = true; |
|
|
|
|
|