See Release Notes
Long Term Support Release
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Theme filter. 19 * 20 * @package tool_usertours 21 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace tool_usertours\local\filter; 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 use tool_usertours\tour; 30 use context; 31 32 /** 33 * Theme filter. 34 * 35 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk> 36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 37 */ 38 class theme extends base { 39 /** 40 * The name of the filter. 41 * 42 * @return string 43 */ 44 public static function get_filter_name() { 45 return 'theme'; 46 } 47 48 /** 49 * Retrieve the list of available filter options. 50 * 51 * @return array An array whose keys are the valid options 52 * And whose values are the values to display 53 */ 54 public static function get_filter_options() { 55 $manager = \core_plugin_manager::instance(); 56 $themes = $manager->get_installed_plugins('theme'); 57 58 $options = []; 59 foreach (array_keys($themes) as $themename) { 60 try { 61 $theme = \theme_config::load($themename); 62 } catch (Exception $e) { 63 // Bad theme, just skip it for now. 64 continue; 65 } 66 if ($themename !== $theme->name) { 67 // Obsoleted or broken theme, just skip for now. 68 continue; 69 } 70 if ($theme->hidefromselector) { 71 // The theme doesn't want to be shown in the theme selector and as theme 72 // designer mode is switched off we will respect that decision. 73 continue; 74 } 75 $options[$theme->name] = get_string('pluginname', "theme_{$theme->name}"); 76 } 77 return $options; 78 } 79 80 /** 81 * Check whether the filter matches the specified tour and/or context. 82 * 83 * @param tour $tour The tour to check 84 * @param context $context The context to check 85 * @return boolean 86 */ 87 public static function filter_matches(tour $tour, context $context) { 88 global $PAGE; 89 90 $values = $tour->get_filter_values('theme'); 91 92 if (empty($values)) { 93 // There are no values configured. 94 // No values means all. 95 return true; 96 } 97 98 // Presence within the array is sufficient. Ignore any value. 99 $values = array_flip($values); 100 return isset($values[$PAGE->theme->name]); 101 } 102 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body