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
/**
18
 * @package   theme_monocolor
19
 * @copyright 2022 - 2023 Marcin Czaja (https://rosea.io)
20
 * @license   Commercial https://themeforest.net/licenses
21
 */
22
class theme_monocolor_admin_settingspage_tabs extends admin_settingpage {
23
 
24
    /** @var The tabs */
25
    protected $tabs = array();
26
 
27
    /**
28
     * Add a tab.
29
     *
30
     * @param admin_settingpage $tab A tab.
31
     */
32
    public function add_tab(admin_settingpage $tab) {
33
        foreach ($tab->settings as $setting) {
34
            $this->settings->{$setting->name} = $setting;
35
        }
36
        $this->tabs[] = $tab;
37
        return true;
38
    }
39
 
40
    public function add($tab) {
41
        return $this->add_tab($tab);
42
    }
43
 
44
    /**
45
     * Get tabs.
46
     *
47
     * @return array
48
     */
49
    public function get_tabs() {
50
        return $this->tabs;
51
    }
52
 
53
    /**
54
     * Generate the HTML output.
55
     *
56
     * @return string
57
     */
58
    public function output_html() {
59
        global $OUTPUT;
60
 
61
        $activetab = optional_param('activetab', '', PARAM_TEXT);
62
        $context = array('tabs' => array());
63
        $havesetactive = false;
64
 
65
        foreach ($this->get_tabs() as $tab) {
66
            $active = false;
67
 
68
            // Default to first tab it not told otherwise.
69
            if (empty($activetab) && !$havesetactive) {
70
                $active = true;
71
                $havesetactive = true;
72
            } else if ($activetab === $tab->name) {
73
                $active = true;
74
            }
75
 
76
            $context['tabs'][] = array(
77
                'name' => $tab->name,
78
                'displayname' => $tab->visiblename,
79
                'html' => $tab->output_html(),
80
                'active' => $active,
81
            );
82
        }
83
 
84
        if (empty($context['tabs'])) {
85
            return '';
86
        }
87
 
88
        return $OUTPUT->render_from_template('theme_monocolor/admin_setting_tabs', $context);
89
    }
90
}