Commit 5ec1e1ff authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Override the header logo with institution logo for members



Bug #805780

When a user's institutions are loaded, fetch the institution logos.
When choosing which of the user's institutions determines their theme,
ensure the same institution determines the replacement logo.  Finally,
if the page theme to be displayed is determined by the user, use the
user's header logo in the header template.

Change-Id: I710d6ff727d90276fc5008b179c60700f4499ccc
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 10f7c8f3
......@@ -86,6 +86,7 @@ class User {
'institutions' => array(),
'grouproles' => array(),
'theme' => null,
'headerlogo' => null,
'admininstitutions' => array(),
'staffinstitutions' => array(),
'parentuser' => null,
......@@ -820,30 +821,43 @@ class User {
$admininstitutions = array();
$staffinstitutions = array();
$this->theme = get_config('theme');
foreach ($institutions as $i) {
$this->headerlogo = null;
$themeinstitution = null;
foreach ($institutions as $name => $i) {
if ($i->admin) {
$admininstitutions[$i->institution] = $i->institution;
}
if ($i->staff) {
$staffinstitutions[$i->institution] = $i->institution;
}
if (!empty($i->theme) && $this->theme == get_config('theme') && $i->theme != $this->theme) {
$this->theme = $i->theme;
if (is_null($themeinstitution)) {
$themeinstitution = $name;
}
}
if ($this->authinstance) {
$authobj = AuthFactory::create($this->authinstance);
if (isset($institutions[$authobj->institution])) {
if ($t = $institutions[$authobj->institution]->theme) {
$this->theme = $t;
if ($institutions[$authobj->institution]->theme) {
$themeinstitution = $authobj->institution;
}
}
}
if (!is_null($themeinstitution)) {
$this->theme = $institutions[$themeinstitution]->theme;
$this->headerlogo = $institutions[$themeinstitution]->logo;
}
$this->institutions = $institutions;
$this->admininstitutions = $admininstitutions;
$this->staffinstitutions = $staffinstitutions;
}
public function get_themedata() {
return (object) array(
'basename' => $this->theme,
'headerlogo' => $this->headerlogo,
);
}
public function reset_grouproles() {
$memberships = get_records_array('group_member', 'member', $this->get('id'));
$roles = array();
......@@ -1310,8 +1324,8 @@ class LiveUser extends User {
public function reset_institutions() {
global $THEME;
parent::reset_institutions();
if (isset($THEME->basename) && $this->theme != $THEME->basename && !defined('INSTALLER')) {
$THEME = new Theme($this->theme);
if (!defined('INSTALLER')) {
$THEME = new Theme($this);
}
}
......
......@@ -1262,7 +1262,7 @@ function load_user_institutions($userid) {
throw new InvalidArgumentException("couldn't load institutions, no user id specified");
}
if ($institutions = get_records_sql_assoc('
SELECT u.institution,'.db_format_tsfield('ctime').','.db_format_tsfield('u.expiry', 'membership_expiry').',u.studentid,u.staff,u.admin,i.theme,i.registerallowed, i.showonlineusers,i.allowinstitutionpublicviews
SELECT u.institution,'.db_format_tsfield('ctime').','.db_format_tsfield('u.expiry', 'membership_expiry').',u.studentid,u.staff,u.admin,i.theme,i.registerallowed, i.showonlineusers,i.allowinstitutionpublicviews, i.logo
FROM {usr_institution} u INNER JOIN {institution} i ON u.institution = i.name
WHERE u.usr = ? ORDER BY i.priority DESC', array($userid))) {
return $institutions;
......
......@@ -375,6 +375,7 @@ EOF;
$sitename = 'Mahara';
}
$smarty->assign('sitename', $sitename);
$smarty->assign('sitelogo', $THEME->header_logo());
if (defined('TITLE')) {
$smarty->assign('PAGETITLE', TITLE . ' - ' . $sitename);
......@@ -567,6 +568,11 @@ class Theme {
*/
public $basename = '';
/**
* A user may have had the header logo overridden by an institution
*/
public $headerlogo;
/**
* A human-readable version of the theme name
*/
......@@ -636,17 +642,21 @@ class Theme {
$themename = $arg;
}
else if ($arg instanceof User) {
$themename = $arg->get('theme');
$themedata = $arg->get_themedata();
}
else if (is_int($arg)) {
$user = new User();
$user->find_by_id($arg);
$themename = $user->get('theme');
$themedata = $user->get_themedata();
}
else {
throw new SystemException("Argument to Theme::__construct was not a theme name, user object or user ID");
}
if (isset($themedata)) {
$themename = $themedata->basename;
}
if (!$themename) {
// Theme to show to when no theme has been suggested
if (!$themename = get_config('theme')) {
......@@ -655,11 +665,11 @@ class Theme {
}
// check the validity of the name
if ($this->name_is_valid($themename)) {
$this->init_theme($themename);
} else {
if (!$this->name_is_valid($themename)) {
throw new SystemException("Theme name is in invalid form: '$themename'");
}
$this->init_theme($themename, $themedata);
}
/**
......@@ -673,7 +683,7 @@ class Theme {
/**
* Given a theme name, reads in all config and sets fields on this object
*/
private function init_theme($themename) {
private function init_theme($themename, $themedata) {
$this->basename = $themename;
$themeconfigfile = get_config('docroot') . 'theme/' . $this->basename . '/themeconfig.php';
......@@ -715,6 +725,10 @@ class Theme {
$this->templatedirs[] = get_config('docroot') . 'theme/' . $currenttheme . '/templates/';
$this->inheritance[] = $currenttheme;
}
if (!empty($themedata->headerlogo)) {
$this->headerlogo = $themedata->headerlogo;
}
}
/**
......@@ -754,6 +768,12 @@ class Theme {
return $returnprefix . $plugindirectory . 'theme/' . $themedir . '/static/' . $filename;
}
public function header_logo() {
if (!empty($this->headerlogo)) {
return get_config('wwwroot') . 'thumb.php?type=logobyid&id=' . $this->headerlogo;
}
return $this->get_url('images/site-logo.png');
}
}
......
......@@ -7,7 +7,7 @@
<div id="container">
{if $SITETOP}{$SITETOP|safe}{/if}
<div id="loading-box"></div>
<div id="top-wrapper"><h1 id="site-logo"><a href="{$WWWROOT}"><img src="{theme_url filename='images/site-logo.png'}" alt="{$sitename}"></a></h1>
<div id="top-wrapper"><h1 id="site-logo"><a href="{$WWWROOT}"><img src="{$sitelogo}" alt="{$sitename}"></a></h1>
{include file="header/topright.tpl"}
{if $DROPDOWNMENU}
{include file="header/dropdown.tpl"}
......
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