Commit 8be0121f authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Merge branch 'institution-themes' of http://git.luns.net.uk/mahara into institution-themes

parents fd7ad9e9 a6f8900f
......@@ -38,7 +38,7 @@ require_once('searchlib.php');
define('TITLE', get_string('siteoptions', 'admin'));
$langoptions = get_languages();
$themeoptions = get_themes();
$themeoptions = get_all_themes();
$yesno = array(true => get_string('yes'),
false => get_string('no'));
......
......@@ -177,7 +177,7 @@ if ($institution || $add) {
$authtypes = auth_get_available_auth_types();
}
$themeoptions = get_themes();
$themeoptions = get_institution_themes($institution);
$themeoptions['sitedefault'] = '- ' . get_string('sitedefault', 'admin') . ' (' . $themeoptions[get_config('theme')] . ') -';
uksort($themeoptions, 'theme_sort');
......
......@@ -648,6 +648,14 @@ class User {
$this->theme = $i->theme;
}
}
if ($this->authinstance) {
$authobj = AuthFactory::create($this->authinstance);
if (isset($institutions[$authobj->institution])) {
if ($t = $institutions[$authobj->institution]->theme) {
$this->theme = $t;
}
}
}
$this->institutions = $institutions;
$this->admininstitutions = $admininstitutions;
$this->staffinstitutions = $staffinstitutions;
......
......@@ -523,21 +523,85 @@ function get_language_root($language=null) {
}
/**
* Return a list of available themes.
* Return a list of all available themes.
* @return array subdir => name
*/
function get_themes($all=true) {
function get_all_themes() {
static $themes = null;
$institutionthemes = array();
if (!$all) {
global $USER;
$institutions = $USER->get('institutions');
foreach ($institutions as &$i) {
if (!empty($i->theme)) {
$institutionthemes[$i->theme] = 1;
if (is_null($themes)) {
$themes = array();
$themelist = get_all_theme_objects();
foreach ($themelist AS $subdir => $theme) {
$themes[$subdir] = isset($theme->displayname) ? $theme->displayname : $subdir;
}
}
return $themes;
}
/**
* Return a list of themes available to this user
* If the user is a member of any institutions, only themes available to
* those institutions are returned; or
* If a user is not a member of any institution, all themes not marked as
* institution specific are returned.
* @return array subdir => name
*/
function get_user_accessible_themes() {
global $USER;
$themes = array();
if ($institutions = $USER->get('institutions')) {
// Get themes for all of this users institutions
foreach ($institutions AS $i) {
$themelist = get_institution_themes($i->institution);
foreach ($themelist AS $subdir => $theme) {
$themes[$subdir] = isset($theme->displayname) ? $theme->displayname : $subdir;
}
}
}
else {
$themelist = get_all_theme_objects();
foreach ($themelist AS $subdir => $theme) {
if (!is_array($theme->institutions)) {
$themes[$subdir] = isset($theme->displayname) ? $theme->displayname : $subdir;
}
}
}
return $themes;
}
/**
* Return a list of themes available to the specified institution
* @param string institution the name of the institution to load themes for
* @return array subdir => name
* @throws SystemException if unable to read the theme directory
*/
function get_institution_themes($institution) {
static $institutionthemes = array();
if (!isset($institutionthemes[$institution])) {
$themes = get_all_theme_objects();
$r = array();
foreach ($themes AS $subdir => $theme) {
if (empty($theme->institutions) || !is_array($theme->institutions) || in_array($institution, $theme->institutions)) {
$r[$subdir] = isset($theme->displayname) ? $theme->displayname : $subdir;
}
}
$institutionthemes[$institution] = $r;
}
return $institutionthemes[$institution];
}
/**
* Return a list of all themes available on the system
* @return array An array of theme objects
* @throws SystemException if unable to read the theme directory
*/
function get_all_theme_objects() {
static $themes = null;
if (is_null($themes)) {
$themes = array();
......@@ -550,8 +614,8 @@ function get_themes($all=true) {
$config_path = $themebase . $subdir . '/themeconfig.php';
if (is_readable($config_path)) {
require($config_path);
if ($all || empty($theme->institution_only) || isset($institutionthemes[$subdir])) {
$themes[$subdir] = isset($theme->displayname) ? $theme->displayname : $subdir;
if (empty($theme->disabled) || !$theme->disabled) {
$themes[$subdir] = $theme;
}
}
}
......
......@@ -124,7 +124,7 @@ $extraconfig = array(
// Set up theme
$viewtheme = $view->get('theme');
$allowedthemes = get_themes(false);
$allowedthemes = get_user_accessible_themes();
if ($viewtheme && $THEME->basename != $viewtheme) {
$THEME = new Theme($viewtheme);
}
......
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