Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace tool_usertours\local\filter;
18
 
19
use tool_usertours\tour;
20
use context;
21
 
22
/**
23
 * Theme filter.
24
 *
25
 * @package    tool_usertours
26
 * @copyright  2016 Andrew Nicols <andrew@nicols.co.uk>
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
class theme extends base {
30
    /**
31
     * The name of the filter.
32
     *
33
     * @return  string
34
     */
35
    public static function get_filter_name() {
36
        return 'theme';
37
    }
38
 
39
    /**
40
     * Retrieve the list of available filter options.
41
     *
42
     * @return  array                   An array whose keys are the valid options
43
     *                                  And whose values are the values to display
44
     */
45
    public static function get_filter_options() {
46
        $manager = \core_plugin_manager::instance();
47
        $themes = $manager->get_installed_plugins('theme');
48
 
49
        $options = [];
50
        foreach (array_keys($themes) as $themename) {
51
            try {
52
                $theme = \theme_config::load($themename);
53
            } catch (Exception $e) {
54
                // Bad theme, just skip it for now.
55
                continue;
56
            }
57
            if ($themename !== $theme->name) {
58
                // Obsoleted or broken theme, just skip for now.
59
                continue;
60
            }
61
            if ($theme->hidefromselector) {
62
                // The theme doesn't want to be shown in the theme selector and as theme
63
                // designer mode is switched off we will respect that decision.
64
                continue;
65
            }
66
            $options[$theme->name] = get_string('pluginname', "theme_{$theme->name}");
67
        }
68
        return $options;
69
    }
70
 
71
    /**
72
     * Check whether the filter matches the specified tour and/or context.
73
     *
74
     * @param   tour        $tour       The tour to check
75
     * @param   context     $context    The context to check
76
     * @return  boolean
77
     */
78
    public static function filter_matches(tour $tour, context $context) {
79
        global $PAGE;
80
 
81
        $values = $tour->get_filter_values('theme');
82
 
83
        if (empty($values)) {
84
            // There are no values configured.
85
            // No values means all.
86
            return true;
87
        }
88
 
89
        // Presence within the array is sufficient. Ignore any value.
90
        $values = array_flip($values);
91
        return isset($values[$PAGE->theme->name]);
92
    }
93
}