Skip to content

Commit

Permalink
Improved backwards compatibility of Pulse placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Apr 28, 2024
1 parent be5d76b commit 821af53
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
8 changes: 5 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,19 +601,21 @@ 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.
$alt = get_string('description');
$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);
Expand All @@ -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++;
}
Expand Down
40 changes: 25 additions & 15 deletions lib/vars.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
}

}

/**
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 821af53

Please sign in to comment.