Skip to content

Commit

Permalink
Implemented the instance create for disabled templated
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Sep 27, 2023
1 parent 2e931ad commit c9fbcd4
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 48 deletions.
2 changes: 1 addition & 1 deletion actions/notification/amd/build/chaptersource.min.js

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

2 changes: 1 addition & 1 deletion actions/notification/amd/build/chaptersource.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion actions/notification/amd/src/chaptersource.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/
const previewModalBody = function(contextID, userid = null) {

var params;
if (window.tinyMCE !== undefined) {
if (window.tinyMCE !== undefined && window.tinyMCE.get('id_pulsenotification_headercontent_editor')) {
// EditorPlugin = window.tinyMCE;
params = {
contentheader: window.tinyMCE.get('id_pulsenotification_headercontent_editor').getContent(),
Expand Down
19 changes: 18 additions & 1 deletion actions/notification/classes/actionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ public function delete_instance_action(int $instanceid) {
return $DB->delete_records($instancetable, ['instanceid' => $instanceid]);
}

/**
* Instances disabled, then disable all the schedules of the instances.
*
* @param stdclass $instancedata
* @param bool $status
* @return void
*/
public function instance_status_updated($instancedata, $status) {
global $DB;

$notificationid = $instancedata->actions['notification']['id'];
$notification = notification::instance($notificationid);
$notification->set_notification_data($instancedata->actions['notification'], $instancedata);

$notification->create_schedule_forinstance();
}

/**
* Prepare editor fileareas.
*
Expand Down Expand Up @@ -154,7 +171,7 @@ public function postupdate_editor_fileareas(&$data, \context $context) {
* Get text editor options to manage files.
*
* @param \stdclass $context
* @return void
* @return array
*/
protected function get_editor_options($context=null) {
global $PAGE;
Expand Down
10 changes: 5 additions & 5 deletions actions/notification/classes/local/entities/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,13 @@ public function schedulejoin() {
$notificationalias = $this->get_table_alias('pulseaction_notification');

return "
JOIN {pulse_autoinstances} AS {$autoinstancesalias} ON {$autoinstancesalias}.id = {$notificationschalias}.instanceid
JOIN {pulse_autotemplates} AS {$autotemplatesalias} ON {$autotemplatesalias}.id = {$autoinstancesalias}.templateid
JOIN {pulse_autotemplates_ins} AS {$autotemplatesinsalias}
JOIN {pulse_autoinstances} {$autoinstancesalias} ON {$autoinstancesalias}.id = {$notificationschalias}.instanceid
JOIN {pulse_autotemplates} {$autotemplatesalias} ON {$autotemplatesalias}.id = {$autoinstancesalias}.templateid
JOIN {pulse_autotemplates_ins} {$autotemplatesinsalias}
ON {$autotemplatesinsalias}.instanceid = {$autoinstancesalias}.id
JOIN {pulseaction_notification_ins} AS {$notificationinsalias}
JOIN {pulseaction_notification_ins} {$notificationinsalias}
ON {$notificationinsalias}.instanceid = {$notificationschalias}.instanceid
JOIN {pulseaction_notification} AS {$notificationalias}
JOIN {pulseaction_notification} {$notificationalias}
ON {$notificationalias}.templateid = {$autoinstancesalias}.templateid";
}
}
24 changes: 24 additions & 0 deletions actions/notification/classes/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,24 @@ protected function remove_schedules($status=self::STATUS_SENT) {
$DB->delete_records('pulseaction_notification_sch', ['instanceid' => $this->instancedata->id, 'status' => $status]);
}

/**
* Disable the queued schdule for all users.
*
* @return void
*/
protected function disable_schedules() {
global $DB;

$params = [
'instanceid' => $this->notificationdata->instanceid,
'status' => self::STATUS_QUEUED
];

// Disable the queued schedules for this instance.
$DB->set_field('pulseaction_notification_sch', 'status', self::STATUS_DISABLED, $params);

}

/**
* Removes the current queued schedules and recreate the schedule for all the qualified users.
*
Expand All @@ -487,6 +505,12 @@ public function create_schedule_forinstance($newenrolment=false) {
$this->create_instance_data();
}

// Confirm the instance is not disabled.
if (!$this->instancedata->status) {
$this->disable_schedules();
return false;
}

// Course context.
$context = \context_course::instance($this->instancedata->courseid);
// Roles to receive the notifications.
Expand Down
24 changes: 12 additions & 12 deletions actions/notification/classes/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,17 @@ protected function get_scheduled_records($userid=null) {

// 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} AS ai ON ai.id = ns.instanceid
JOIN {pulse_autotemplates} AS pat ON pat.id = ai.templateid
JOIN {pulse_autotemplates_ins} AS pati ON pati.instanceid = ai.id
JOIN {pulseaction_notification_ins} AS ni ON ni.instanceid = ns.instanceid
JOIN {pulseaction_notification} AS an ON an.templateid = ai.templateid
JOIN {user} AS ue ON ue.id = ns.userid
JOIN {course} as c ON c.id = ai.courseid
JOIN {context} AS ctx ON ctx.instanceid = c.id AND ctx.contextlevel = 50
LEFT JOIN {pulse_condition_overrides} AS con ON con.instanceid = pati.instanceid AND con.triggercondition = 'session'
LEFT JOIN {course_modules} AS cm ON cm.id = ni.dynamiccontent
LEFT JOIN {modules} AS md ON md.id = cm.module
JOIN {pulse_autoinstances} ai ON ai.id = ns.instanceid
JOIN {pulse_autotemplates} pat ON pat.id = ai.templateid
JOIN {pulse_autotemplates_ins} pati ON pati.instanceid = ai.id
JOIN {pulseaction_notification_ins} ni ON ni.instanceid = ns.instanceid
JOIN {pulseaction_notification} an ON an.templateid = ai.templateid
JOIN {user} ue ON ue.id = ns.userid
JOIN {course} c ON c.id = ai.courseid
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
LEFT JOIN {modules} md ON md.id = cm.module
JOIN (
SELECT DISTINCT eu1_u.id, ej1_e.courseid, COUNT(ej1_ue.enrolid) AS activeenrolment
FROM {user} eu1_u
Expand All @@ -308,7 +308,7 @@ protected function get_scheduled_records($userid=null) {
AND (ej1_ue.timestart = 0 OR ej1_ue.timestart <= :timestart)
AND (ej1_ue.timeend = 0 OR ej1_ue.timeend > :timeend)
GROUP BY eu1_u.id, ej1_e.courseid
) AS active_enrols ON active_enrols.id = ue.id AND active_enrols.courseid = c.id
) active_enrols ON active_enrols.id = ue.id AND active_enrols.courseid = c.id
WHERE ns.status = :status
AND active_enrols.activeenrolment <> 0
AND c.visible = 1
Expand Down
4 changes: 2 additions & 2 deletions actions/notification/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ function pulseaction_notification_output_fragment_preview_content($args) {
$modules = notification::get_modules_data($dynamicmodules);
$mod = current($modules[$modname]);
}

// Check the session condition are set for this notification. if its added then load the session data for placeholders.
$sessionincondition = in_array('session', (array) array_keys($formdata['condition']));
if ($sessionincondition && $formdata['condition']['session']['status']) {
if (isset($formdata['condition']['session']['status']) && $formdata['condition']['session']['status']) {
$sessionconditiondata = (object) ['modules' => $formdata['condition']['session']['modules']];
schedule::instance()->include_session_data($mod, $sessionconditiondata, $user->id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,54 @@ public function i_create_pulsenotification_instance_with_general($title, $refere
}

/**
* Fills a automation template condition form with field/value data.
* Create a new an automation instance and fills the form with field/value data.
*
* @Given /^I initiate new automation instance of template "([^"]*)" to these values:$/
* @param String $title
* @param TableNode $generaldata
*/
public function i_set_pulsenotification_instance_with_general($title, TableNode $generaldata) {

$this->execute('behat_forms::i_set_the_field_to', ["templateid", $title]);
$this->execute("behat_general::i_click_on", ["Add automation instance", "button"]);
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$generaldata]);
}

/**
* Fills the previously initiated instance notification actions form with these values.
*
* @Given /^I set previous automation instance notification to these values:$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param TableNode $notificationdata
*/
public function i_set_previous_instance_notification($notificationdata) {
$this->execute("behat_general::i_click_on_in_the", ["Notification", "link", "#automation-tabs", "css_element"]);
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$notificationdata]);
}

/**
* Create a new automation template, Fills a automation template form with field/value data.
*
* @Given /^I initiate new automation template to these values:$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param TableNode $generaldata
*/
public function i_set_pulsenotification_template_with_general($generaldata) {
$this->execute('behat_pulse::i_navigate_to_automation_template');
$this->execute('behat_pulse::i_navigate_to_automation_templates');
$this->execute("behat_general::i_click_on", ["Create new template", "button"]);
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$generaldata]);
}

/**
* Fills a automation template condition form with field/value data.
* Fills the previously initiated templates notification actions form with these values.
*
* @Given /^I set previous automation template notification to these values:$/
* @throws ElementNotFoundException Thrown by behat_base::find
* @param TableNode $notificationdata
*/
public function i_set_previous_template_notification($notificationdata) {

$this->execute("behat_general::i_click_on_in_the", ["Notification", "link", "#automation-tabs .nav-item", "css_element"]);
$this->execute("behat_general::i_click_on_in_the", ["Notification", "link", "#automation-tabs", "css_element"]);
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$notificationdata]);

}
Expand Down
Loading

0 comments on commit c9fbcd4

Please sign in to comment.