MDL-14617 removed legacy enrol and unenrol student code

This commit is contained in:
skodak
2008-05-01 22:09:00 +00:00
parent ffe45a68aa
commit 09253986f5
2 changed files with 0 additions and 123 deletions
-80
View File
@@ -240,86 +240,6 @@ function isguest($userid=0) {
return has_capability('moodle/legacy:guest', $context, $userid, false);
}
/**
* Enrols (or re-enrols) a student in a given course
*
* NOTE: Defaults to 'manual' enrolment - enrolment plugins
* must set it explicitly.
*
* @uses $CFG
* @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user.
* @param int $courseid The id of the course that is being viewed
* @param int $timestart ?
* @param int $timeend ?
* @param string $enrol ?
* @return bool
*/
function enrol_student($userid, $courseid, $timestart=0, $timeend=0, $enrol='manual') {
global $CFG;
if (!$user = get_record('user', 'id', $userid)) { // Check user
return false;
}
if (!$roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
return false;
}
$role = array_shift($roles); // We can only use one, let's use the first one
if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
return false;
}
$res = role_assign($role->id, $user->id, 0, $context->id, $timestart, $timeend, 0, $enrol);
return $res;
}
/**
* Unenrols a student from a given course
*
* @param int $courseid The id of the course that is being viewed, if any
* @param int $userid The id of the user that is being tested against.
* @return bool
*/
function unenrol_student($userid, $courseid=0) {
global $CFG;
$status = true;
if ($courseid) {
/// First delete any crucial stuff that might still send mail
if ($forums = get_records('forum', 'course', $courseid)) {
foreach ($forums as $forum) {
delete_records('forum_subscriptions', 'forum', $forum->id, 'userid', $userid);
}
}
/// remove from all legacy student roles
if ($courseid == SITEID) {
$context = get_context_instance(CONTEXT_SYSTEM);
} else if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
return false;
}
if (!$roles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
return false;
}
foreach($roles as $role) {
$status = role_unassign($role->id, $userid, 0, $context->id) and $status;
}
} else {
// recursivelly unenroll student from all courses
if ($courses = get_records('course')) {
foreach($courses as $course) {
$status = unenrol_student($userid, $course->id) and $status;
}
}
}
return $status;
}
/**
* Add a teacher to a given course
*