Skip to content

Commit

Permalink
Merge pull request #139 from isuru89/fix/activity-overrides
Browse files Browse the repository at this point in the history
Respect activity overrides and extensions #134
  • Loading branch information
isuru89 authored Sep 25, 2021
2 parents dbee53f + e2379d0 commit 84b6985
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 13 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Moodle - Local Reminders
---
![Version](https://img.shields.io/badge/version-v2.4-blue)
![Version](https://img.shields.io/badge/version-v2.5-blue)
![Moodle Version](https://img.shields.io/badge/moodle-%3E%3D%203.5-orange)
![Maturiy](https://img.shields.io/badge/maturity-STABLE-brightgreen)
![License](https://img.shields.io/badge/license-GPL%20v3-green)
![Maintenance](https://img.shields.io/maintenance/yes/2022)
[![Build Status](https://github.com/isuru89/moodle-local_reminders/actions/workflows/moodle-ci.yml/badge.svg?branch=release_2.0)](https://github.com/isuru89/moodle-local_reminders/actions/workflows/moodle-ci.yml)

This plugin will send email reminders for [Moodle](https://moodle.org/) calendar events.
Expand All @@ -25,11 +27,12 @@ In addition to that, there are lot of new features introduced in v2 of the plugi
* Send reminders to users who unable to complete an expired activity.
* Send email reminders when a calendar event is created, updated or removed.
* Ability to enable/disable and scheduling reminders per activity basis.
* Ability to customize email header and footer contents
* Ability to exclude specific set of activity types from sending reminders.
* No reminders after a user has completed activity.
* Added event location / timezone information to the reminder email.
* New category event type support
* Improved email style
* New category event type support.
* Honours activity overriddes and extensions.

And many bug fixes too.

Expand Down Expand Up @@ -96,6 +99,11 @@ In addition to above, user can control reminders for calendar event changes per

## Changelog

### v2.5
* Ability to customize reminder email header and footer #137 #135
* Bug fix on user and group overrides and extensions #134
* Minor bug fixes #136

### v2.4
* Ability to explicitly turn on reminders instead of enabling by default for all (#129, #130)

Expand Down
2 changes: 1 addition & 1 deletion classes/calendar_observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ public static function calendar_event_added($event) {
when_calendar_event_updated($event, REMINDERS_CALENDAR_EVENT_ADDED);
}

}
}
2 changes: 1 addition & 1 deletion classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ class provider implements
public static function get_reason() : string {
return 'privacy:metadata';
}
}
}
2 changes: 1 addition & 1 deletion coursesettings_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ private function generate_event_link($event) {

return $calurl->out(false);
}
}
}
2 changes: 1 addition & 1 deletion db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
'eventname' => '\core\event\calendar_event_deleted',
'callback' => '\local_reminders\calendar_observer::calendar_event_removed'
)
);
);
2 changes: 1 addition & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ function create_local_reminders_post_activity_table($dbman) {
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
}
}
4 changes: 4 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
define('REMINDERS_CLEAN_TABLE', 'local_reminders');
define('REMINDERS_ENABLED_KEY', 'enabled');

define('REMINDERS_SUPPORTED_OVERRIDES', array('assign', 'quiz'));
define('REMINDERS_SUPPORTED_OVERRIDES_REF_IDS', array('assign' => 'assignid', 'quiz' => 'quiz'));


/**
* ======== FUNCTIONS =========================================
*/
Expand Down
54 changes: 52 additions & 2 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function handle_course_activity_event($event, $course, $cm, $options) {
$showtrace && mtrace(" [Local Reminder] Event #".$event->id." is a user overridden ".$event->modulename." event.");
$user = $DB->get_record('user', array('id' => $event->userid));
$sendusers[] = $user;
} else if ($event->courseid <= 0 && $event->groupid > 0) {
} else if ($event->groupid > 0) {
// A group overridden activity.
$showtrace && mtrace(" [Local Reminder] Event #".$event->id." is a group overridden ".$event->modulename." event.");
$group = $DB->get_record('groups', array('id' => $event->groupid));
Expand All @@ -296,6 +296,7 @@ function handle_course_activity_event($event, $course, $cm, $options) {
// Here 'ra.id field added to avoid printing debug message,
// from get_role_users (has odd behaivior when called with an array for $roleid param'.
$sendusers = get_active_role_users($options->activityroleids, $context);
$sendusers = filter_user_group_overrides($event, $sendusers, $showtrace);

// Filter user list,
// see: https://docs.moodle.org/dev/Availability_API.
Expand Down Expand Up @@ -689,12 +690,61 @@ function get_correct_timeformat_user($user) {
* @return array of user records
*/
function get_active_role_users($activityroleids, $context) {
return get_role_users($activityroleids, $context, true, 'ra.id, u.*',
return get_role_users($activityroleids, $context, true, 'ra.id as ra_id, u.*',
null, false, '', '', '',
'ue.status = :userenrolstatus',
array('userenrolstatus' => ENROL_USER_ACTIVE));
}

/**
* Filter and return eligible set of users after excluding users who belongs
* in overridden extensions.
*
* @param object $event source event object.
* @param array $sendusers all users for this activity instance.
* @param bool $showtrace to print logs or not.
* @return array filtered out users.
*/
function filter_user_group_overrides($event, $sendusers, $showtrace) {
global $DB;

if (!in_array($event->modulename, REMINDERS_SUPPORTED_OVERRIDES)) {
return $sendusers;
}

$showtrace && mtrace(" [Local Reminder] Event supports overrides for key ");
$idcolumn = REMINDERS_SUPPORTED_OVERRIDES_REF_IDS[$event->modulename];
$overridesrecords = $DB->get_records($event->modulename.'_overrides', array($idcolumn => $event->instance));
if (empty($overridesrecords)) {
$showtrace && mtrace(" [Local Reminder] No overrides for activity ".$event->instance."!");
return $sendusers;
}

$extendedusers = [];
foreach ($overridesrecords as $record) {
if ($record->userid > 0) {
$showtrace && mtrace(" Overrides for user id: ".$record->userid);
$extendedusers[] = $record->userid;
} else if ($record->groupid > 0) {
$showtrace && mtrace(" Overrides for group id: ".$record->groupid);
$groupmemberroles = groups_get_members_by_role($record->groupid, $event->courseid, 'u.id');
if (!empty($groupmemberroles)) {
foreach ($groupmemberroles as $roleid => $roledata) {
foreach ($roledata->users as $member) {
$extendedusers[] = $member->id;
}
}
}
}
}

$finalarray = array_filter($sendusers, function($it) use ($extendedusers) {
return !in_array($it->id, $extendedusers);
});
return $finalarray;
}


/**
* Returns all users belong to the given group.
*
Expand Down
2 changes: 1 addition & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,4 @@
$settings->add(new admin_setting_configcheckbox('local_reminders_enable_categoryforcalevents',
get_string('enabledforcalevents', 'local_reminders'),
get_string('enabledforcaleventsdescription', 'local_reminders'), 0));
}
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021092500;
$plugin->version = 2021092600;
$plugin->requires = 2018051700; // Require moodle 3.5 or higher.
$plugin->release = '2.5';
$plugin->maturity = MATURITY_RC;
$plugin->maturity = MATURITY_STABLE;
$plugin->component = 'local_reminders';

0 comments on commit 84b6985

Please sign in to comment.