if ($userrecord->id = $DB->insert_record('user', $userrecord)) {
$userrecord = $DB->get_record('user', array('id'=>$userrecord->id));
} else {
- // TODO: Error out
- return false;
+ throw new mnet_server_exception(5011, get_string('couldnotcreateuser', 'enrol_mnet'));
}
}
if (! $course = $DB->get_record('course', array('id'=>$courseid))) {
- // TODO: Error out
- return false;
+ throw new mnet_server_exception(5012, get_string('coursenotfound', 'enrol_mnet'));
}
$courses = $this->available_courses();
if (enrol_into_course($course, $userrecord, 'mnet')) {
return true;
}
+ throw new mnet_server_exception(5016, get_string('couldnotenrol', 'enrol_mnet'));
}
- return false;
+ throw new mnet_server_exception(5013, get_string('courseunavailable', 'enrol_mnet'));
}
/**
function unenrol_user($username, $courseid) {
global $MNET_REMOTE_CLIENT;
- $userrecord = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$MNET_REMOTE_CLIENT->id));
-
- if ($userrecord == false) {
- return false;
- // TODO: Error out
+ if (!$userrecord = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$MNET_REMOTE_CLIENT->id));
+ throw new mnet_exception(5014, get_string('usernotfound', 'enrol_mnet'));
}
if (! $course = $DB->get_record('course', array('id'=>$courseid))) {
- return false;
- // TODO: Error out
+ throw new mnet_server_exception(5012, get_string('coursenotfound', 'enrol_mnet'));
}
- if (! $context = get_context_instance(CONTEXT_COURSE, $course->id)) {
- return false;
- // TODO: Error out (Invalid context)
- }
+ $context = get_context_instance(CONTEXT_COURSE, $course->id);
// Are we a *real* user or the shady MNET Daemon?
// require_capability('moodle/role:assign', $context, NULL, false);
if (!role_unassign(0, $userrecord->id, 0, $context->id)) {
- print_error("unenrolerror");
+ throw new mnet_exception(5015, get_string('couldnotunenrol', 'enrol_mnet'));
}
return true;
'<ul><li><em>Dependency</em>: You must also <strong>subscribe</strong> to the SSO (Service Provider) service on $a.</li>'.
'<li><em>Dependency</em>: You must also <strong>publish</strong> the SSO (Identity Provider) service to $a.</li></ul><br/>';
$string['mnetlocalforexternal'] = 'Local courses for external users';
-
+$string['couldnotcreateuser'] = 'An error occurred while trying to create that user!';
+$string['coursenotfound'] = 'Sorry, but that course doesn\'t exist';
+$string]'courseunavailable'] = 'Sorry, but that course isn\'t available';
+$string['usernotfound'] = 'Sorry, could not find that user record';
+$string['couldnotenrol'] = 'Sorry, could not enrol that user in that course!';
+$string['couldnotenrol'] = 'Sorry, could not unenrol that user from that course!';
?>