diff --git a/enroluser.php b/enroluser.php index 379208a..a7e9c7a 100644 --- a/enroluser.php +++ b/enroluser.php @@ -104,7 +104,11 @@ if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { } //echo "
";print_r($instance);exit(); $enrol_manual->enrol_user($instance, $adduser->id, $roleid, $timestart, $timeend); - add_to_log($course->id, 'course', 'enrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! + + // Deprecated fixed by Shiro+ //add_to_log($course->id, 'course', 'enrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! + $context = context_course::instance($course->id); + \core\event\user_enrolment_created::create(array('context' => $context))->trigger(); } $potentialuserselector->invalidate_selected_users(); @@ -120,7 +124,11 @@ if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { if (!empty($userstounassign)) { foreach($userstounassign as $removeuser) { $enrol_manual->unenrol_user($instance, $removeuser->id); - add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! + + // Deprecated fixed by Shiro + //add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere! + $context = context_course::instance($course->id); + \core\event\user_enrolment_deleted::delete(array('context' => $context))->trigger(); } $potentialuserselector->invalidate_selected_users(); diff --git a/lib.php b/lib.php index 4a872e6..d92638f 100644 --- a/lib.php +++ b/lib.php @@ -96,7 +96,11 @@ class enrol_apply_plugin extends enrol_plugin { sendConfirmMailToTeachers($instance->courseid, $instance->id, $data->applydescription); sendConfirmMailToManagers($instance->courseid,$data->applydescription); - add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere! + // Deprecated fixed by Shiro + //add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere! + $context = context_course::instance($instance->courseid); + \core\event\user_enrolment_created::create(array('context' => $context))->trigger(); + redirect("$CFG->wwwroot/course/view.php?id=$instance->courseid"); } } diff --git a/unenrolself.php b/unenrolself.php index 9130f56..942014c 100644 --- a/unenrolself.php +++ b/unenrolself.php @@ -49,7 +49,12 @@ $PAGE->set_title($plugin->get_instance_name($instance)); if ($confirm and confirm_sesskey()) { $plugin->unenrol_user($instance, $USER->id); - add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //TODO: there should be userid somewhere! + + // Deprecated fixed by Shiro + //add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //TODO: there should be userid somewhere! + $context = context_course::instance($course->id); + \core\event\user_enrolment_deleted::delete(array('context' => $context))->trigger(); + redirect(new moodle_url('/index.php')); } diff --git a/unenroluser.php b/unenroluser.php index a8ec0ab..dfea543 100644 --- a/unenroluser.php +++ b/unenroluser.php @@ -31,15 +31,16 @@ $ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXI // Get the user for whom the enrolment is $user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST); // Get the course the enrolment is to -list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); -$sql = "SELECT c.* $ctxsql +//list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx'); +$ctxsql = context_helper::get_preload_record_columns_sql('ctx'); +$sql = "SELECT c.*, $ctxsql FROM {course} c LEFT JOIN {enrol} e ON e.courseid = c.id - $ctxjoin + LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextcourse) WHERE e.id = :enrolid"; -$params = array('enrolid' => $ue->enrolid); +$params = array('enrolid' => $ue->enrolid, 'contextcourse' => CONTEXT_COURSE); $course = $DB->get_record_sql($sql, $params, MUST_EXIST); -context_instance_preload($course); +context_helper::preload_from_record($course); // Make sure it's not the front page @@ -94,4 +95,4 @@ $PAGE->navbar->add($fullname); echo $OUTPUT->header(); echo $OUTPUT->heading($fullname); echo $OUTPUT->confirm($message, $yesurl, $returnurl); -echo $OUTPUT->footer(); \ No newline at end of file +echo $OUTPUT->footer();