According to the final comments in SC#65:

Made isteacher() require that the first parameter (course id) be
specified and non-empty. If it is empty, [i.e., 0, which was used to
simulate what has now become isteacherinanycourse()], then the return
value IS correct but a warning is printed on screen. This should allow
us to track down any such calls in legacy modules without breaking Moodle.

The correct way to check for teacher status in ANY course is now to
call isteacherinanycourse().
This commit is contained in:
defacer 2005-01-23 21:38:01 +00:00
parent cae46b18c6
commit 9407d4563f
7 changed files with 33 additions and 12 deletions

View file

@ -28,7 +28,7 @@ class block_participants extends block_base {
$course = get_record('course', 'id', $this->instance->pageid);
if ($this->instance->pageid != SITEID || $CFG->showsiteparticipantslist > 1 || ($CFG->showsiteparticipantslist == 1 && isteacher()) || isteacher(SITEID)) {
if ($this->instance->pageid != SITEID || $CFG->showsiteparticipantslist > 1 || ($CFG->showsiteparticipantslist == 1 && isteacherinanycourse()) || isteacher(SITEID)) {
$this->content->items[]='<a title="'.get_string('listofallpeople').'" href="'.$CFG->wwwroot.'/user/index.php?id='.$this->instance->pageid.'">'.get_string('participants').'</a>';
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="" />';
}

View file

@ -2765,7 +2765,7 @@ function count_login_failures($mode, $username, $lastlogin) {
$count->accounts = count_records_select('log', $select, 'COUNT(DISTINCT info)');
return $count;
}
} else if ($mode == 'everybody' or ($mode == 'teacher' and isteacher())) {
} else if ($mode == 'everybody' or ($mode == 'teacher' and isteacherinanycourse())) {
if ($count->attempts = count_records_select('log', $select .' AND info = \''. $username .'\'')) {
return $count;
}

View file

@ -1079,20 +1079,25 @@ function isadmin($userid=0) {
/**
* Determines if a user is a teacher or an admin
*
* @uses $USER
* @uses $USER
* @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.
* @param boolean $includeadmin If true this function will return true when it encounters an admin user.
* @return boolean
* @todo Finish documenting this function
*/
function isteacher($courseid=0, $userid=0, $includeadmin=true) {
function isteacher($courseid, $userid=0, $includeadmin=true) {
global $USER;
if ($includeadmin and isadmin($userid)) { // admins can do anything the teacher can
return true;
}
if (empty($courseid)) {
notify('isteacher() should not be used without a valid course id as argument');
return isteacherinanycourse($userid, $includeadmin);
}
if (!$userid) {
if ($courseid) {
return !empty($USER->teacher[$courseid]);
@ -1103,11 +1108,27 @@ function isteacher($courseid=0, $userid=0, $includeadmin=true) {
$userid = $USER->id;
}
if (!$courseid) {
return record_exists('user_teachers', 'userid', $userid);
return record_exists('user_teachers', 'userid', $userid, 'course', $courseid);
}
/**
* Determines if a user is a teacher in any course, or an admin
*
* @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 boolean $includeadmin If true this function will return true when it encounters an admin user.
* @return boolean
* @todo Finish documenting this function
*/
function isteacherinanycourse($userid = 0, $includeadmin = true) {
if(empty($userid)) {
if(empty($USER) || empty($USER->id)) {
return false;
}
$userid = $USER->id;
}
return record_exists('user_teachers', 'userid', $userid, 'course', $courseid);
return record_exists('user_teachers', 'userid', $userid);
}
/**

View file

@ -47,7 +47,7 @@ $qtype = $question->qtype;
require_login();
if (!isteacher()) {
if (!isteacherinanycourse()) {
error('This page is for teachers only');
}

View file

@ -40,10 +40,10 @@
/////////////////////////////////////
// Check access
/////////////////////////////////////
if ($quizid == 0) { // teache doing preview during quiz creation
if ($quizid == 0) { // teacher doing preview during quiz creation
if ($questioncategory->publish) {
require_login();
if (!isteacher()) {
if (!isteacherinanycourse()) {
error('No valid arguments supplied');
}
} else {

View file

@ -28,7 +28,7 @@
if (!$CFG->showsiteparticipantslist and !isteacher(SITEID)) {
notice(get_string('sitepartlist0'));
}
if ($CFG->showsiteparticipantslist < 2 and !isteacher()) {
if ($CFG->showsiteparticipantslist < 2 and !isteacherinanycourse()) {
notice(get_string('sitepartlist1'));
}
}

View file

@ -69,7 +69,7 @@
}
if (!$course->category and !$currentuser) { // To reduce possibility of "browsing" userbase at site level
if (!isteacher() and !isteacher(0, $user->id) ) { // Teachers can browse and be browsed at site level
if (!isteacherinanycourse() and !isteacherinanycourse($user->id) ) { // Teachers can browse and be browsed at site level
print_header("$personalprofile: ", "$personalprofile: ",
"<a href=\"index.php?id=$course->id\">$participants</a>",
"", "", true, "&nbsp;", navmenu($course));