Skip to content

Commit

Permalink
Include separate method for session delay in schedules.
Browse files Browse the repository at this point in the history
- Fix PLS-726
  • Loading branch information
prasanna-lmsace committed Mar 9, 2024
1 parent ad9030d commit 81923bb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
39 changes: 27 additions & 12 deletions actions/notification/classes/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ protected function insert_schedule($data, $newschedule=false) {

if ($record = $DB->get_record_sql($sql, [
'instanceid' => $data['instanceid'], 'userid' => $data['userid'], 'disabledstatus' => self::STATUS_DISABLED,
'queued' => self::STATUS_QUEUED
'queued' => self::STATUS_QUEUED,
])) {

$data['id'] = $record->id;
Expand All @@ -331,7 +331,7 @@ protected function insert_schedule($data, $newschedule=false) {
// Dont create new schedule for already notified users until is not new schedule.
// It prevents creating new record for user during the update of instance interval.
if (!$newschedule && $DB->record_exists('pulseaction_notification_sch', [
'instanceid' => $data['instanceid'], 'userid' => $data['userid'], 'status' => self::STATUS_SENT
'instanceid' => $data['instanceid'], 'userid' => $data['userid'], 'status' => self::STATUS_SENT,
])) {
return false;
}
Expand All @@ -353,7 +353,7 @@ protected function disable_user_schedule($userid) {

$params = [
'instanceid' => $this->notificationdata->instanceid, 'userid' => $userid, 'disabledstatus' => self::STATUS_DISABLED,
'queued' => self::STATUS_QUEUED
'queued' => self::STATUS_QUEUED,
];

if ($record = $DB->get_record_sql($sql, $params)) {
Expand All @@ -375,7 +375,7 @@ public function remove_user_schedules($userid) {

$params = [
'instanceid' => $this->notificationdata->instanceid, 'userid' => $userid, 'disabledstatus' => self::STATUS_DISABLED,
'queued' => self::STATUS_QUEUED
'queued' => self::STATUS_QUEUED,
];

if ($record = $DB->get_record_sql($sql, $params)) {
Expand All @@ -393,7 +393,7 @@ protected function get_schedule($data) {
global $DB;

if ($record = $DB->get_record('pulseaction_notification_sch', [
'instanceid' => $data->instanceid, 'userid' => $data->userid
'instanceid' => $data->instanceid, 'userid' => $data->userid,
])) {
return $record;
}
Expand All @@ -413,7 +413,7 @@ protected function find_last_notifiedtime($userid) {
$id = $this->notificationdata->instanceid;

// Get last notified schedule for this instance to the user.
$condition = array('instanceid' => $id, 'userid' => $userid, 'status' => self::STATUS_SENT);
$condition = ['instanceid' => $id, 'userid' => $userid, 'status' => self::STATUS_SENT];
$records = $DB->get_records('pulseaction_notification_sch', $condition, 'id DESC', '*', 0, 1);

return !empty($records) ? current($records)->notifiedtime : '';
Expand All @@ -431,7 +431,7 @@ protected function find_notify_count($userid) {
$id = $this->notificationdata->instanceid;

// Get last notified schedule for this instance to the user.
$condition = array('instanceid' => $id, 'userid' => $userid, 'status' => self::STATUS_SENT);
$condition = ['instanceid' => $id, 'userid' => $userid, 'status' => self::STATUS_SENT];
$records = $DB->get_records('pulseaction_notification_sch', $condition, 'id DESC', '*', 0, 1);

return !empty($records) ? current($records)->notifycount : '';
Expand Down Expand Up @@ -478,7 +478,7 @@ protected function disable_schedules() {

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

// Disable the queued schedules for this instance.
Expand Down Expand Up @@ -687,13 +687,28 @@ protected function generate_the_scheduletime($userid, $lastrun=null, $expectedru

// Add limit of available.
if ($data->notifydelay == self::DELAYAFTER) {

// QuickFIX - PLS-726.
// When the instances are created/updated, creates the schedules directly.
// With is method expected run time are not included.
// Other conditions are not contains any specific usecases.
// Verify and include the expected runtime from sessions only.
if (!$expectedruntime && method_exists('\pulsecondition_session\conditionform', 'get_session_time')) {
// Confirm any f2f module added in condition.
$sessionstarttime = \pulsecondition_session\conditionform::get_session_time($data, $this->instancedata);
if (!empty($sessionstarttime)) {
$nextrun->setTimestamp($sessionstarttime);
}
}

$delay = $data->delayduration;
$nextrun->modify("+ $delay seconds");

} else if ($data->notifydelay == self::DELAYBEFORE) {
$delay = $data->delayduration;

if ($expectedruntime) {
// SEssion condition only send the expected runtime.
// Session condition only send the expected runtime.
// Reduce the delay directly from the expected runtime.
$nextrun->modify("- $delay seconds");

Expand Down Expand Up @@ -745,7 +760,7 @@ protected function get_users_withroles(array $roles, $context, $childuserid=null

$rolesql .= " WHERE (ra.contextid = :ctxid2 $childcontext) AND ra.roleid $insql ORDER BY u.id";

$params = array('ctxid' => $context->id, 'ctxid2' => $context->id) + $inparams;
$params = ['ctxid' => $context->id, 'ctxid2' => $context->id] + $inparams;

$users = $DB->get_records_sql($rolesql, $params);

Expand Down Expand Up @@ -849,7 +864,7 @@ public static function generate_dynamic_content($contenttype, $contentlength, $c
$content = format_text($chaptertext, $chapter->contentformat, ['noclean' => true, 'overflowdiv' => true]);
$link = new moodle_url('/mod/book/view.php', ['id' => $cm->id, 'chapterid' => $chapterid]);
} else if ($cm->modname == 'page') {
$page = $DB->get_record('page', array('id' => $cm->instance), '*', MUST_EXIST);
$page = $DB->get_record('page', ['id' => $cm->instance], '*', MUST_EXIST);

$content = file_rewrite_pluginfile_urls(
$page->content, 'pluginfile.php', $context->id, 'mod_page', 'content', $page->revision);
Expand Down Expand Up @@ -1037,7 +1052,7 @@ public static function get_schedule_subject($value, $row) {
'class' => 'pulse-automation-info-block',
'data-target' => 'view-content',
'data-instanceid' => $row->instanceid,
'data-userid' => $row->userid
'data-userid' => $row->userid,
]);
}

Expand Down
28 changes: 14 additions & 14 deletions conditions/session/classes/conditionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public function is_user_completed($instancedata, $userid, \completion_info $comp
AND f2f_sts.superceded != 1
AND f2f_sts.statuscode >= :code AND f2f_sts.statuscode < :statuscode";

$existingsignup = $DB->count_records_sql($sql, array(
$existingsignup = $DB->count_records_sql($sql, [
'f2fid' => $modules, 'userid' => $userid,
'code' => MDL_F2F_STATUS_REQUESTED, 'statuscode' => MDL_F2F_STATUS_NO_SHOW));
'code' => MDL_F2F_STATUS_REQUESTED, 'statuscode' => MDL_F2F_STATUS_NO_SHOW]);

return ($existingsignup) ? true : false;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public static function signup_success($eventdata) {
$modules = $additional['modules'] ?? '';

if (!empty($modules)) {
$session = $DB->get_record('facetoface_sessions_dates', array('sessionid' => $sessionid));
$session = $DB->get_record('facetoface_sessions_dates', ['sessionid' => $sessionid], '*', IGNORE_MULTIPLE);
// Trigger all the instance for notifications.
$condition->trigger_instance($notification->instanceid, $userid, $session->timestart);
}
Expand Down Expand Up @@ -218,10 +218,10 @@ public static function get_session_data($face2faceid, $userid) {
WHERE f2f_ss.facetoface = :f2fid AND f2f_su.userid = :userid AND f2f_sd.timestart > :timestart
AND f2f_sts.statuscode >= :code AND f2f_sts.statuscode < :statuscode";

$existingsignup = $DB->get_records_sql($sql, array(
$existingsignup = $DB->get_records_sql($sql, [
'f2fid' => $face2faceid, 'userid' => $userid, 'timestart' => time(), 'code' => MDL_F2F_STATUS_REQUESTED,
'statuscode' => MDL_F2F_STATUS_NO_SHOW
), 0, 1);
'statuscode' => MDL_F2F_STATUS_NO_SHOW,
], 0, 1);
return $existingsignup;
}

Expand All @@ -246,10 +246,10 @@ public static function prepare_session_signup_schedule(?int $instanceid=null) {
$session = facetoface_get_session($sessionid);
$instanceid = $instanceid ?: $session->facetoface;

$potentialuserselector = new \facetoface_candidate_selector('addselect', array(
'sessionid' => $session->id, 'courseid' => $PAGE->course->id));
$potentialuserselector = new \facetoface_candidate_selector('addselect', [
'sessionid' => $session->id, 'courseid' => $PAGE->course->id]);
// Users to signup to the session.
$addusers = optional_param_array($potentialuserselector->get_name(), array(), PARAM_INT);
$addusers = optional_param_array($potentialuserselector->get_name(), [], PARAM_INT);

list($insql, $inparams) = $DB->get_in_or_equal($addusers, SQL_PARAMS_NAMED, 'f2fu');
$params = ['code' => MDL_F2F_STATUS_REQUESTED, 'statuscode' => MDL_F2F_STATUS_NO_SHOW, 'sessionid' => $sessionid];
Expand Down Expand Up @@ -277,7 +277,7 @@ public static function prepare_session_signup_schedule(?int $instanceid=null) {

if (!empty($modules)) {

$session = $DB->get_record('facetoface_sessions_dates', array('sessionid' => $sessionid));
$session = $DB->get_record('facetoface_sessions_dates', ['sessionid' => $sessionid], '*', IGNORE_MULTIPLE);
// Trigger all the instance for notifications.
foreach ($users as $userid) {
$condition->trigger_instance($notification->instanceid, $userid, $session->timestart);
Expand Down Expand Up @@ -309,9 +309,9 @@ public static function remove_session_signup_schedule(?int $instanceid=null) {
$session = facetoface_get_session($sessionid);
$instanceid = $instanceid ?: $session->facetoface;

$potentialuserselector = new \facetoface_candidate_selector('removeselect', array(
'sessionid' => $session->id, 'courseid' => $PAGE->course->id));
$removeusers = optional_param_array($potentialuserselector->get_name(), array(), PARAM_INT);
$potentialuserselector = new \facetoface_candidate_selector('removeselect', [
'sessionid' => $session->id, 'courseid' => $PAGE->course->id]);
$removeusers = optional_param_array($potentialuserselector->get_name(), [], PARAM_INT);

list($insql, $inparams) = $DB->get_in_or_equal($removeusers, SQL_PARAMS_NAMED, 'f2fu');
$params = ['code' => MDL_F2F_STATUS_REQUESTED, 'statuscode' => MDL_F2F_STATUS_NO_SHOW, 'sessionid' => $sessionid];
Expand Down Expand Up @@ -339,7 +339,7 @@ public static function remove_session_signup_schedule(?int $instanceid=null) {

if (!empty($modules)) {

$session = $DB->get_record('facetoface_sessions_dates', array('sessionid' => $sessionid));
$session = $DB->get_record('facetoface_sessions_dates', ['sessionid' => $sessionid], '*', IGNORE_MULTIPLE);
// Trigger all the instance for notifications.
foreach ($removeusers as $userid) {
if (isset($users[$userid])) {
Expand Down
4 changes: 2 additions & 2 deletions conditions/session/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'pulsecondition_session';
$plugin->version = 2023080206;
$plugin->dependencies = array('mod_facetoface' => 2021113000); // Dependencies set for the session module "Face to Face".
$plugin->version = 2023080207;
$plugin->dependencies = ['mod_facetoface' => 2021113000]; // Dependencies set for the session module "Face to Face".

0 comments on commit 81923bb

Please sign in to comment.