Commit 01c43b82 authored by Andrew Robert Nicols's avatar Andrew Robert Nicols
Browse files

Improvements to per-institution theme selection

To allow an institution to have multiple themes available to it, this
change introduces a check on an optional theme parameter
$theme->institution. Only themes where $theme->institution matches the name
of the institution given, or where the value is not set are returned.

This change allows for multiple themes to be made available to an
institution.

The following behaviours should be seen:
* admin/users/institutions.php now only shows themes which are sitewide, or
  intended for the specified institution;
* admin/site/options.php shows all themes on the system (not just sitewide
  themes); and
* view/blocks.php lists all themes for all institutions a user belongs to,
  plus sitewide themes. This changes the behaviour introduced in
  4e0132ac

 which restricted available view
  themes to the currently set themes of each institution. However, I feel
  that this change offers more possibilities as institutions will be able
  to have a series of themes available for views; in addition to their
  primary Mahara theme.
Signed-off-by: default avatarAndrew Robert Nicols <andrew.nicols@luns.net.uk>
parent 320bdce4
......@@ -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');
......
......@@ -524,21 +524,85 @@ function get_language_root($language=null) {
/**
* Return a list of available themes.
* @return array subdir => name
*/
function get_themes($all=true) {
function get_all_themes() {
static $themes = null;
$institutionthemes = array();
if (!$all) {
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_available_themes() {
global $USER;
$institutions = $USER->get('institutions');
foreach ($institutions as &$i) {
if (!empty($i->theme)) {
$institutionthemes[$i->theme] = 1;
$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 (empty($theme->institution)) {
$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->institution) || $theme->institution == $institution) {
$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();
$themebase = get_config('docroot') . 'theme/';
......@@ -550,9 +614,7 @@ 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;
}
$themes[$subdir] = $theme;
}
}
}
......
......@@ -123,7 +123,7 @@ $extraconfig = array(
// Set up theme
$viewtheme = $view->get('theme');
$allowedthemes = get_themes(false);
$allowedthemes = get_available_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