Permalink
Browse files

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

  • Loading branch information...
1 parent cf5a329 commit ef8a733aa6316ea1ba18754894cb91892a332852 @mackensen mackensen committed Mar 8, 2013
Showing with 18 additions and 10 deletions.
  1. +3 −2 enrol/flatfile/lib.php
  2. +1 −1 enrol/guest/lib.php
  3. +1 −5 enrol/manual/ajax.php
  4. +2 −1 enrol/upgrade.txt
  5. +11 −1 lib/enrollib.php
View
5 enrol/flatfile/lib.php
@@ -138,10 +138,11 @@ public function get_user_enrolment_actions(course_enrolment_manager $manager, $u
* @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
2 enrol/guest/lib.php
@@ -52,7 +52,7 @@ public function get_info_icons(array $instances) {
}
}
- 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
6 enrol/manual/ajax.php
@@ -136,11 +136,7 @@
}
$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
3 enrol/upgrade.txt
@@ -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
12 lib/enrollib.php
@@ -1244,9 +1244,10 @@ public function try_guestaccess(stdClass $instance) {
* @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 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
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 @@ public function enrol_user(stdClass $instance, $userid, $roleid = NULL, $timesta
}
}
+ // 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])) {

0 comments on commit ef8a733

Please sign in to comment.