Skip to content

Commit

Permalink
Improved course completion condition.
Browse files Browse the repository at this point in the history
- Fix PLS-711, PLS-709
  • Loading branch information
prasanna-lmsace committed Feb 6, 2024
1 parent 9d3fce7 commit dd9f79f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions actions/notification/classes/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public function create_schedule_forinstance($newenrolment=false) {
$users = $this->get_users_withroles($roles, $context);
foreach ($users as $userid => $user) {
$suppressreached = notify_users::is_suppress_reached(
$this->notificationdata, $userid, $this->instancedata->course, null);
$this->notificationdata, $user->id, $this->instancedata->course, null);
if ($suppressreached) {
continue;
}
Expand Down Expand Up @@ -730,7 +730,7 @@ protected function get_users_withroles(array $roles, $context, $childuserid=null
list($insql, $inparams) = $DB->get_in_or_equal($roles, SQL_PARAMS_NAMED, 'rle');

// TODO: Define user fields, never get entire fields.
$rolesql = "SELECT DISTINCT u.id, u.*, ra.roleid FROM {role_assignments} ra
$rolesql = "SELECT u.*, ra.id, ra.roleid FROM {role_assignments} ra
JOIN {user} u ON u.id = ra.userid
JOIN {role} r ON ra.roleid = r.id
LEFT JOIN {role_names} rn ON (rn.contextid = :ctxid AND rn.roleid = r.id) ";
Expand Down
3 changes: 3 additions & 0 deletions classes/automation/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ public function timemanagement_details(string $var, \stdClass $course, int $user

// Upcoming event dates.
if ($var == 'eventdates') {
// Calender lib inclusion.
require_once($CFG->dirroot.'/calendar/lib.php');

$calendar = \calendar_information::create(time(), $course->id, null);
list($data, $template) = calendar_get_view($calendar, 'upcoming_mini');
$final = isset($data->events) ? array_map(function($event) {
Expand Down
5 changes: 3 additions & 2 deletions conditions/course/classes/conditionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public static function course_completed($eventdata) {

$data = $eventdata->get_data();
$courseid = $data['courseid'];
$relateduserid = $data['userid'];
// Use the related user id, instead of userid.
// When the course is completed via cron then the event uses the admin user as event user.
$relateduserid = $data['relateduserid'];

// Trigger the instances, this will trigger its related actions for this user.
$like = $DB->sql_like('pat.triggerconditions', ':value');
Expand All @@ -99,7 +101,6 @@ public static function course_completed($eventdata) {
$instances = $DB->get_records_sql($sql, $params);

foreach ($instances as $key => $instance) {
// TODO: Condition status check.
$condition = (new self())->trigger_instance($instance->instanceid, $relateduserid);
}

Expand Down

0 comments on commit dd9f79f

Please sign in to comment.