Skip to content

Commit

Permalink
Merge branch 'main' into dev_automation
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanscholz authored Jan 8, 2024
2 parents b2ae68b + 03f06b8 commit bab9b37
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
41 changes: 24 additions & 17 deletions classes/task/notify_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function pulse_cron_task($extend=true) {
return true;
}

$rolesql = "SELECT rc.roleid FROM {role_capabilities} rc
$rolesql = "SELECT rc.id, rc.roleid FROM {role_capabilities} rc
JOIN {capabilities} cap ON rc.capability = cap.name
JOIN {context} ctx on rc.contextid = ctx.id
WHERE rc.capability = :capability ";
Expand All @@ -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
13 changes: 11 additions & 2 deletions classes/task/sendinvitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,21 @@ public function send_pulse($users, $pulse, $course, $context) {
// Rewrite the plugin file placeholders in the email text.
$messagehtml = file_rewrite_pluginfile_urls($messagehtml, 'pluginfile.php',
$context->id, 'mod_pulse', $filearea, 0);

// Set current student as user, filtercodes plugin uses current User data.
\core\session\manager::set_user($student);
if (isset($student->lang)) {
$oldforcelang = force_current_language($student->lang); // Force the session lang to user lang.
}
// Format filter supports. filter the enabled filters.
$subject = format_text($subject, FORMAT_HTML);
$messagehtml = format_text($messagehtml, FORMAT_HTML);

$messageplain = html_to_text($messagehtml); // Plain text.
// After format the message and subject return back to previous lang.
if (isset($oldforcelang)) {
force_current_language($oldforcelang);
}

// Send message to user.
pulse_mtrace("Sending pulse to the user ". fullname($userto) ."\n" );

Expand Down Expand Up @@ -201,7 +210,7 @@ public static function find_user_sender($senderdata, $userid) {
*/
public static function get_sender($courseid) {
global $DB;
$rolesql = "SELECT rc.roleid FROM {role_capabilities} rc
$rolesql = "SELECT rc.id, rc.roleid FROM {role_capabilities} rc
JOIN {capabilities} cap ON rc.capability = cap.name
JOIN {context} ctx on rc.contextid = ctx.id
WHERE rc.capability = :capability ";
Expand Down
2 changes: 1 addition & 1 deletion classes/task/update_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function mod_pulse_completion_crontask() {

pulse_mtrace('Fetching pulse instance list - MOD-Pulse INIT');

$rolesql = "SELECT rc.roleid FROM {role_capabilities} rc
$rolesql = "SELECT rc.id, rc.roleid FROM {role_capabilities} rc
JOIN {capabilities} cap ON rc.capability = cap.name
JOIN {context} ctx on rc.contextid = ctx.id
WHERE rc.capability = :capability ";
Expand Down

0 comments on commit bab9b37

Please sign in to comment.