From: skodak Date: Thu, 1 May 2008 22:17:01 +0000 (+0000) Subject: MDL-14617 removed legacy add and remove teacher code X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e29b04a047144727bdb0f990ddb5317fb390b1af;p=moodle.git MDL-14617 removed legacy add and remove teacher code --- diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index cc4d20e134..0e1bc646a6 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -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 *