From 821af5358401e36ed069098f0ae22b834913b0ca Mon Sep 17 00:00:00 2001 From: Prasanna LMSACE Date: Sun, 28 Apr 2024 20:56:43 +0530 Subject: [PATCH] Improved backwards compatibility of Pulse placeholders --- lib.php | 8 +++++--- lib/vars.php | 40 +++++++++++++++++++++++++--------------- version.php | 2 +- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/lib.php b/lib.php index d47654f..3e5cb03 100644 --- a/lib.php +++ b/lib.php @@ -601,11 +601,13 @@ function mod_pulse_output_fragment_completionbuttons($args) { * @return void */ function pulse_email_placeholders($editor) { - global $OUTPUT; + global $OUTPUT, $PAGE; $vars = \pulse_email_vars::vars(); $i = 0; + $output = $PAGE->get_renderer('core'); + foreach ($vars as $key => $var) { $label = str_replace($key.'_', '', $var); // Help text added. @@ -613,7 +615,7 @@ function pulse_email_placeholders($editor) { $data = [ 'text' => get_string($key.'_vars_help', 'mod_pulse'), 'alt' => $alt, - 'icon' => (new \pix_icon('help', $alt, 'core', ['class' => 'iconhelp']))->export_for_template($OUTPUT), + 'icon' => (new \pix_icon('help', $alt, 'core', ['class' => 'iconhelp']))->export_for_template($output), 'ltr' => !right_to_left(), ]; $helptext = $OUTPUT->render_from_template('core/help_icon', $data); @@ -625,7 +627,7 @@ function pulse_email_placeholders($editor) { 'vars' => $label, 'showmore' => (count($label) > 6) ? true : false, 'active' => $i, - 'pretext' => ($key == "Mod_Metadata") ? '' : $key."_", + 'pretext' => ($key == "Mod_Metadata" || $key == 'others' || $key == 'Reaction') ? '' : $key."_", ]; $i++; } diff --git a/lib/vars.php b/lib/vars.php index 8a10533..78e2890 100644 --- a/lib/vars.php +++ b/lib/vars.php @@ -107,13 +107,6 @@ class pulse_email_vars { */ protected $orgcourse = null; - /** - * Reaction Data - * - * @var object - */ - public $reaction = null; - /** * Sets up and retrieves the API objects. * @@ -153,10 +146,6 @@ public function __construct($user, $course, $sender, $pulse) { $this->enrolment = $this->get_user_enrolment(); - if (pulsehelper::pulse_has_pro() && $this->pulse) { - $this->reaction = $this->reaction_data(); - } - } /** @@ -233,6 +222,8 @@ public static function vars() { $result += \mod_pulse\extendpro::pulse_extend_reaction_placholder(); + $result += ['others' => ['siteurl', 'courseurl', 'linkurl', 'completionstatus']]; + // Remove empty vars. $result = array_filter($result); @@ -304,14 +295,30 @@ public function linkurl() { } } + /** + * Provide the CourseURL method for templates. + * + * returns text; + * + **/ + public function courseurl() { + global $CFG; + + if (empty($CFG->allowthemechangeonurl)) { + return $this->course->url; + } else { + return new moodle_url($this->course->url); + } + } + /** * Reaction placeholders dynamic data. * Pro featuer extended from locla_pulsepro. * - * @return array + * @return void */ - public function reaction_data() { - return (object)['reaction' => \mod_pulse\extendpro::pulse_extend_reaction($this)]; + public function reaction() { + return \mod_pulse\extendpro::pulse_extend_reaction($this); } /** @@ -392,11 +399,14 @@ public static function user_profile_fields() { 'institution', ]; + $userdbfields = $DB->get_columns('user'); + $profilefields = array_map(function($value) { return str_replace('profile_field', 'profilefield', $value); }, (new auth_plugin_base)->get_custom_user_profile_fields()); - $fields = array_merge($userfields, array_values($profilefields)); + $fields = array_merge($userfields, array_keys($userdbfields), array_values($profilefields)); + $fields = array_unique($fields); array_walk($fields, function(&$value) { $value = 'User_'.ucwords($value); diff --git a/version.php b/version.php index 1da694f..d08f7f3 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'mod_pulse'; -$plugin->version = 2024033004; +$plugin->version = 2024033005; $plugin->requires = 2022112800; // Requires Moodle 4.1. $plugin->release = 'v2.1'; $plugin->maturity = MATURITY_STABLE;