From 3b2a45d755ebfc59ccec7a470e492929f0d9f6bc Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 6 Jun 2018 20:38:08 +0800 Subject: [PATCH] #170 Elements now respect filters --- element/categoryname/classes/element.php | 8 +++++--- element/coursename/classes/element.php | 6 ++++-- element/gradeitemname/classes/element.php | 4 ++++ element/text/classes/element.php | 8 ++++++-- element/userfield/classes/element.php | 4 ++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/element/categoryname/classes/element.php b/element/categoryname/classes/element.php index adf7d70..054a70b 100644 --- a/element/categoryname/classes/element.php +++ b/element/categoryname/classes/element.php @@ -57,7 +57,8 @@ class element extends \mod_customcert\element { public function render_html() { global $COURSE; - return \mod_customcert\element_helper::render_html_content($this, $COURSE->fullname); + $categoryname = format_string($COURSE->fullname, true, ['context' => \context_course::instance($COURSE->id)]); + return \mod_customcert\element_helper::render_html_content($this, $categoryname); } /** @@ -74,9 +75,10 @@ class element extends \mod_customcert\element { // Check that there is a course category available. if (!empty($course->category)) { - return $DB->get_field('course_categories', 'name', array('id' => $course->category), MUST_EXIST); + $categoryname = $DB->get_field('course_categories', 'name', array('id' => $course->category), MUST_EXIST); + return format_string($categoryname, true, ['context' => \context_course::instance($courseid)]); } else { // Must be in a site template. - return $SITE->fullname; + return format_string($SITE->fullname, true, ['context' => \context_system::instance()]); } } } diff --git a/element/coursename/classes/element.php b/element/coursename/classes/element.php index a4d1058..5b0f78d 100644 --- a/element/coursename/classes/element.php +++ b/element/coursename/classes/element.php @@ -46,7 +46,8 @@ class element extends \mod_customcert\element { $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); $course = get_course($courseid); - \mod_customcert\element_helper::render_content($pdf, $this, $course->fullname); + $coursename = format_string($course->fullname, true, ['context' => \context_course::instance($courseid)]); + \mod_customcert\element_helper::render_content($pdf, $this, $coursename); } /** @@ -60,6 +61,7 @@ class element extends \mod_customcert\element { public function render_html() { global $COURSE; - return \mod_customcert\element_helper::render_html_content($this, $COURSE->fullname); + $coursename = format_string($COURSE->fullname, true, ['context' => \context_course::instance($COURSE->id)]); + return \mod_customcert\element_helper::render_html_content($this, $coursename); } } diff --git a/element/gradeitemname/classes/element.php b/element/gradeitemname/classes/element.php index 82c7435..afa792c 100644 --- a/element/gradeitemname/classes/element.php +++ b/element/gradeitemname/classes/element.php @@ -82,7 +82,9 @@ class element extends \mod_customcert\element { $module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST); // Get the name of the item. + $courseid = \mod_customcert\element_helper::get_courseid($this->get_data()); $itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST); + $itemname = format_string($itemname, true, ['context' => \context_course::instance($courseid)]); \mod_customcert\element_helper::render_content($pdf, $this, $itemname); } @@ -106,7 +108,9 @@ class element extends \mod_customcert\element { $module = $DB->get_record('modules', array('id' => $cm->module), '*', MUST_EXIST); // Get the name of the item. + $courseid = \mod_customcert\element_helper::get_courseid($this->get_data()); $itemname = $DB->get_field($module->name, 'name', array('id' => $cm->instance), MUST_EXIST); + $itemname = format_string($itemname, true, ['context' => \context_course::instance($courseid)]); return \mod_customcert\element_helper::render_html_content($this, $itemname); } diff --git a/element/text/classes/element.php b/element/text/classes/element.php index 9ae500f..bb5e0b9 100644 --- a/element/text/classes/element.php +++ b/element/text/classes/element.php @@ -67,7 +67,9 @@ class element extends \mod_customcert\element { * @param \stdClass $user the user we are rendering this for */ public function render($pdf, $preview, $user) { - \mod_customcert\element_helper::render_content($pdf, $this, $this->get_data()); + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); + $text = format_text($this->get_data(), FORMAT_MOODLE, ['context' => \context_course::instance($courseid)]); + \mod_customcert\element_helper::render_content($pdf, $this, $text); } /** @@ -79,7 +81,9 @@ class element extends \mod_customcert\element { * @return string the html */ public function render_html() { - return \mod_customcert\element_helper::render_html_content($this, $this->get_data()); + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); + $text = format_text($this->get_data(), FORMAT_MOODLE, ['context' => \context_course::instance($courseid)]); + return \mod_customcert\element_helper::render_html_content($this, $text); } /** diff --git a/element/userfield/classes/element.php b/element/userfield/classes/element.php index 1b87086..ad9ceff 100644 --- a/element/userfield/classes/element.php +++ b/element/userfield/classes/element.php @@ -119,6 +119,8 @@ class element extends \mod_customcert\element { $value = $user->$field; } + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); + $value = format_string($value, true, ['context' => \context_course::instance($courseid)]); \mod_customcert\element_helper::render_content($pdf, $this, $value); } @@ -155,6 +157,8 @@ class element extends \mod_customcert\element { $value = $USER->$field; } + $courseid = \mod_customcert\element_helper::get_courseid($this->get_id()); + $value = format_string($value, true, ['context' => \context_course::instance($courseid)]); return \mod_customcert\element_helper::render_html_content($this, $value); }