Skip to content

Commit

Permalink
MDL-14617 removed legacy add and remove teacher code
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed May 1, 2008
1 parent 53b4c28 commit e29b04a
Showing 1 changed file with 0 additions and 97 deletions.
97 changes: 0 additions & 97 deletions lib/deprecatedlib.php
Expand Up @@ -240,103 +240,6 @@ function isguest($userid=0) {
return has_capability('moodle/legacy:guest', $context, $userid, false);
}

/**
* Add a teacher to a given course
*
* @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, if any
* @param int $editall Can edit the course
* @param string $role Obsolete
* @param int $timestart The time they start
* @param int $timeend The time they end in this role
* @param string $enrol The type of enrolment this is
* @return bool
*/
function add_teacher($userid, $courseid, $editall=1, $role='', $timestart=0, $timeend=0, $enrol='manual') {
global $CFG;

if (!$user = get_record('user', 'id', $userid)) { // Check user
return false;
}

$capability = $editall ? 'moodle/legacy:editingteacher' : 'moodle/legacy:teacher';

if (!$roles = get_roles_with_capability($capability, 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;
}

/**
* Removes a teacher from a given course (or ALL courses)
* Does not delete the user account
*
* @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 remove_teacher($userid, $courseid=0) {
global $CFG;

$roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW);

if ($roles) {
$roles += get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW);
} else {
$roles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW);
}

if (empty($roles)) {
return true;
}

$return = true;

if ($courseid) {

if (!$context = get_context_instance(CONTEXT_COURSE, $courseid)) {
return false;
}

/// 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);
}
}

/// No need to remove from groups now

foreach ($roles as $role) { // Unassign them from all the teacher roles
$newreturn = role_unassign($role->id, $userid, 0, $context->id);
if (empty($newreturn)) {
$return = false;
}
}

} else {
delete_records('forum_subscriptions', 'userid', $userid);
$return = true;
foreach ($roles as $role) { // Unassign them from all the teacher roles
$newreturn = role_unassign($role->id, $userid, 0, 0);
if (empty($newreturn)) {
$return = false;
}
}
}

return $return;
}

/**
* Add an admin to a site
*
Expand Down

0 comments on commit e29b04a

Please sign in to comment.