Commit ef8a733a authored by Charles Fulton's avatar Charles Fulton
Browse files

MDL-36024 enrol: enable grade recovery for all enrol plugins

parent cf5a3296
...@@ -138,10 +138,11 @@ class enrol_flatfile_plugin extends enrol_plugin { ...@@ -138,10 +138,11 @@ class enrol_flatfile_plugin extends enrol_plugin {
* @param int $timestart 0 means unknown * @param int $timestart 0 means unknown
* @param int $timeend 0 means forever * @param int $timeend 0 means forever
* @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates * @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
* @param bool $recovergrades restore grade history
* @return void * @return void
*/ */
public function enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null) { public function enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) {
parent::enrol_user($instance, $userid, null, $timestart, $timeend, $status); parent::enrol_user($instance, $userid, null, $timestart, $timeend, $status, $recovergrades);
if ($roleid) { if ($roleid) {
$context = context_course::instance($instance->courseid, MUST_EXIST); $context = context_course::instance($instance->courseid, MUST_EXIST);
role_assign($roleid, $userid, $context->id, 'enrol_'.$this->get_name(), $instance->id); role_assign($roleid, $userid, $context->id, 'enrol_'.$this->get_name(), $instance->id);
......
...@@ -52,7 +52,7 @@ class enrol_guest_plugin extends enrol_plugin { ...@@ -52,7 +52,7 @@ class enrol_guest_plugin extends enrol_plugin {
} }
} }
public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timestart = 0, $timeend = 0, $status = NULL) { public function enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) {
// no real enrolments here! // no real enrolments here!
return; return;
} }
......
...@@ -136,11 +136,7 @@ switch ($action) { ...@@ -136,11 +136,7 @@ switch ($action) {
} }
$plugin = $plugins[$instance->enrol]; $plugin = $plugins[$instance->enrol];
if ($plugin->allow_enrol($instance) && has_capability('enrol/'.$plugin->get_name().':enrol', $context)) { if ($plugin->allow_enrol($instance) && has_capability('enrol/'.$plugin->get_name().':enrol', $context)) {
$plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend); $plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend, null, $recovergrades);
if ($recovergrades) {
require_once($CFG->libdir.'/gradelib.php');
grade_recover_history_grades($user->id, $instance->courseid);
}
} else { } else {
throw new enrol_ajax_exception('enrolnotpermitted'); throw new enrol_ajax_exception('enrolnotpermitted');
} }
......
...@@ -6,6 +6,7 @@ information provided here is intended especially for developers. ...@@ -6,6 +6,7 @@ information provided here is intended especially for developers.
* plugins may use general enrol/editenrolment.php page to let users edit * plugins may use general enrol/editenrolment.php page to let users edit
enrolments manually enrolments manually
* new support for grade recovery in enrol_plugin::enrol_user() method
=== 2.4 === === 2.4 ===
...@@ -32,4 +33,4 @@ required changes in code: ...@@ -32,4 +33,4 @@ required changes in code:
=== 2.0 === === 2.0 ===
required changes in code: required changes in code:
* enrolment plugins need to be rewritten to use new API - see inline phpdocs and official plugins * enrolment plugins need to be rewritten to use new API - see inline phpdocs and official plugins
\ No newline at end of file
...@@ -1244,9 +1244,10 @@ abstract class enrol_plugin { ...@@ -1244,9 +1244,10 @@ abstract class enrol_plugin {
* @param int $timestart 0 means unknown * @param int $timestart 0 means unknown
* @param int $timeend 0 means forever * @param int $timeend 0 means forever
* @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates * @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates
* @param bool $recovergrades restore grade history
* @return void * @return void
*/ */
public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timestart = 0, $timeend = 0, $status = NULL) { public function enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) {
global $DB, $USER, $CFG; // CFG necessary!!! global $DB, $USER, $CFG; // CFG necessary!!!
if ($instance->courseid == SITEID) { if ($instance->courseid == SITEID) {
...@@ -1260,6 +1261,9 @@ abstract class enrol_plugin { ...@@ -1260,6 +1261,9 @@ abstract class enrol_plugin {
throw new coding_exception('invalid enrol instance!'); throw new coding_exception('invalid enrol instance!');
} }
$context = context_course::instance($instance->courseid, MUST_EXIST); $context = context_course::instance($instance->courseid, MUST_EXIST);
if (!isset($recovergrades)) {
$recovergrades = $CFG->recovergradesdefault;
}
$inserted = false; $inserted = false;
$updated = false; $updated = false;
...@@ -1314,6 +1318,12 @@ abstract class enrol_plugin { ...@@ -1314,6 +1318,12 @@ abstract class enrol_plugin {
} }
} }
// Recover old grades if present.
if ($recovergrades) {
require_once("$CFG->libdir/gradelib.php");
grade_recover_history_grades($userid, $courseid);
}
// reset current user enrolment caching // reset current user enrolment caching
if ($userid == $USER->id) { if ($userid == $USER->id) {
if (isset($USER->enrol['enrolled'][$courseid])) { if (isset($USER->enrol['enrolled'][$courseid])) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment