Adding visibility field in order to hide the first categories see BT#6540

skala
Julio Montoya 13 years ago
parent d0952ee0fb
commit 5ef033adee
  1. 57
      main/exercice/exercise.class.php
  2. 2
      main/exercice/exercise_show.php
  3. 10
      main/exercice/exercise_submit.php
  4. 32
      main/exercice/testcategory.class.php
  5. 6
      main/exercice/tests_category.php
  6. 39
      main/inc/Entity/CQuizCategory.php

@ -775,7 +775,7 @@ class Exercise
}
}
}
}
}
if (!empty($questions_by_category)) {
$temp_question_list = array();
@ -795,7 +795,7 @@ class Exercise
if (!empty($numberOfQuestions)) {
$elements = Testcategory::getNElementsFromArray($categoryQuestionList, $numberOfQuestions, $randomizeQuestions);
if (!empty($elements)) {
if (!empty($elements)) {
$temp_question_list[$category_id] = $elements;
$categoryQuestionList = $elements;
}
@ -832,6 +832,7 @@ class Exercise
$cat = new Testcategory();
// Setting category order.
switch ($questionSelectionType) {
case EX_Q_SELECTION_ORDERED: // 1
case EX_Q_SELECTION_RANDOM: // 2
@ -864,12 +865,12 @@ class Exercise
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', 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;
@ -886,6 +887,7 @@ class Exercise
$repo = $em->getRepository('Entity\CQuizCategory');
$newCategoryList = array();
// var_dump($questions_by_category);
foreach ($questions_by_category as $categoryId => $questionList) {
@ -903,11 +905,39 @@ class Exercise
} else {
$categoryEntity = $parentsLoaded[$cat['parent_id']];
}
$path = $repo->getPath($categoryEntity);
$index = 0;
if ($this->categoryMinusOne) {
$index = 1;
//$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;
}
/*
if (isset($path) && isset($path[$index])) {
$categoryParentId = $path[$index]->getIid();
@ -917,7 +947,7 @@ class Exercise
$categoryParentInfo['title'] = $path[$index]->getTitle();
$categoryParentInfo['name'] = $path[$index]->getTitle();
$categoryParentInfo['parent_id'] = null;
}
}*/
}
$cat['parent_info'] = $categoryParentInfo;
$newCategoryList[$categoryId] = array(
@ -927,6 +957,7 @@ class Exercise
}
$result['category_with_questions_list'] = $newCategoryList;
}
//echo '<pre>'; print_r($result);
return $result;
}
@ -5988,6 +6019,8 @@ class Exercise
$selectionType = $this->getQuestionSelectionType();
$useRootAsCategoryTitle = false;
// Grouping questions per parent category see BT#6540
if (in_array(
$selectionType,
array(
@ -6007,11 +6040,19 @@ class Exercise
// The new categories list starts empty
$newCategoryList = array();
foreach ($categories as $category) {
if ($this->categoryMinusOne) {
/*if ($this->categoryMinusOne) {
$rootElement = $category['id'];
} else {
$rootElement = $category['root'];
}*/
$rootElement = $category['root'];
if (isset($category['parent_info'])) {
$rootElement = $category['parent_info']['id'];
}
//$rootElement = $category['id'];
// If the current category's ancestor was never seen
// before, then declare it and assign the current
// category to it.

@ -725,7 +725,7 @@ if (!empty($category_list) && ($show_results || $show_only_total_score)) {
'score' => $my_total_score_temp,
'total' => $totalWeighting
);
echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list);
echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list, $objExercise->categoryMinusOne);
}
echo $total_score_text;

@ -362,7 +362,7 @@ if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSessi
// if the specified exercise doesn't exist or is disabled
if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath'))) {
if ($debug) {
if ($debug) {
error_log('1.1. Error while reading the exercise');
}
unset ($objExercise);
@ -376,7 +376,7 @@ if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSessi
}
}
// $objExercise = new Exercise(); $objExercise->read($exerciseId);
$objExercise = new Exercise(); $objExercise->read($exerciseId);
//2. Checking if $objExercise is set
if (!isset($objExercise) && isset($exerciseInSession)) {
@ -518,9 +518,9 @@ if ($objExercise->selectAttempts() > 0) {
// 5. Getting user exercise info (if the user took the exam before) - generating exe_id
$exercise_stat_info = $objExercise->getStatTrackExerciseInfo($learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
//if (1) {
$questionListInSession = Session::read('questionList');
if (!isset($questionListInSession)) {
if (1) {
//$questionListInSession = Session::read('questionList');
//if (!isset($questionListInSession)) {
// Selects the list of question ID
$questionList = $objExercise->getQuestionList();

@ -16,6 +16,7 @@ class Testcategory
public $course_id;
public $c_id; // from db
public $root;
public $visibility;
/**
* Constructor of the class Category
@ -31,7 +32,7 @@ class Testcategory
* @param string $type
* @param int $course_id
*/
public function Testcategory($in_id = 0, $in_name = '', $in_description = "", $parent_id = 0, $type = 'simple', $course_id = null)
public function Testcategory($in_id = 0, $in_name = '', $in_description = "", $parent_id = 0, $type = 'simple', $course_id = null, $visibility = 1)
{
if ($in_id != 0 && $in_name == "") {
$tmpobj = new Testcategory();
@ -44,6 +45,7 @@ class Testcategory
$this->parent_path = $this->name;
$this->c_id = $tmpobj->c_id;
$this->root = $tmpobj->root;
$this->visibility = $tmpobj->visibility;
if (!empty($tmpobj->parent_id)) {
$category = new Testcategory($tmpobj->parent_id);
@ -54,10 +56,11 @@ class Testcategory
$this->name = $in_name;
$this->description = $in_description;
$this->parent_id = $parent_id;
$this->visibility = $visibility;
}
$this->type = $type;
if (!empty($course_id)) {
if (!empty($course_id)) {
$this->course_id = $course_id;
} else {
$this->course_id = api_get_course_int_id();
@ -89,6 +92,7 @@ class Testcategory
$this->parent_id = $row['parent_id'];
$this->c_id = $row['c_id'];
$this->root = $row['root'];
$this->visibility = $row['visibility'];
} else {
return false;
@ -169,6 +173,7 @@ class Testcategory
$category->setTitle($this->name);
$category->setDescription($this->description);
$category->setVisibility($this->visibility);
if (!empty($this->parent_id)) {
foreach ($this->parent_id as $parentId) {
@ -690,8 +695,7 @@ class Testcategory
WHERE exercice_id = $exerciseId AND
qrc.c_id = ".api_get_course_int_id()."
";
$res = Database::query($sql);
$res = Database::query($sql);
$categories = array();
while ($data = Database::fetch_array($res)) {
@ -715,7 +719,6 @@ class Testcategory
$newCategoryList[$categoryId] = $categories[$categoryId];
//}
}
return $newCategoryList;
}
@ -956,8 +959,6 @@ class Testcategory
$em = $app['orm.em'];
$repo = $em->getRepository('Entity\CQuizCategory');
$redefineCategoryList = array();
if (!empty($category_list) && count($category_list) > 1) {
$globalCategoryScore = array();
@ -1054,27 +1055,21 @@ class Testcategory
WHERE exercise_id = {$exercise_id} ";
if (!empty($order)) {
$sql .= "ORDER BY $order";
$sql .= " ORDER BY $order";
}
$categories = array();
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($row = Database::fetch_array($result, 'ASSOC')) {
if ($excludeCategoryWithNoQuestions) {
//if ($row['count_questions'] == 0 || $row['count_questions'] == -1) {
/*0 means no questions selected this options is also filtered in the function:
Exercise::pickQuestionsPerCategory() */
if ($row['count_questions'] == 0) {
continue;
}
}
$categories[$row['category_id']] = $row;
}
if (!empty($list)) {
//$categories = $this->sort_tree_array($list);
}
}
if ($shuffle) {
ArrayClass::shuffle_assoc($categories);
}
@ -1163,6 +1158,12 @@ class Testcategory
$form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200'));
$category_parent_list = array();
$options = array(
'1' => get_lang('Visible'),
'0' => get_lang('Hidden')
);
$form->addElement('select', 'visibility', get_lang('Visibility'), $options);
$script = null;
if (!empty($this->parent_id)) {
$parent_cat = new Testcategory($this->parent_id);
@ -1180,6 +1181,7 @@ class Testcategory
$defaults["category_name"] = $this->name;
$defaults["category_description"] = $this->description;
$defaults["parent_id"] = $this->parent_id;
$defaults["visibility"] = $this->visibility;
$form->setDefaults($defaults);
// setting the rules

@ -129,7 +129,8 @@ function edit_category_form($in_action, $type = 'simple') {
$v_name = $values['category_name'];
$v_description = $values['category_description'];
$parent_id = isset($values['parent_id']) ? $values['parent_id'] : null;
$objcat = new Testcategory($v_id, $v_name, $v_description, $parent_id, $type);
$visibility = isset($values['visibility']) ? $values['visibility'] : 1;
$objcat = new Testcategory($v_id, $v_name, $v_description, $parent_id, $type, null, $visibility);
if ($objcat->modifyCategory()) {
Display::display_confirmation_message(get_lang('MofidfyCategoryDone'));
} else {
@ -153,7 +154,8 @@ function edit_category_form($in_action, $type = 'simple') {
}
// process to delete a category
function delete_category_form($in_action, $type = 'simple') {
function delete_category_form($in_action, $type = 'simple')
{
$in_action = Security::remove_XSS($in_action);
if (isset($_GET['category_id']) && is_numeric($_GET['category_id'])) {
$category_id = Security::remove_XSS($_GET['category_id']);

@ -89,6 +89,12 @@ class CQuizCategory
*/
private $children;
/**
*
* @ORM\Column(name="visibility", type="integer")
*/
private $visibility;
/**
* @ORM\OneToMany(targetEntity="CQuizQuestionRelCategory", mappedBy="category")
**/
@ -217,20 +223,39 @@ class CQuizCategory
* @param integer $cId
* @return CQuizQuestionCategory
*/
public function setParentId($id)
{
public function setParentId($id)
{
$this->parentId = $id;
return $this;
}
}
/**
/**
* Get cId
*
* @return integer
*/
public function getParentId()
{
public function getParentId()
{
return $this->parentId;
}
}
/**
* @return integer
*/
public function getVisibility()
{
return $this->visibility;
}
/**
* @param $visibility
* @return $this
*/
public function setVisibility($visibility)
{
$this->visibility = $visibility;
return $this;
}
}

Loading…
Cancel
Save