Skip to content

Commit

Permalink
Implemented the pulse 2.1
Browse files Browse the repository at this point in the history
- PLS-610, PLS-676, PLS-675, PLS-682, PLS-681, PLS-620, PLS-673
  • Loading branch information
raja-lmsace committed Mar 30, 2024
1 parent bdb47d3 commit 58f1300
Show file tree
Hide file tree
Showing 60 changed files with 3,897 additions and 273 deletions.
2 changes: 1 addition & 1 deletion actions/notification/amd/build/chaptersource.min.js.map

Large diffs are not rendered by default.

80 changes: 76 additions & 4 deletions actions/notification/classes/actionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ public function load_global_form(&$mform, $forminstance) {
global $CFG, $PAGE;

require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->dirroot.'/mod/pulse/lib.php');

// Sender Group.
$senderoptions = array(
Expand Down Expand Up @@ -727,7 +728,8 @@ public function load_global_form(&$mform, $forminstance) {
$this->get_editor_options($context)
);
$mform->addHelpButton('pulsenotification_headercontent_editor', 'headercontent', 'pulseaction_notification');
$forminstance->pulse_email_placeholders($mform);
$placeholders = pulse_email_placeholders('header');
$mform->addElement('html', $placeholders);

// Statecontent editor.
$mform->addElement('editor', 'pulsenotification_staticcontent_editor',
Expand All @@ -736,21 +738,22 @@ public function load_global_form(&$mform, $forminstance) {
$this->get_editor_options($context)
);
$mform->addHelpButton('pulsenotification_staticcontent_editor', 'staticcontent', 'pulseaction_notification');
$forminstance->pulse_email_placeholders($mform);
$placeholders = pulse_email_placeholders('static');
$mform->addElement('html', $placeholders);

// Footer Content.
$mform->addElement('editor', 'pulsenotification_footercontent_editor',
get_string('footercontent', 'pulseaction_notification'),
['class' => 'fitem_id_templatevars_editor'], $this->get_editor_options($context));
$mform->addHelpButton('pulsenotification_footercontent_editor', 'footercontent', 'pulseaction_notification');
$forminstance->pulse_email_placeholders($mform);
$placeholders = pulse_email_placeholders('footer');
$mform->addElement('html', $placeholders);

// Preview Button.
$test = $mform->addElement('button', 'pulsenotification_preview', get_string('preview', 'pulseaction_notification'));
$mform->addHelpButton('pulsenotification_preview', 'preview', 'pulseaction_notification');

// Email tempalte placholders.
$PAGE->requires->js_call_amd('mod_pulse/module', 'init');
$contextid = $PAGE->context->id;
$PAGE->requires->js_call_amd('pulseaction_notification/chaptersource', 'previewNotification', ['contextid' => $contextid]);
}
Expand Down Expand Up @@ -779,4 +782,73 @@ public function get_times() {

return $timelist;
}

/**
* Get a email placeholders data fields.
*
* @return array
*/
public function get_email_placeholders() {

$result = [
'Assignment' => $this->assignment_data_fields(),
];

return $result;
}

/**
* Assignment extension data fields.
*
* @return array
*/
public function assignment_data_fields() {
return [ 'Assignment_Extensions'];
}

/**
* Get the assignment extenstion placeholders values.
*
* @param int $courseid Course ID.
* @param int $userid User ID.
* @return array
*/
public function get_assignment_extension($courseid, $userid) {
global $DB, $CFG;
require_once($CFG->libdir . '/completionlib.php');

// Get only assignments from the course of the instance shall be included.
$assignments = $DB->get_records('assign', ['course' => $courseid]);
$extension = '';

// Get a course completeion.
$completion = new \completion_info(get_course($courseid));

foreach ($assignments as $assignment) {
// Get the assignments only not completed by the user.
$cmid = $DB->get_record('course_modules', ['module' => 1, 'instance' => $assignment->id]);
$cm = get_coursemodule_from_id('assign', $cmid->id, 0, false, MUST_EXIST);
$cminfo = \cm_info::create($cm, $userid);
$assigncompletion = $completion->get_data($cminfo, true, $userid);

if ($assigncompletion->completionstate != COMPLETION_COMPLETE) {
// Get only assignments where the assignment submission deadline was extended.
if ($DB->record_exists('assign_user_flags', ['assignment' => $assignment->id, 'userid' => $userid])) {
$extensionassignments = $DB->get_records('assign_user_flags', ['assignment' => $assignment->id,
'userid' => $userid]);
foreach ($extensionassignments as $extensionassign) {
if ($extensionassign->extensionduedate != 0) {
$extensionduedate = userdate($extensionassign->extensionduedate) ?? '';
$extension .= html_writer::tag('h6', $assignment->name.": ". $extensionduedate .'('.
get_string('previously', 'pulse').': '.userdate($assignment->duedate).')');
}
}
}
}
}

return (object) [
'extensions' => (!empty($extension)) ? $extension : get_string('noextensiongranted', 'pulse'),
];
}
}
52 changes: 52 additions & 0 deletions actions/notification/classes/local/entities/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,58 @@ protected function get_all_columns(): array {

$notificationinsalias = $this->get_table_alias('pulseaction_notification_ins');

// Title of instance.
$columns[] = (new column(
'title',
new lang_string('institle', 'pulseaction_notification'),
$this->get_entity_name()
))
->set_is_sortable(true)
->add_field("{$templatesinsalias}.title", 'institle')
->add_callback(static function ($value, $row): string {
$val = $row->institle ?: '';
return format_string($val);
});

// Reference of instance.
$columns[] = (new column(
'insreference',
new lang_string('insreference', 'pulseaction_notification'),
$this->get_entity_name()
))
->set_is_sortable(true)
->add_field("{$templatesinsalias}.insreference")
->add_callback(static function ($value, $row): string {
$val = $row->insreference ?: '';
return format_string($val);
});

// Title of templates.
$columns[] = (new column(
'templatetitle',
new lang_string('templatetitle', 'pulseaction_notification'),
$this->get_entity_name()
))
->set_is_sortable(true)
->add_field("{$templatesalias}.title", 'templatetitle')
->add_callback(static function ($value, $row): string {
$val = $row->templatetitle ?: '';
return format_string($val);
});

// Reference of templates.
$columns[] = (new column(
'tempreference',
new lang_string('tempreference', 'pulseaction_notification'),
$this->get_entity_name()
))
->set_is_sortable(true)
->add_field("{$templatesalias}.reference", 'tempreference')
->add_callback(static function ($value, $row): string {
$val = $row->tempreference ?: '';
return format_string($val);
});

// Time the schedule is created.
$columns[] = (new column(
'timecreated',
Expand Down
27 changes: 24 additions & 3 deletions actions/notification/classes/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,17 @@ public function send_scheduled_notification($userid=null) {
$this->include_session_data($mod, $sessionconditiondata, $this->user->id);
}

// Include the conditions vars for placeholder replace.
$plugins = \mod_pulse\plugininfo\pulsecondition::instance()->get_plugins_base();
$conditionvars = [];
foreach ($plugins as $component => $pluginbase) {
$vars = $pluginbase->update_email_customvars($this->user->id, $this->instancedata, $this->schedulerecord);
$conditionvars += $vars ?: [];
}

// Update the email placeholders.
list($subject, $messagehtml) = pulsehelper::update_emailvars(
$detail->content, $detail->subject, $this->course, $this->user, $mod, $sender);
$detail->content, $detail->subject, $this->course, $this->user, $mod, $sender, array_filter($conditionvars));

// Plain message.
$messageplain = html_to_text($messagehtml);
Expand Down Expand Up @@ -262,8 +270,6 @@ protected function get_scheduled_records($userid=null) {

$select = array_merge($select, $columns);
}
// Final list of select columns, convert to sql mode.
$select = implode(', ', $select);

// Number of notification to send in this que.
$limit = get_config('pulse', 'schedulecount') ?: 100;
Expand All @@ -272,6 +278,20 @@ protected function get_scheduled_records($userid=null) {
$userwhere = $userid ? ' AND ns.userid =:userid ' : '';
$userparam = $userid ? ['userid' => $userid] : [];

$conditionleftjoins = '';
$plugins = \mod_pulse\plugininfo\pulsecondition::instance()->get_plugins_base();
foreach ($plugins as $component => $pluginbase) {
list($fields, $join) = $pluginbase->schedule_override_join();
if (empty($fields)) {
continue;
}
$conditionleftjoins .= $join;
$select[] = $fields;
}

// Final list of select columns, convert to sql mode.
$select = implode(', ', $select);

// Fetch the schedule which is status as 1 and nextrun not empty and not greater than now.
$sql = "SELECT $select FROM {pulseaction_notification_sch} ns
JOIN {pulse_autoinstances} ai ON ai.id = ns.instanceid
Expand All @@ -284,6 +304,7 @@ protected function get_scheduled_records($userid=null) {
JOIN {context} ctx ON ctx.instanceid = c.id AND ctx.contextlevel = 50
LEFT JOIN {pulse_condition_overrides} con ON con.instanceid = pati.instanceid AND con.triggercondition = 'session'
LEFT JOIN {course_modules} cm ON cm.id = ni.dynamiccontent
$conditionleftjoins
LEFT JOIN {modules} md ON md.id = cm.module
JOIN (
SELECT DISTINCT eu1_u.id, ej1_e.courseid, COUNT(ej1_ue.enrolid) AS activeenrolment
Expand Down
4 changes: 4 additions & 0 deletions actions/notification/lang/en/pulseaction_notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,7 @@
// ...Reports filter string.
$string['automationinstance'] = 'Automation instance';
$string['automationtemplate'] = 'Automation template';
$string['insreference'] = 'Instance reference';
$string['tempreference'] = 'Template reference';
$string['institle'] = 'Instance title';
$string['templatetitle'] = 'Template title';
8 changes: 8 additions & 0 deletions actions/notification/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ function pulseaction_notification_output_fragment_preview_instance_content($args
schedule::instance()->include_session_data($mod, $sessionconditiondata, $user->id);
}

// Include the conditions vars for placeholder replace.
/* $plugins = \mod_pulse\plugininfo\pulsecondition::instance()->get_plugins_base();
$conditionvars = [];
foreach ($plugins as $component => $pluginbase) {
$vars = $pluginbase->update_email_customvars($args['userid'], $formdata);
$conditionvars += $vars ?: [];
} */

list($subject, $messagehtml) = mod_pulse\helper::update_emailvars($content, '', $course, $user, $mod, $sender);
$selector = "";

Expand Down
10 changes: 10 additions & 0 deletions amd/build/bulkaction.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 58f1300

Please sign in to comment.