Adding edit link for question admins

skala
Julio Montoya 13 years ago
parent 3ad4245489
commit ac1fbbf10e
  1. 51
      main/exercice/testcategory.class.php
  2. 32
      main/exercice/tests_category.php
  3. 30
      main/inc/Entity/CQuizCategory.php
  4. 5
      main/inc/routes.php
  5. 47
      main/template/default/admin/questionmanager/edit_category.tpl
  6. 9
      main/template/default/admin/questionmanager/questions.tpl
  7. 23
      main/template/default/layout/head.tpl
  8. 47
      src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php
  9. 2
      src/ChamiloLMS/Controller/EditorController.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 .= '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</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');
}
}

@ -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 '<script>$(function() { $("#parent_id").trigger("addItem",[{"title": "'.$parent_cat->name.'", "value": "'.$parent_cat->id.'"}]); });</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"] = $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;
}
}

@ -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;
}
}

@ -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', '.+')

@ -0,0 +1,47 @@
{% extends app.template_style ~ "/layout/layout_1_col.tpl" %}
{% block content %}
<script>
function check() {
$("#parent_id option:selected").each(function() {
var id = $(this).val();
var name = $(this).text();
if (id != "" ) {
$.ajax({
async: false,
url: "{{ _p.web_ajax }}exercise.ajax.php?type=global&a=exercise_category_exists",
data: "id="+id,
success: function(return_value) {
if (return_value == 0 ) {
alert("{{ 'CategoryDoesNotExists' | get_lang }}");
//Deleting select option tag
$("#parent_id").find("option").remove();
$(".holder li").each(function () {
if ($(this).attr("rel") == id) {
$(this).remove();
}
});
}
}
});
}
});
}
$(function() {
$("#parent_id").fcbkcomplete({
json_url: "{{ _p.web_ajax }}exercise.ajax.php?type=global&a=search_category_parent",
maxitems: 1,
addontab: false,
input_min_size: 1,
cache: false,
complete_text:"{{ 'StartToType' | get_lang }}",
firstselected: false,
onselect: check,
filter_selected: true,
newel: true
});
});
</script>
{{ form }}
{% endblock %}

@ -121,8 +121,15 @@
<div class="questions">
{% if category %}
<h3>{{ category.title }}</h3>
<h3>{{ category.title }}
{% if category.cId == 0 %}
<a href="{{ app.url_generator.generate('admin_category_edit', {id : category.iid}) }}">
<img src="{{ "edit.png"|icon(22) }}">
</a>
{% endif %}
</h3>
{% endif %}
<div class="clear"></div>
{{ grid }}
</div>

@ -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() {
});*/
});
</script>
{% block extraHead %}
{% endblock %}
{{ header_extra_content }}

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
namespace ChamiloLMS\Controller\Admin\QuestionManager;
use Silex\Application;
@ -229,7 +230,8 @@ class QuestionManagerController
'childClose' => '</li>',
'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[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$extraJS[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript"></script>';
$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());
}
}

@ -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();
}
}

Loading…
Cancel
Save