Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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