$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
- if (!$userid) {
- return has_capability('moodle/legacy:admin', $context, $USER->id, false);
- } else {
- return has_capability('moodle/legacy:admin', $context, $userid, false);
- }
+ return has_capability('moodle/legacy:admin', $context, $userid, false);
}
/**
* Determines if a user is a teacher (or better)
*
- * @uses $USER
* @uses $CFG
* @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. Set this to 0 if you would just like to test against the currently logged in user.
function isteacher($courseid=0, $userid=0, $obsolete_includeadmin=true) {
/// Is the user able to access this course as a teacher?
- global $USER, $CFG;
+ global $CFG;
if (empty($CFG->rolesactive)) { // Teachers are locked out during an upgrade to 1.7
return false;
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
}
- if (!$userid) {
- return (has_capability('moodle/legacy:teacher', $context, $USER->id, false)
- or has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)
- or has_capability('moodle/legacy:admin', $context, $USER->id, false)
- );
- } else {
- return (has_capability('moodle/legacy:teacher', $context, $userid, false)
- or has_capability('moodle/legacy:editingteacher', $context, $userid, false)
- or has_capability('moodle/legacy:admin', $context, $userid, false)
- );
- }
+ return (has_capability('moodle/legacy:teacher', $context, $userid, false)
+ or has_capability('moodle/legacy:editingteacher', $context, $userid, false)
+ or has_capability('moodle/legacy:admin', $context, $userid, false));
}
/**
*
* @uses $USER
* @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 bool $obsolete_includeadmin No longer used
+ * @param bool $includeadmin Include anyone wo is an admin as well
* @return bool
*/
-function isteacherinanycourse($userid=0, $obsolete_includeadmin=true) {
+function isteacherinanycourse($userid=0, $includeadmin=true) {
global $USER, $CFG;
if (empty($CFG->rolesactive)) { // Teachers are locked out during an upgrade to 1.7
}
}
+/// Include admins if required
+ if ($includeadmin) {
+ $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+ if (has_capability('moodle/legacy:admin', $context, $userid, false)) {
+ return true;
+ }
+ }
return false;
}
/**
* Determines if a user is allowed to edit a given course
*
- * @uses $USER
* @param int $courseid The id of the course that is being edited
* @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.
* @return bool
*/
function isteacheredit($courseid, $userid=0, $obsolete_ignorestudentview=false) {
- global $USER, $CFG;
+ global $CFG;
if (empty($CFG->rolesactive)) {
return false;
$context = get_context_instance(CONTEXT_COURSE, $courseid);
}
- if (!$userid) {
- return (has_capability('moodle/legacy:editingteacher', $context, $USER->id, false)
- or has_capability('moodle/legacy:admin', $context, $USER->id, false));
- } else {
- return (has_capability('moodle/legacy:editingteacher', $context, $userid, false)
- or has_capability('moodle/legacy:admin', $context, $userid, false));
- }
+ return (has_capability('moodle/legacy:editingteacher', $context, $userid, false)
+ or has_capability('moodle/legacy:admin', $context, $userid, false));
}
/**
* Determines if a user can create new courses
*
- * @uses $USER
* @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
* @return bool
*/
function iscreator ($userid=0) {
- global $USER, $CFG;
+ global $CFG;
if (empty($CFG->rolesactive)) {
return false;
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
- if (!$userid) {
- return (has_capability('moodle/legacy:coursecreator', $context, $userid, false)
- or has_capability('moodle/legacy:admin', $context, $userid, false));
- } else {
- return (has_capability('moodle/legacy:coursecreator', $context, $USER->id, false)
- or has_capability('moodle/legacy:admin', $context, $USER->id, false));
- }
+ return (has_capability('moodle/legacy:coursecreator', $context, $userid, false)
+ or has_capability('moodle/legacy:admin', $context, $userid, false));
}
/**
* If the course id specifies the site then this determines
* if the user is a confirmed and valid user of this site.
*
- * @uses $USER
* @uses $CFG
* @uses SITEID
* @param int $courseid The id of the course being tested
* @return bool
*/
function isstudent($courseid=0, $userid=0) {
- global $USER, $CFG;
+ global $CFG;
if (empty($CFG->rolesactive)) {
return false;
$context = get_context_instance(CONTEXT_COURSE, $courseid);
}
- if ($userid) {
- return has_capability('moodle/legacy:student', $context, $userid, false);
- } else {
- return has_capability('moodle/legacy:student', $context, $USER->id, false);
- }
+ return has_capability('moodle/legacy:student', $context, $userid, false);
}
/**
* Determines if the specified user is logged in as guest.
*
- * @uses $USER
* @param int $userid The user being tested. You can set this to 0 or leave it blank to test the currently logged in user.
* @return bool
*/
function isguest($userid=0) {
- global $USER, $CFG;
+ global $CFG;
if (empty($CFG->rolesactive)) {
return false;
$context = get_context_instance(CONTEXT_SYSTEM, SITEID);
- if ($userid) {
- return has_capability('moodle/legacy:guest', $context, $userid, false);
- } else {
- return has_capability('moodle/legacy:guest', $context, $USER->id, false);
- }
+ return has_capability('moodle/legacy:guest', $context, $userid, false);
}
/**
* Add a teacher to a given course
*
- * @uses $USER
* @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
function remove_teacher($userid, $courseid=0) {
global $CFG;
- $capability = $editall ? 'moodle/legacy:editingteacher' : 'moodle/legacy:teacher';
-
$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)) {