Commit c4a7f1c1 authored by Donal McMullan's avatar Donal McMullan

New functions: auth_get_auth_instances_for_username and

auth_get_auth_instances_for_wwwroot
parent d6a396bb
......@@ -424,6 +424,73 @@ function auth_get_auth_instances_for_institution($institution) {
return $cache[$institution];
}
function auth_get_auth_instances_for_wwwroot($wwwroot) {
global $CFG;
$query = " SELECT
ai.*,
aic.*,
i.*
FROM
{$CFG->dbprefix}auth_instance ai,
{$CFG->dbprefix}auth_instance_config aic,
{$CFG->dbprefix}institution i
WHERE
aic.field = 'wwwroot' AND
aic.value = ? AND
aic.instance = ai.id AND
i.name = ai.institution";
return get_records_sql_array($query, array('value' => $wwwroot));
}
/**
* Given an institution, returns the authentication methods used by it, sorted
* by priority.
*
* @param string $institution Name of the institution
* @return array Array of auth instance records
*/
function auth_get_auth_instances_for_username($institution, $username) {
global $CFG;
static $cache = array();
if (!isset($cache[$institution][$username])) {
// Get auth instances in order of priority
// DO NOT CHANGE THE SORT ORDER OF THIS RESULT SET
// YEAH EINSTEIN - THAT MEANS YOU!!!
// TODO: work out why this won't accept a placeholder - had to use db_quote
$sql ='
SELECT DISTINCT
i.id,
i.instancename,
i.priority,
i.authname,
a.requires_config,
a.requires_parent
FROM
'.$CFG->dbprefix.'auth_instance i,
'.$CFG->dbprefix.'auth_installed a,
'.$CFG->dbprefix.'usr u
WHERE
a.name = i.authname AND
i.institution = ? AND
u.username = ? AND
u.institution = i.institution
ORDER BY
i.priority,
i.instancename';
$cache[$institution][$username] = get_records_sql_array($sql, array(array('institution' => $institution), array('username' => $username)));
if(empty($cache[$institution])) {
return false;
}
}
return $cache[$institution];
}
/**
* Given an institution, get all the auth types EXCEPT those that are already
* enabled AND do not require configuration.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment