Skip to content

Commit

Permalink
Improved invitation query to send notification based on limit
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Nov 26, 2023
1 parent 7d37056 commit 407582b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
39 changes: 23 additions & 16 deletions classes/task/notify_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function pulse_cron_task($extend=true) {
JOIN {modules} md ON md.id = cm.module
JOIN {course} cu ON cu.id = nt.course
RIGHT JOIN {context} ctx ON ctx.instanceid = cm.id and contextlevel = 70
WHERE md.name = 'pulse' AND cm.visible = 1 AND cu.visible = 1
WHERE md.name = 'pulse' AND cm.visible = 1 AND cu.visible = 1 AND nt.pulse = 1
AND cu.startdate <= :startdate AND (cu.enddate = 0 OR cu.enddate >= :enddate)";

$records = $DB->get_records_sql($sql, ['startdate' => time(), 'enddate' => time()]);
Expand Down Expand Up @@ -129,27 +129,31 @@ public static function pulse_cron_task($extend=true) {
$usersql = "SELECT u.*
FROM {user} u
JOIN (SELECT DISTINCT eu1_u.id
FROM {user} eu1_u
JOIN {user_enrolments} ej1_ue ON ej1_ue.userid = eu1_u.id
JOIN {enrol} ej1_e ON (ej1_e.id = ej1_ue.enrolid AND ej1_e.courseid = ?)
JOIN (SELECT DISTINCT userid
FROM {role_assignments}
WHERE contextid $insql
AND roleid $roleinsql GROUP BY userid
) ra ON ra.userid = eu1_u.id
WHERE 1 = 1 AND ej1_ue.status = 0
AND (ej1_ue.timestart = 0 OR ej1_ue.timestart <= ?)
AND (ej1_ue.timeend = 0 OR ej1_ue.timeend > ?)
AND eu1_u.deleted = 0 AND eu1_u.id <> ? AND eu1_u.deleted = 0) je ON je.id = u.id
WHERE u.deleted = 0 AND u.suspended = 0 ORDER BY u.lastname, u.firstname, u.id";
FROM {user} eu1_u
JOIN {user_enrolments} ej1_ue ON ej1_ue.userid = eu1_u.id
JOIN {enrol} ej1_e ON (ej1_e.id = ej1_ue.enrolid AND ej1_e.courseid = ?)
JOIN (SELECT DISTINCT userid
FROM {role_assignments}
WHERE contextid $insql
AND roleid $roleinsql GROUP BY userid
) ra ON ra.userid = eu1_u.id
WHERE 1 = 1 AND ej1_ue.status = 0
AND (ej1_ue.timestart = 0 OR ej1_ue.timestart <= ?)
AND (ej1_ue.timeend = 0 OR ej1_ue.timeend > ?)
AND eu1_u.deleted = 0 AND eu1_u.id <> ? AND eu1_u.deleted = 0) je ON je.id = u.id
WHERE u.deleted = 0 AND u.suspended = 0 AND u.id NOT IN (
SELECT userid FROM {pulse_users} WHERE pulseid = ? AND status = 1
) ORDER BY u.lastname, u.firstname, u.id";

$params[] = $course['id'];
$params = array_merge($params, array_filter($inparams));
$params = array_merge($params, array_filter($roleinparams));
$params[] = time();
$params[] = time();
$params[] = 1;
$students = $DB->get_records_sql($usersql, $params);
$params[] = $pulse['id'];
$limit = get_config('mod_pulse', 'schedulecount') ?: 100;
$students = $DB->get_records_sql($usersql, $params, 0, $limit);

$courseid = $pulse['course'];

Expand All @@ -159,7 +163,10 @@ public static function pulse_cron_task($extend=true) {
$instance->context = (object) $context;
$instance->cm = (object) $cm;
$instance->students = $students;
self::pulse_set_notification_adhoc($instance);
// Students are available.
if (!empty($students)) {
self::pulse_set_notification_adhoc($instance);
}
}
pulse_mtrace('Pulse message sending completed....');
return true;
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 = 2023051800;
$plugin->version = 2023051801;
$plugin->requires = 2020061500; // Requires Moodle 3.90.
$plugin->release = 'v1.3';
$plugin->maturity = MATURITY_RC;
Expand Down

0 comments on commit 407582b

Please sign in to comment.