| 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 |
* unilabel module.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_unilabel
|
|
|
21 |
* @author Andreas Grabs <info@grabs-edv.de>
|
|
|
22 |
* @copyright 2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace mod_unilabel;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Settings page providing a tabbed view.
|
|
|
30 |
* @package mod_unilabel
|
|
|
31 |
* @author Andreas Grabs <info@grabs-edv.de>
|
|
|
32 |
* @copyright 2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class admin_settingspage_tabs extends \admin_settingpage {
|
|
|
36 |
/** @var array The tabs of this page */
|
|
|
37 |
protected $tabs = [];
|
|
|
38 |
/** @var string The description of this page */
|
|
|
39 |
private $description = '';
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Add a tab.
|
|
|
43 |
*
|
|
|
44 |
* @param admin_settingpage $tab a tab
|
|
|
45 |
* @return bool
|
|
|
46 |
*/
|
|
|
47 |
public function add_tab(\admin_settingpage $tab) {
|
|
|
48 |
foreach ($tab->settings as $setting) {
|
|
|
49 |
$this->settings->{$setting->plugin . $setting->name} = $setting;
|
|
|
50 |
}
|
|
|
51 |
$this->tabs[] = $tab;
|
|
|
52 |
|
|
|
53 |
return true;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Add a setting page as new tab.
|
|
|
58 |
*
|
|
|
59 |
* @param \admin_settingpage $tab
|
|
|
60 |
* @return bool
|
|
|
61 |
*/
|
|
|
62 |
public function add($tab) {
|
|
|
63 |
return $this->add_tab($tab);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Set a description of this setting page.
|
|
|
68 |
*
|
|
|
69 |
* @param string $description
|
|
|
70 |
* @return void
|
|
|
71 |
*/
|
|
|
72 |
public function set_description($description) {
|
|
|
73 |
$this->description = $description;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* Get tabs.
|
|
|
78 |
*
|
|
|
79 |
* @return array
|
|
|
80 |
*/
|
|
|
81 |
public function get_tabs() {
|
|
|
82 |
return $this->tabs;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
/**
|
|
|
86 |
* Generate the HTML output.
|
|
|
87 |
*
|
|
|
88 |
* @return string
|
|
|
89 |
*/
|
|
|
90 |
public function output_html() {
|
|
|
91 |
global $OUTPUT;
|
|
|
92 |
|
|
|
93 |
$activetab = optional_param('activetab', '', PARAM_TEXT);
|
|
|
94 |
$context = ['tabs' => []];
|
|
|
95 |
$havesetactive = false;
|
|
|
96 |
|
|
|
97 |
foreach ($this->get_tabs() as $tab) {
|
|
|
98 |
$active = false;
|
|
|
99 |
|
|
|
100 |
// Default to first tab it not told otherwise.
|
|
|
101 |
if (empty($activetab) && !$havesetactive) {
|
|
|
102 |
$active = true;
|
|
|
103 |
$havesetactive = true;
|
|
|
104 |
} else if ($activetab === $tab->name) {
|
|
|
105 |
$active = true;
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
$context['tabs'][] = [
|
|
|
109 |
'name' => $tab->name,
|
|
|
110 |
'displayname' => $tab->visiblename,
|
|
|
111 |
'html' => $tab->output_html(),
|
|
|
112 |
'active' => $active,
|
|
|
113 |
];
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
if (!empty($context['tabs'])) {
|
|
|
117 |
$context['hastabs'] = true;
|
|
|
118 |
}
|
|
|
119 |
$context['description'] = $this->description;
|
|
|
120 |
|
|
|
121 |
return $OUTPUT->render_from_template('mod_unilabel/admin_setting_tabs', $context);
|
|
|
122 |
}
|
|
|
123 |
}
|