mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
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:
parent
cae46b18c6
commit
9407d4563f
7 changed files with 33 additions and 12 deletions
|
@ -28,7 +28,7 @@ class block_participants extends block_base {
|
||||||
|
|
||||||
$course = get_record('course', 'id', $this->instance->pageid);
|
$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->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="" />';
|
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/users.gif" height="16" width="16" alt="" />';
|
||||||
}
|
}
|
||||||
|
|
|
@ -2765,7 +2765,7 @@ function count_login_failures($mode, $username, $lastlogin) {
|
||||||
$count->accounts = count_records_select('log', $select, 'COUNT(DISTINCT info)');
|
$count->accounts = count_records_select('log', $select, 'COUNT(DISTINCT info)');
|
||||||
return $count;
|
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 .'\'')) {
|
if ($count->attempts = count_records_select('log', $select .' AND info = \''. $username .'\'')) {
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1079,20 +1079,25 @@ function isadmin($userid=0) {
|
||||||
/**
|
/**
|
||||||
* Determines if a user is a teacher or an admin
|
* 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 $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 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.
|
* @param boolean $includeadmin If true this function will return true when it encounters an admin user.
|
||||||
* @return boolean
|
* @return boolean
|
||||||
* @todo Finish documenting this function
|
* @todo Finish documenting this function
|
||||||
*/
|
*/
|
||||||
function isteacher($courseid=0, $userid=0, $includeadmin=true) {
|
function isteacher($courseid, $userid=0, $includeadmin=true) {
|
||||||
global $USER;
|
global $USER;
|
||||||
|
|
||||||
if ($includeadmin and isadmin($userid)) { // admins can do anything the teacher can
|
if ($includeadmin and isadmin($userid)) { // admins can do anything the teacher can
|
||||||
return true;
|
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 (!$userid) {
|
||||||
if ($courseid) {
|
if ($courseid) {
|
||||||
return !empty($USER->teacher[$courseid]);
|
return !empty($USER->teacher[$courseid]);
|
||||||
|
@ -1103,11 +1108,27 @@ function isteacher($courseid=0, $userid=0, $includeadmin=true) {
|
||||||
$userid = $USER->id;
|
$userid = $USER->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$courseid) {
|
return record_exists('user_teachers', 'userid', $userid, 'course', $courseid);
|
||||||
return record_exists('user_teachers', 'userid', $userid);
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -47,7 +47,7 @@ $qtype = $question->qtype;
|
||||||
|
|
||||||
require_login();
|
require_login();
|
||||||
|
|
||||||
if (!isteacher()) {
|
if (!isteacherinanycourse()) {
|
||||||
error('This page is for teachers only');
|
error('This page is for teachers only');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,10 @@
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
// Check access
|
// Check access
|
||||||
/////////////////////////////////////
|
/////////////////////////////////////
|
||||||
if ($quizid == 0) { // teache doing preview during quiz creation
|
if ($quizid == 0) { // teacher doing preview during quiz creation
|
||||||
if ($questioncategory->publish) {
|
if ($questioncategory->publish) {
|
||||||
require_login();
|
require_login();
|
||||||
if (!isteacher()) {
|
if (!isteacherinanycourse()) {
|
||||||
error('No valid arguments supplied');
|
error('No valid arguments supplied');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
if (!$CFG->showsiteparticipantslist and !isteacher(SITEID)) {
|
if (!$CFG->showsiteparticipantslist and !isteacher(SITEID)) {
|
||||||
notice(get_string('sitepartlist0'));
|
notice(get_string('sitepartlist0'));
|
||||||
}
|
}
|
||||||
if ($CFG->showsiteparticipantslist < 2 and !isteacher()) {
|
if ($CFG->showsiteparticipantslist < 2 and !isteacherinanycourse()) {
|
||||||
notice(get_string('sitepartlist1'));
|
notice(get_string('sitepartlist1'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$course->category and !$currentuser) { // To reduce possibility of "browsing" userbase at site level
|
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: ",
|
print_header("$personalprofile: ", "$personalprofile: ",
|
||||||
"<a href=\"index.php?id=$course->id\">$participants</a>",
|
"<a href=\"index.php?id=$course->id\">$participants</a>",
|
||||||
"", "", true, " ", navmenu($course));
|
"", "", true, " ", navmenu($course));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue