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 @@
{% if category %} -

{{ category.title }}

+

{{ category.title }} + {% if category.cId == 0 %} + + + + {% endif %} +

{% endif %} +
{{ grid }}
diff --git a/main/template/default/layout/head.tpl b/main/template/default/layout/head.tpl index a77166c1f1..0273873d54 100644 --- a/main/template/default/layout/head.tpl +++ b/main/template/default/layout/head.tpl @@ -31,8 +31,6 @@ if ((navigator.userAgent.toLowerCase().indexOf('msie') != -1 ) && ( navigator.us } {% endraw %} - - function setCheckbox(value, table_id) { checkboxes = $("#"+table_id+" input:checkbox"); $.each(checkboxes, function(index, checkbox) { @@ -256,16 +254,13 @@ $(function() { } // load remote content - dialog.load( - url, - {}, - function(responseText, textStatus, XMLHttpRequest) { - dialog.dialog({ - modal : true, - width : width_value, - height : height_value, - resizable : resizable_value - }); + dialog.load(url,{}, function(responseText, textStatus, XMLHttpRequest) { + dialog.dialog({ + modal : true, + width : width_value, + height : height_value, + resizable : resizable_value + }); }); //prevent the browser to follow the link return false; @@ -274,7 +269,7 @@ $(function() { //old jquery.menu.js $('#navigation a').stop().animate({ 'marginLeft':'50px' - },1000); + }, 1000); $('#navigation > li').hover( function () { @@ -308,4 +303,6 @@ $(function() { });*/ }); +{% block extraHead %} +{% endblock %} {{ header_extra_content }} diff --git a/src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php b/src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php index 2651a0d941..797957769b 100644 --- a/src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php +++ b/src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php @@ -1,5 +1,6 @@ '', 'nodeDecorator' => function ($row) use ($app, $categoryId, $subtree) { $url = $app['url_generator']->generate('admin_questions_get_categories', array('id' => $row['iid'])); - $url = \Display::url($row['title'], $url, array('id' => $row['iid'])); + $title = $row['title']; + $url = \Display::url($title, $url, array('id' => $row['iid'])); if ($row['iid'] == $categoryId) { $url .= $subtree; } @@ -253,7 +255,6 @@ class QuestionManagerController $query = $qb->getQuery(); $tree = $repo->buildTree($query->getArrayResult(), $options); - $app['template']->assign('category_tree', $tree); // Getting globals @@ -272,4 +273,46 @@ class QuestionManagerController return new Response($response, 200, array()); } + + /** + * Edit category + * + * @param Application $app + * @param $id + * @return Response + */ + public function editCategoryAction(Application $app, $id) + { + $extraJS = array(); + //@todo improve this JS includes should be added using twig + $extraJS[] = ''; + $extraJS[] = ''; + $app['extraJS'] = $extraJS; + + $objcat = new \Testcategory($id); + + if (!empty($objcat->c_id)) { + $app->abort(401); + } + $url = $app['url_generator']->generate('admin_category_edit', array('id' => $id)); + $form = new \FormValidator('edit', 'post', $url); + + $objcat->editForm($form); + $message = null; + if ($form->validate()) { + $values = $form->getSubmitValues(); + $objcat = new \Testcategory($id, $values['category_name'], $values['category_description'], $values['parent_id'], 'global'); + if ($objcat->modifyCategory()) { + $message = \Display::return_message(get_lang('MofidfyCategoryDone'), 'confirmation'); + } else { + $message = \Display::return_message(get_lang('ModifyCategoryError'), 'warning'); + } + } + $app['template']->assign('message', $message); + $app['template']->assign('form', $form->toHtml()); + $response = $app['template']->render_template('admin/questionmanager/edit_category.tpl'); + + return new Response($response, 200, array()); + + } } diff --git a/src/ChamiloLMS/Controller/EditorController.php b/src/ChamiloLMS/Controller/EditorController.php index 8306ceb6a8..404af17b23 100644 --- a/src/ChamiloLMS/Controller/EditorController.php +++ b/src/ChamiloLMS/Controller/EditorController.php @@ -22,6 +22,7 @@ class EditorController public function filemanagerAction(Application $app) { $response = $app['template']->render_template('javascript/elfinder.tpl'); + return new Response($response, 200, array()); } @@ -44,5 +45,4 @@ class EditorController $connector = new \elFinderConnector(new \elFinder($opts)); $connector->run(); } - }