MDL-30625 full support for main admin

This commit is contained in:
Petr Skoda
2011-12-09 00:13:05 +01:00
committed by Eloy Lafuente (stronk7)
parent e0745be16b
commit db48cf080d
4 changed files with 63 additions and 14 deletions
+17 -9
View File
@@ -49,24 +49,32 @@ define('LASTACCESS_UPDATE_SECS', 60);
/**
* Returns $user object of the main admin user
* primary admin = admin with lowest role_assignment id among admins
*
* @static stdClass $mainadmin
* @return stdClass {@link $USER} record from DB, false if not found
*/
function get_admin() {
global $CFG, $DB;
static $mainadmin = null;
if (!isset($mainadmin)) {
if (! $admins = get_admins()) {
return false;
if (isset($mainadmin)) {
return clone($mainadmin);
}
foreach (explode(',', $CFG->siteadmins) as $id) {
if ($user = $DB->get_record('user', array('id'=>$id, 'deleted'=>0))) {
$mainadmin = $user;
break;
}
//TODO: add some admin setting for specifying of THE main admin
// for now return the first assigned admin
$mainadmin = reset($admins);
}
if ($mainadmin) {
return clone($mainadmin);
} else {
// this should not happen
return false;
}
// we must clone this otherwise code outside can break the static var
return clone($mainadmin);
}
/**