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.
This commit is contained in:
@@ -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())) {
|
||||
|
||||
+17
-12
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user