diff --git a/main/exercice/testcategory.class.php b/main/exercice/testcategory.class.php index 055c8aa8c7..2e3c853b3b 100644 --- a/main/exercice/testcategory.class.php +++ b/main/exercice/testcategory.class.php @@ -14,6 +14,7 @@ class Testcategory public $category_array_tree; public $type; public $course_id; + public $c_id; // from db /** * Constructor of the class Category @@ -61,12 +62,11 @@ class Testcategory } /** - * Return the Testcategory object with id=in_id - * @param int $id - * @return bool - * @assert () === false - */ - + * Return the Testcategory object with id=in_id + * @param int $id + * @return bool + * @assert () === false + */ public function getCategory($id) { $t_cattable = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); @@ -80,15 +80,16 @@ class Testcategory $this->title = $this->name = $row['title']; $this->description = $row['description']; $this->parent_id = $row['parent_id']; + $this->c_id = $row['c_id']; } else { return false; } } /** - * Add Testcategory in the database if name doesn't already exists - * - */ + * Add Testcategory in the database if name doesn't already exists + * + */ public function addCategoryInBDD() { $t_cattable = Database :: get_course_table(TABLE_QUIZ_QUESTION_CATEGORY); @@ -1148,4 +1149,36 @@ class Testcategory } } + + public function editForm(& $form) { + + // settting the form elements + $form->addElement('header', get_lang('EditCategory')); + $form->addElement('hidden', 'category_id'); + $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6')); + $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200')); + $category_parent_list = array(); + + $script = null; + if (!empty($this->parent_id)) { + $parent_cat = new Testcategory($this->parent_id); + $category_parent_list = array($parent_cat->id => $parent_cat->name); + $script .= ''; + } + $form->addElement('html', $script); + + $form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id')); + $form->addElement('style_submit_button', 'SubmitNote', get_lang('ModifyCategory'), 'class="add"'); + + // setting the defaults + $defaults = array(); + $defaults["category_id"] = $this->id; + $defaults["category_name"] = $this->name; + $defaults["category_description"] = $this->description; + $defaults["parent_id"] = $this->parent_id; + $form->setDefaults($defaults); + + // setting the rules + $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required'); + } } diff --git a/main/exercice/tests_category.php b/main/exercice/tests_category.php index 7ac854c161..f48c4a3ef0 100644 --- a/main/exercice/tests_category.php +++ b/main/exercice/tests_category.php @@ -61,7 +61,7 @@ $htmlHeadXtra[] = ' } }); } - }, + } }); } }); @@ -112,37 +112,13 @@ function edit_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']); + $objcat = new Testcategory($category_id); // initiate the object $form = new FormValidator('note', 'post', api_get_self().'?action='.$in_action.'&category_id='.$category_id."&type=".$type); - // settting the form elements - $form->addElement('header', get_lang('EditCategory')); - $form->addElement('hidden', 'category_id'); - $form->addElement('text', 'category_name', get_lang('CategoryName'), array('class' => 'span6')); - $form->add_html_editor('category_description', get_lang('CategoryDescription'), false, false, array('ToolbarSet' => 'test_category', 'Width' => '90%', 'Height' => '200')); - $category_parent_list = array(); - - if (!empty($objcat->parent_id)) { - $parent_cat = new Testcategory($objcat->parent_id); - $category_parent_list = array($parent_cat->id => $parent_cat->name); - echo ''; - } - - $form->addElement('select', 'parent_id', get_lang('Parent'), $category_parent_list, array('id' => 'parent_id')); - $form->addElement('style_submit_button', 'SubmitNote', get_lang('ModifyCategory'), 'class="add"'); - - // setting the defaults - $defaults = array(); - $defaults["category_id"] = $objcat->id; - $defaults["category_name"] = $objcat->name; - $defaults["category_description"] = $objcat->description; - $defaults["parent_id"] = $objcat->parent_id; - $form->setDefaults($defaults); - - // setting the rules - $form->addRule('category_name', get_lang('ThisFieldIsRequired'), 'required'); + $objcat->editForm($form); // The validation or display if ($form->validate()) { @@ -397,4 +373,4 @@ function protectJSDialogQuote($in_txt) { $res = str_replace("'", "\'", $res); $res = str_replace('"', "\'\'", $res); // super astuce pour afficher les " dans les boite de dialogue return $res; -} \ No newline at end of file +} diff --git a/main/inc/Entity/CQuizCategory.php b/main/inc/Entity/CQuizCategory.php index b55ffe8a6e..a14e73a813 100644 --- a/main/inc/Entity/CQuizCategory.php +++ b/main/inc/Entity/CQuizCategory.php @@ -46,6 +46,12 @@ class CQuizCategory */ private $description; + /** + * + * @ORM\Column(name="parent_id", type="integer") + */ + private $parentId; + /** * @Gedmo\TreeParent * @ORM\ManyToOne(targetEntity="CQuizCategory", inversedBy="children") @@ -53,7 +59,6 @@ class CQuizCategory */ private $parent; - /** * @Gedmo\TreeLeft * @ORM\Column(name="lft", type="integer") @@ -205,4 +210,27 @@ class CQuizCategory { return $this->description; } + + /** + * Set cId + * + * @param integer $cId + * @return CQuizQuestionCategory + */ + public function setParentId($id) + { + $this->parentId = $id; + + return $this; + } + + /** + * Get cId + * + * @return integer + */ + public function getParentId() + { + return $this->parentId; + } } diff --git a/main/inc/routes.php b/main/inc/routes.php index abf16be0a2..c50d460ef9 100644 --- a/main/inc/routes.php +++ b/main/inc/routes.php @@ -510,6 +510,11 @@ $app->get('/admin/questionmanager/questions/get-questions-by-category/{categoryI ->before($adminAndQuestionManagerCondition) ->bind('admin_get_questions_by_category'); +$app->match('/admin/questionmanager/categories/{id}/edit', 'question_manager.controller:editCategoryAction', 'GET|POST') + ->assert('type', '.+') + ->before($adminAndQuestionManagerCondition) + ->bind('admin_category_edit'); + /** Editor */ $app->match('/editor/filemanager', 'editor.controller:filemanagerAction', 'GET|POST') ->assert('type', '.+') diff --git a/main/template/default/admin/questionmanager/edit_category.tpl b/main/template/default/admin/questionmanager/edit_category.tpl new file mode 100644 index 0000000000..144753ee3b --- /dev/null +++ b/main/template/default/admin/questionmanager/edit_category.tpl @@ -0,0 +1,47 @@ +{% extends app.template_style ~ "/layout/layout_1_col.tpl" %} +{% block content %} + + + {{ form }} +{% endblock %} diff --git a/main/template/default/admin/questionmanager/questions.tpl b/main/template/default/admin/questionmanager/questions.tpl index ca8a9ae7d3..77761b8d3a 100644 --- a/main/template/default/admin/questionmanager/questions.tpl +++ b/main/template/default/admin/questionmanager/questions.tpl @@ -121,8 +121,15 @@