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

This commit is contained in:
Charles Fulton 2013-03-08 12:26:36 -08:00
parent cf5a3296c4
commit ef8a733aa6
5 changed files with 18 additions and 10 deletions

View File

@ -138,10 +138,11 @@ class enrol_flatfile_plugin extends enrol_plugin {
* @param int $timestart 0 means unknown
* @param int $timeend 0 means forever
* @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
*/
public function enrol_user(stdClass $instance, $userid, $roleid = null, $timestart = 0, $timeend = 0, $status = null) {
parent::enrol_user($instance, $userid, null, $timestart, $timeend, $status);
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, $recovergrades);
if ($roleid) {
$context = context_course::instance($instance->courseid, MUST_EXIST);
role_assign($roleid, $userid, $context->id, 'enrol_'.$this->get_name(), $instance->id);

View File

@ -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!
return;
}

View File

@ -136,11 +136,7 @@ switch ($action) {
}
$plugin = $plugins[$instance->enrol];
if ($plugin->allow_enrol($instance) && has_capability('enrol/'.$plugin->get_name().':enrol', $context)) {
$plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend);
if ($recovergrades) {
require_once($CFG->libdir.'/gradelib.php');
grade_recover_history_grades($user->id, $instance->courseid);
}
$plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend, null, $recovergrades);
} else {
throw new enrol_ajax_exception('enrolnotpermitted');
}

View File

@ -6,6 +6,7 @@ information provided here is intended especially for developers.
* plugins may use general enrol/editenrolment.php page to let users edit
enrolments manually
* new support for grade recovery in enrol_plugin::enrol_user() method
=== 2.4 ===
@ -32,4 +33,4 @@ required changes in code:
=== 2.0 ===
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

View File

@ -1244,9 +1244,10 @@ abstract class enrol_plugin {
* @param int $timestart 0 means unknown
* @param int $timeend 0 means forever
* @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
*/
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!!!
if ($instance->courseid == SITEID) {
@ -1260,6 +1261,9 @@ abstract class enrol_plugin {
throw new coding_exception('invalid enrol instance!');
}
$context = context_course::instance($instance->courseid, MUST_EXIST);
if (!isset($recovergrades)) {
$recovergrades = $CFG->recovergradesdefault;
}
$inserted = false;
$updated = false;
@ -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
if ($userid == $USER->id) {
if (isset($USER->enrol['enrolled'][$courseid])) {