diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index c761ebad83b..edad7c9f020 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -825,7 +825,7 @@ class backup_badges_structure_step extends backup_structure_step { $criteria = new backup_nested_element('criteria'); $criterion = new backup_nested_element('criterion', array('id'), array('badgeid', - 'criteriatype', 'method')); + 'criteriatype', 'method', 'description', 'descriptionformat')); $parameters = new backup_nested_element('parameters'); $parameter = new backup_nested_element('parameter', array('id'), array('critid', diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index ca6610287bc..014cfb41339 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -2269,9 +2269,11 @@ class restore_badges_structure_step extends restore_structure_step { $data = (object)$data; $params = array( - 'badgeid' => $this->get_new_parentid('badge'), - 'criteriatype' => $data->criteriatype, - 'method' => $data->method + 'badgeid' => $this->get_new_parentid('badge'), + 'criteriatype' => $data->criteriatype, + 'method' => $data->method, + 'description' => $data->description, + 'descriptionformat' => $data->descriptionformat, ); $newid = $DB->insert_record('badge_criteria', $params); $this->set_mapping('criterion', $data->id, $newid); diff --git a/badges/criteria/award_criteria.php b/badges/criteria/award_criteria.php index a4127db67be..2d102dcce3a 100644 --- a/badges/criteria/award_criteria.php +++ b/badges/criteria/award_criteria.php @@ -112,6 +112,12 @@ abstract class award_criteria { */ public $description; + /** + * Format of the criterion description. + * @var integer + */ + public $descriptionformat; + /** * Any additional parameters. * @var array @@ -128,6 +134,7 @@ abstract class award_criteria { $this->method = isset($params['method']) ? $params['method'] : BADGE_CRITERIA_AGGREGATION_ANY; $this->badgeid = $params['badgeid']; $this->description = isset($params['description']) ? $params['description'] : ''; + $this->descriptionformat = isset($params['descriptionformat']) ? $params['descriptionformat'] : FORMAT_HTML; if (isset($params['id'])) { $this->params = $this->get_params($params['id']); } @@ -249,7 +256,7 @@ abstract class award_criteria { if (!empty($this->description)) { $badge = new badge($this->badgeid); echo $OUTPUT->box( - format_text($this->description, FORMAT_HTML, array('context' => $badge->get_context())), + format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())), 'criteria-description' ); } @@ -348,8 +355,10 @@ abstract class award_criteria { // Figure out criteria description. // If it is coming from the form editor, it is an array(text, format). $description = ''; + $descriptionformat = FORMAT_HTML; if (isset($params['description']['text'])) { $description = $params['description']['text']; + $descriptionformat = $params['description']['format']; } else if (isset($params['description'])) { $description = $params['description']; } @@ -359,6 +368,7 @@ abstract class award_criteria { $fordb->method = isset($params['agg']) ? $params['agg'] : BADGE_CRITERIA_AGGREGATION_ALL; $fordb->badgeid = $this->badgeid; $fordb->description = $description; + $fordb->descriptionformat = $descriptionformat; $t = $DB->start_delegated_transaction(); // Pick only params that are required by this criterion. @@ -434,6 +444,7 @@ abstract class award_criteria { $fordb->method = $this->method; $fordb->badgeid = $newbadgeid; $fordb->description = $this->description; + $fordb->descriptionformat = $this->descriptionformat; if (($newcrit = $DB->insert_record('badge_criteria', $fordb, true)) && isset($this->params)) { foreach ($this->params as $k => $param) { foreach ($param as $key => $value) { diff --git a/badges/criteria/award_criteria_course.php b/badges/criteria/award_criteria_course.php index 89897ea01c4..25823656823 100644 --- a/badges/criteria/award_criteria_course.php +++ b/badges/criteria/award_criteria_course.php @@ -77,9 +77,11 @@ class award_criteria_course extends award_criteria { if (!empty($this->description)) { echo $OUTPUT->box( - format_text($this->description, FORMAT_HTML, array('context' => context_course::instance($this->courseid))), + format_text($this->description, $this->descriptionformat, + array('context' => context_course::instance($this->courseid)) + ), 'criteria-description' - ); + ); } if (!empty($this->params)) { diff --git a/badges/criteria/award_criteria_overall.php b/badges/criteria/award_criteria_overall.php index 6e4909848e3..7d6aad80e77 100644 --- a/badges/criteria/award_criteria_overall.php +++ b/badges/criteria/award_criteria_overall.php @@ -48,7 +48,7 @@ class award_criteria_overall extends award_criteria { if (!empty($this->description)) { $badge = new badge($this->badgeid); echo $OUTPUT->box( - format_text($this->description, FORMAT_HTML, array('context' => $badge->get_context())), + format_text($this->description, $this->descriptionformat, array('context' => $badge->get_context())), 'criteria-description'); } echo $OUTPUT->heading($this->get_title(), 2); @@ -184,8 +184,10 @@ class award_criteria_overall extends award_criteria { // Sort out criteria description. // If it is coming from the form editor, it is an array of (text, format). $description = ''; + $descriptionformat = FORMAT_HTML; if (isset($params['description']['text'])) { $description = $params['description']['text']; + $descriptionformat = $params['description']['format']; } else if (isset($params['description'])) { $description = $params['description']; } @@ -194,6 +196,7 @@ class award_criteria_overall extends award_criteria { $fordb->criteriatype = $this->criteriatype; $fordb->badgeid = $this->badgeid; $fordb->description = $description; + $fordb->descriptionformat = $descriptionformat; if ($this->id !== 0) { $fordb->id = $this->id; $DB->update_record('badge_criteria', $fordb); diff --git a/badges/criteria_form.php b/badges/criteria_form.php index 3bd659f9f5b..c8d18d14729 100644 --- a/badges/criteria_form.php +++ b/badges/criteria_form.php @@ -58,7 +58,11 @@ class edit_criteria_form extends moodleform { $mform->addElement('header', 'description_header', get_string('description')); $mform->addElement('editor', 'description', '', null, null); $mform->setType('description', PARAM_RAW); - $mform->setDefault('description', array('text' => $criteria->description)); + $mform->setDefault('description', array( + 'text' => $criteria->description, + 'format' => $criteria->descriptionformat + ) + ); $mform->closeHeaderBefore('buttonar'); $this->add_action_buttons(true, get_string('save', 'badges')); diff --git a/badges/renderer.php b/badges/renderer.php index 990d3a89823..d4fad08aec0 100644 --- a/badges/renderer.php +++ b/badges/renderer.php @@ -721,7 +721,7 @@ class core_badges_renderer extends plugin_renderer_base { $overall = $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]; if (!$short && !empty($overall->description)) { $overalldescr = $this->output->box( - format_text($overall->description, FORMAT_HTML, array('context' => $badge->get_context())), + format_text($overall->description, $overall->descriptionformat, array('context' => $badge->get_context())), 'criteria-description' ); } @@ -745,7 +745,7 @@ class core_badges_renderer extends plugin_renderer_base { $c = reset($badge->criteria); if (!$short && !empty($c->description)) { $overalldescr = $this->output->box( - format_text($c->description, FORMAT_HTML, array('context' => $badge->get_context())), + format_text($c->description, $c->descriptionformat, array('context' => $badge->get_context())), 'criteria-description' ); } @@ -762,7 +762,7 @@ class core_badges_renderer extends plugin_renderer_base { $criteriadescr = ''; if (!$short && !empty($c->description)) { $criteriadescr = $this->output->box( - format_text($c->description, FORMAT_HTML, array('context' => $badge->get_context())), + format_text($c->description, $c->descriptionformat, array('context' => $badge->get_context())), 'criteria-description' ); } diff --git a/badges/tests/badgeslib_test.php b/badges/tests/badgeslib_test.php index 4483d14056d..b6284316023 100644 --- a/badges/tests/badgeslib_test.php +++ b/badges/tests/badgeslib_test.php @@ -154,10 +154,19 @@ class core_badges_badgeslib_testcase extends advanced_testcase { public function test_add_badge_criteria_description() { $criteriaoverall = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_OVERALL, 'badgeid' => $this->badgeid)); - $criteriaoverall->save(array('agg' => BADGE_CRITERIA_AGGREGATION_ALL, 'description' => 'Overall description')); + $criteriaoverall->save(array( + 'agg' => BADGE_CRITERIA_AGGREGATION_ALL, + 'description' => 'Overall description', + 'descriptionformat' => FORMAT_HTML + )); $criteriaprofile = award_criteria::build(array('criteriatype' => BADGE_CRITERIA_TYPE_PROFILE, 'badgeid' => $this->badgeid)); - $params = array('agg' => BADGE_CRITERIA_AGGREGATION_ALL, 'field_address' => 'address', 'description' => 'Description'); + $params = array( + 'agg' => BADGE_CRITERIA_AGGREGATION_ALL, + 'field_address' => 'address', + 'description' => 'Description', + 'descriptionformat' => FORMAT_HTML + ); $criteriaprofile->save($params); $badge = new badge($this->badgeid); diff --git a/lib/db/install.xml b/lib/db/install.xml index 852bead663e..da0ef3b119a 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -2864,6 +2864,7 @@ + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 0c785bd72c4..f4df15b2b39 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -4249,13 +4249,19 @@ function xmldb_main_upgrade($oldversion) { if ($oldversion < 2015032000.00) { $table = new xmldb_table('badge_criteria'); - $field = new xmldb_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null); + $field = new xmldb_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null); // Conditionally add description field to the badge_criteria table. if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } + $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, 2, null, XMLDB_NOTNULL, null, 0); + // Conditionally add description format field to the badge_criteria table. + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + upgrade_main_savepoint(true, 2015032000.00); }