From fa5c608c6203fb48d29ca06a0184470fad85c97c Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 5 Aug 2013 18:36:56 +0100 Subject: [PATCH] MDL-41036 Question category info should use HTML editor This is a minimal fix. All this code could do with a clean-up, but at the moment, it works, so I am not going to touch it. --- question/category.php | 8 ++++++-- question/category_class.php | 29 +++++++++++++++++------------ question/category_form.php | 19 ++++++++++++++++--- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/question/category.php b/question/category.php index ed6a085607d..0d6288710e8 100644 --- a/question/category.php +++ b/question/category.php @@ -104,10 +104,14 @@ if ($param->delete && ($questionstomove = $DB->count_records("question", array(" if ($qcobject->catform->is_cancelled()) { redirect($thispageurl); } else if ($catformdata = $qcobject->catform->get_data()) { + $catformdata->infoformat = $catformdata->info['format']; + $catformdata->info = $catformdata->info['text']; if (!$catformdata->id) {//new category - $qcobject->add_category($catformdata->parent, $catformdata->name, $catformdata->info); + $qcobject->add_category($catformdata->parent, $catformdata->name, + $catformdata->info, false, $catformdata->infoformat); } else { - $qcobject->update_category($catformdata->id, $catformdata->parent, $catformdata->name, $catformdata->info); + $qcobject->update_category($catformdata->id, $catformdata->parent, + $catformdata->name, $catformdata->info, $catformdata->infoformat); } redirect($thispageurl); } else if ((!empty($param->delete) and (!$questionstomove) and confirm_sesskey())) { diff --git a/question/category_class.php b/question/category_class.php index f6ef2bc7a41..39740fde6e7 100644 --- a/question/category_class.php +++ b/question/category_class.php @@ -134,25 +134,28 @@ class question_category_list_item extends list_item { */ class question_category_object { - var $str; /** - * Nested lists to display categories. - * - * @var array + * @var array common language strings. */ - var $editlists = array(); - var $newtable; - var $tab; - var $tabsize = 3; + public $str; + + /** + * @var array nested lists to display categories. + */ + public $editlists = array(); + public $newtable; + public $tab; + public $tabsize = 3; /** * @var moodle_url Object representing url for this page */ - var $pageurl; + public $pageurl; + /** * @var question_category_edit_form Object representing form for adding / editing categories. */ - var $catform; + public $catform; /** * Constructor @@ -377,7 +380,7 @@ class question_category_object { /** * Creates a new category with given params */ - public function add_category($newparent, $newcategory, $newinfo, $return = false) { + public function add_category($newparent, $newcategory, $newinfo, $return = false, $newinfoformat = FORMAT_HTML) { global $DB; if (empty($newcategory)) { print_error('categorynamecantbeblank', 'question'); @@ -397,6 +400,7 @@ class question_category_object { $cat->contextid = $contextid; $cat->name = $newcategory; $cat->info = $newinfo; + $cat->infoformat = $newinfoformat; $cat->sortorder = 999; $cat->stamp = make_unique_id_code(); $categoryid = $DB->insert_record("question_categories", $cat); @@ -410,7 +414,7 @@ class question_category_object { /** * Updates an existing category with given params */ - public function update_category($updateid, $newparent, $newname, $newinfo) { + public function update_category($updateid, $newparent, $newname, $newinfo, $newinfoformat = FORMAT_HTML) { global $CFG, $DB; if (empty($newname)) { print_error('categorynamecantbeblank', 'question'); @@ -442,6 +446,7 @@ class question_category_object { $cat->id = $updateid; $cat->name = $newname; $cat->info = $newinfo; + $cat->infoformat = $newinfoformat; $cat->parent = $parentid; $cat->contextid = $tocontextid; $DB->update_record('question_categories', $cat); diff --git a/question/category_form.php b/question/category_form.php index 600ee888625..93011aac2be 100644 --- a/question/category_form.php +++ b/question/category_form.php @@ -59,14 +59,27 @@ class question_category_edit_form extends moodleform { $mform->addRule('name', get_string('categorynamecantbeblank', 'question'), 'required', null, 'client'); $mform->setType('name', PARAM_TEXT); - $mform->addElement('textarea', 'info', get_string('categoryinfo', 'question'), array('rows'=> '10', 'cols'=>'45')); + $mform->addElement('editor', 'info', get_string('categoryinfo', 'question'), + array('rows' => 10), array('noclean' => 1)); $mform->setDefault('info', ''); - $mform->setType('info', PARAM_TEXT); + $mform->setType('info', PARAM_RAW); $this->add_action_buttons(false, get_string('addcategory', 'question')); $mform->addElement('hidden', 'id', 0); $mform->setType('id', PARAM_INT); } -} + public function set_data($current) { + if (is_object($current)) { + $current = (array) $current; + } + if (!empty($current['info'])) { + $current['info'] = array('text' => $current['info'], + 'infoformat' => $current['infoformat']); + } else { + $current['info'] = array('text' => '', 'infoformat' => FORMAT_HTML); + } + parent::set_data($current); + } +} -- 2.43.0