-
Notifications
You must be signed in to change notification settings - Fork 33
/
simple_theme_settings.class.php
156 lines (142 loc) · 5.52 KB
/
simple_theme_settings.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
// This file is part of The Bootstrap 3 Moodle theme
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* A wrapper round Moodle's settings API to simplify the common cases
* for themers, often via "convention over configuration" and the reduction
* in repetitive typing
*
* Assumes all strings are in the theme lang file, assumes the title
* langstring is the same as the name, and that the description langstring
* is the same as the title with 'desc' added to the end.
*
* @package theme_bootstrap
* @copyright 2014 Bas Brands, www.basbrands.nl
* @authors Bas Brands, David Scotson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
class simple_theme_settings {
private $themename;
private $settingspage;
public function __construct($settingspage, $themename) {
$this->themename = $themename;
$this->settingspage = $settingspage;
}
private function name_for($setting, $suffix='') {
return $this->themename.'/'.$setting.$suffix;
}
private function title_for($setting, $additional = null) {
return get_string($setting, $this->themename, $additional);
}
private function description_for($setting) {
return get_string($setting.'desc', $this->themename);
}
public function add_checkbox($setting, $default='0', $checked='1', $unchecked='0') {
$checkbox = new admin_setting_configcheckbox(
$this->name_for($setting),
$this->title_for($setting),
$this->description_for($setting),
$default,
$checked,
$unchecked
);
$checkbox->set_updatedcallback('theme_reset_all_caches');
$this->settingspage->add($checkbox);
}
public function add_text($setting, $default='') {
$text = new admin_setting_configtext(
$this->name_for($setting),
$this->title_for($setting),
$this->description_for($setting),
$default
);
$text->set_updatedcallback('theme_reset_all_caches');
$this->settingspage->add($text);
}
public function add_heading($setting) {
$heading = new admin_setting_heading(
$this->name_for($setting),
$this->title_for($setting),
$this->description_for($setting)
);
$this->settingspage->add($heading);
}
public function add_select($setting, $default, $options) {
$select = new admin_setting_configselect(
$this->name_for($setting),
$this->title_for($setting),
$this->description_for($setting),
$default,
$options
);
$select->set_updatedcallback('theme_reset_all_caches');
$this->settingspage->add($select);
}
public function add_textarea($setting, $default='') {
$textarea = new admin_setting_configtextarea(
$this->name_for($setting),
$this->title_for($setting),
$this->description_for($setting),
$default
);
$textarea->set_updatedcallback('theme_reset_all_caches');
$this->settingspage->add($textarea);
}
public function add_htmleditor($setting, $default='') {
$htmleditor = new admin_setting_confightmleditor(
$this->name_for($setting),
$this->title_for($setting),
$this->description_for($setting),
$default
);
$htmleditor->set_updatedcallback('theme_reset_all_caches');
$this->settingspage->add($htmleditor);
}
public function add_colourpicker($setting, $default='#666') {
$colorpicker = new admin_setting_configcolourpicker(
$this->name_for($setting),
$this->title_for($setting),
$this->description_for($setting),
$default,
null // Don't hook up any javascript preview of color change.
);
$colorpicker->set_updatedcallback('theme_reset_all_caches');
$this->settingspage->add($colorpicker);
}
public function add_file($setting) {
$file = new admin_setting_configstoredfile(
$this->name_for($setting),
$this->title_for($setting),
$this->description_for($setting),
$setting // TODO find out what this does,
// for now assume it just needs to be unique.
);
$file->set_updatedcallback('theme_reset_all_caches');
$this->settingspage->add($file);
}
public function add_numbered_textareas($setting, $count, $default='') {
for ($i = 1; $i <= $count; $i++) {
$textarea = new admin_setting_configtextarea(
$this->name_for($setting, $i),
$this->title_for($setting, $i),
$this->description_for($setting),
$default
);
$textarea->set_updatedcallback('theme_reset_all_caches');
$this->settingspage->add($textarea);
}
}
}