diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 61aaf87257..7169489919 100644 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -98,6 +98,8 @@ class Exercise public $modelType = 1; public $questionSelectionType = EX_Q_SELECTION_ORDERED; public $hideQuestionTitle = 0; + public $scoreTypeModel = 0; + public $categoryMinusOne = true; // Shows the category -1: See BT#6540 /** * Constructor of the class @@ -130,6 +132,7 @@ class Exercise $this->modelType = 1; $this->questionSelectionType = EX_Q_SELECTION_ORDERED; $this->endButton = 0; + $this->scoreTypeModel = 0; if (!empty($course_id)) { $course_info = api_get_course_info_by_id($course_id); @@ -147,6 +150,7 @@ class Exercise * Reads exercise information from the database * * @author Olivier Brouckaert + * @todo use Doctrine to manage read/writes * @param int $id - exercise ID * @param bool parse exercise question list * @return boolean - true if exercise exists, otherwise false @@ -193,6 +197,7 @@ class Exercise $this->modelType = $object->model_type; $this->questionSelectionType = $object->question_selection_type; $this->hideQuestionTitle = $object->hide_question_title; + $this->scoreTypeModel = $object->score_type_model; $this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false; $sql = "SELECT max_score FROM $table_lp_item @@ -532,6 +537,15 @@ class Exercise $this->hideQuestionTitle = intval($value); } + public function getScoreTypeModel() + { + return $this->scoreTypeModel; + } + + public function setScoreTypeModel($value) + { + $this->scoreTypeModel = intval($value); + } /** * * @param int $start @@ -743,6 +757,7 @@ class Exercise $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 @@ -845,17 +860,17 @@ class Exercise $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 + case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED_NO_GROUPED: // 7 break; case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM_NO_GROUPED: // 8 - break;*/ + break; case EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED: // 9 - $categoriesAddedInExercise = $cat->getCategoryExerciseTree($this->id, $this->course['real_id'], 'root ASC', false, true); + $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 ASC', false, true); + $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; @@ -889,16 +904,45 @@ class Exercise $categoryEntity = $parentsLoaded[$cat['parent_id']]; } $path = $repo->getPath($categoryEntity); - if (isset($path) && isset($path[0])) { - $categoryParentId = $path[0]->getIid(); + $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'] = $path[0]->getTitle(); - $categoryParentInfo['name'] = $path[0]->getTitle(); + $categoryParentInfo['title'] = $categoryTitle; + $categoryParentInfo['name'] = $categoryTitle; $categoryParentInfo['parent_id'] = null; + break; } + /* + if (isset($path) && isset($path[$index])) { + $categoryParentId = $path[$index]->getIid(); + + $categoryParentInfo['id'] = $categoryParentId; + $categoryParentInfo['iid'] = $categoryParentId; + $categoryParentInfo['parent_path'] = null; + $categoryParentInfo['title'] = $path[$index]->getTitle(); + $categoryParentInfo['name'] = $path[$index]->getTitle(); + $categoryParentInfo['parent_id'] = null; + }*/ } $cat['parent_info'] = $categoryParentInfo; $newCategoryList[$categoryId] = array( @@ -948,8 +992,6 @@ class Exercise } - if ($this->categories_grouping) { - } return $questionList; } @@ -1338,6 +1380,7 @@ class Exercise model_type = '".$this->getModelType()."', question_selection_type = '".$this->getQuestionSelectionType()."', hide_question_title = '".$this->getHideQuestionTitle()."', + score_type_model = '".$this->getScoreTypeModel()."', results_disabled='".Database::escape_string($results_disabled)."'"; } $sql .= " WHERE iid = ".Database::escape_string($id)." AND c_id = {$this->course_id}"; @@ -1355,7 +1398,7 @@ class Exercise c_id, start_time, end_time, title, description, sound, type, random, random_answers, active, max_attempt, feedback_type, expired_time, session_id, review_answers, random_by_category, text_when_finished, display_category_name, pass_percentage, end_button, email_notification_template, - results_disabled, model_type, question_selection_type, hide_question_title) + results_disabled, model_type, question_selection_type, score_type_model, hide_question_title) VALUES( ".$this->course_id.", '$start_time', @@ -1381,6 +1424,7 @@ class Exercise '".Database::escape_string($results_disabled)."', '".Database::escape_string($this->getModelType())."', '".Database::escape_string($this->getQuestionSelectionType())."', + '".Database::escape_string($this->getScoreTypeModel())."', '".Database::escape_string($this->getHideQuestionTitle())."' )"; Database::query($sql); @@ -1541,16 +1585,46 @@ class Exercise ' ); - // Random questions - // style="" and not "display:none" to avoid #4029 Random and number of attempt menu empty $form->addElement('html', '