MDL-35148 themes: Updated checks deciding when mobile themes are used

Now, if a site-theme is set for tablet/phone AND the user is using
a tablet/phone that site-theme will be used, always. In any other
case the normal theme resolution will be used: course, category, ...
This commit is contained in:
Frederic Massart 2015-06-10 17:22:47 +08:00
parent e1d4e288ac
commit e32af34f76

View File

@ -1560,16 +1560,22 @@ class moodle_page {
}
}
$devicetheme = core_useragent::get_device_type_theme($this->devicetypeinuse);
// The user is using another device than default, and we have a theme for that, we should use it.
$hascustomdevicetheme = core_useragent::DEVICETYPE_DEFAULT != $this->devicetypeinuse && !empty($devicetheme);
foreach ($themeorder as $themetype) {
switch ($themetype) {
case 'course':
if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && $this->devicetypeinuse == 'default') {
if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && !$hascustomdevicetheme) {
return $this->_course->theme;
}
break;
case 'category':
if (!empty($CFG->allowcategorythemes) && $this->devicetypeinuse == 'default') {
if (!empty($CFG->allowcategorythemes) && !$hascustomdevicetheme) {
$categories = $this->categories;
foreach ($categories as $category) {
if (!empty($category->theme)) {
@ -1586,7 +1592,7 @@ class moodle_page {
break;
case 'user':
if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && $this->devicetypeinuse == 'default') {
if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && !$hascustomdevicetheme) {
if ($mnetpeertheme) {
return $mnetpeertheme;
} else {
@ -1600,12 +1606,11 @@ class moodle_page {
return $mnetpeertheme;
}
// First try for the device the user is using.
$devicetheme = core_useragent::get_device_type_theme($this->devicetypeinuse);
if (!empty($devicetheme)) {
return $devicetheme;
}
// Next try for the default device (as a fallback).
$devicetheme = core_useragent::get_device_type_theme('default');
$devicetheme = core_useragent::get_device_type_theme(core_useragent::DEVICETYPE_DEFAULT);
if (!empty($devicetheme)) {
return $devicetheme;
}