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 type carousel.
|
|
|
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 |
defined('MOODLE_INTERNAL') || die;
|
|
|
29 |
require_once($CFG->libdir . '/adminlib.php');
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* Content type definition.
|
|
|
33 |
* @package mod_unilabel
|
|
|
34 |
* @author Andreas Grabs <info@grabs-edv.de>
|
|
|
35 |
* @copyright 2018 onwards Grabs EDV {@link https://www.grabs-edv.de}
|
|
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
37 |
*/
|
|
|
38 |
class setting_configselect_button extends \admin_setting {
|
|
|
39 |
/**
|
|
|
40 |
* Options used in select box and also in css templates.
|
|
|
41 |
*
|
|
|
42 |
* @var array
|
|
|
43 |
*/
|
|
|
44 |
private $options;
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* List of css codes for fontawesome.
|
|
|
48 |
*
|
|
|
49 |
* @var array
|
|
|
50 |
*/
|
|
|
51 |
public $buttonlist = [];
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Constructor.
|
|
|
55 |
* @param string $name unique ascii name
|
|
|
56 |
* @param string $visiblename localised
|
|
|
57 |
* @param string $description long localised info
|
|
|
58 |
* @param string $defaultsetting
|
|
|
59 |
* @return void
|
|
|
60 |
*/
|
|
|
61 |
public function __construct($name, $visiblename, $description, $defaultsetting) {
|
|
|
62 |
$this->buttonlist = static::get_font_buttons();
|
|
|
63 |
$this->options = [0 => 0];
|
|
|
64 |
foreach ($this->buttonlist as $key => $btn) {
|
|
|
65 |
$this->options[$key] = $btn['next'];
|
|
|
66 |
}
|
|
|
67 |
parent::__construct($name, $visiblename, $description, $defaultsetting);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Retrieves the current setting using the objects name.
|
|
|
72 |
*
|
|
|
73 |
* @return string
|
|
|
74 |
*/
|
|
|
75 |
public function get_setting() {
|
|
|
76 |
return $this->config_read($this->name);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* Sets the value for the setting.
|
|
|
81 |
*
|
|
|
82 |
* Sets the value for the setting to either the yes or no values
|
|
|
83 |
* of the object by comparing $data to yes
|
|
|
84 |
*
|
|
|
85 |
* @param mixed $data Gets converted to str for comparison against yes value
|
|
|
86 |
* @return string empty string or error
|
|
|
87 |
*/
|
|
|
88 |
public function write_setting($data) {
|
|
|
89 |
if (empty($data)) {
|
|
|
90 |
$data = 0;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
return $this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin');
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Returns an XHTML checkbox field.
|
|
|
98 |
*
|
|
|
99 |
* @param string $data If $data matches yes then checkbox is checked
|
|
|
100 |
* @param string $query
|
|
|
101 |
* @return string XHTML field
|
|
|
102 |
*/
|
|
|
103 |
public function output_html($data, $query = '') {
|
|
|
104 |
global $OUTPUT;
|
|
|
105 |
|
|
|
106 |
$default = $this->get_defaultsetting();
|
|
|
107 |
// Get the string for default setting.
|
|
|
108 |
$defaultinfo = $default;
|
|
|
109 |
if (empty($default)) {
|
|
|
110 |
$defaultinfo = get_string('theme');
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
$values = [];
|
|
|
114 |
$currenttitle = get_string('choose');
|
|
|
115 |
foreach ($this->options as $key => $id) {
|
|
|
116 |
$value = new \stdClass();
|
|
|
117 |
$value->value = $key;
|
|
|
118 |
$value->title = $id;
|
|
|
119 |
if ($value->value == $data) {
|
|
|
120 |
$value->checked = 'checked';
|
|
|
121 |
$currentvalue = $value->value;
|
|
|
122 |
}
|
|
|
123 |
if ($key == 0) {
|
|
|
124 |
$value->title = $defaultinfo;
|
|
|
125 |
$value->istext = 1;
|
|
|
126 |
}
|
|
|
127 |
$values[] = $value;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
$context = (object) [
|
|
|
131 |
'id' => $this->get_id(),
|
|
|
132 |
'name' => $this->get_full_name(),
|
|
|
133 |
'values' => $values,
|
|
|
134 |
'currentvalue' => $this->options[$currentvalue],
|
|
|
135 |
];
|
|
|
136 |
if ($currentvalue == 0) {
|
|
|
137 |
$context->currentvalue = $defaultinfo;
|
|
|
138 |
$context->currentvalueistext = 1;
|
|
|
139 |
}
|
|
|
140 |
|
|
|
141 |
// To make sure we have clean html we have to put the carousel css into the <head> by using javascript.
|
|
|
142 |
$cssstring = $OUTPUT->render_from_template('mod_unilabel/setting_configselect_style', $context);
|
|
|
143 |
$context->cssjsonstring = json_encode($cssstring);
|
|
|
144 |
|
|
|
145 |
$element = $OUTPUT->render_from_template('mod_unilabel/setting_configselect', $context);
|
|
|
146 |
|
|
|
147 |
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
/**
|
|
|
151 |
* Get an array with a font awesome button definition. Depending on the Moodle
|
|
|
152 |
* version it returns font awesome 4.7 or 6.0 free.
|
|
|
153 |
*
|
|
|
154 |
* @return array
|
|
|
155 |
*/
|
|
|
156 |
public static function get_font_buttons() {
|
|
|
157 |
// Since Moodle 4.2 the new FontAwesome 6 is used.
|
|
|
158 |
if (version_compare(moodle_major_version(), '4.2', '<')) {
|
|
|
159 |
// The current Moodle version is less then 4.2. So we load the fontawesome 4.7 items.
|
|
|
160 |
return [
|
|
|
161 |
'1' => ['next' => 'fa fa-angle-right fa-xl', 'prev' => 'fa fa-angle-left fa-xl'],
|
|
|
162 |
'2' => ['next' => 'fa fa-angle-double-right fa-xl', 'prev' => 'fa fa-angle-double-left fa-xl'],
|
|
|
163 |
'3' => ['next' => 'fa fa-forward fa-xl', 'prev' => 'fa fa-backward fa-xl'],
|
|
|
164 |
'4' => ['next' => 'fa fa-caret-right fa-xl', 'prev' => 'fa fa-caret-left fa-xl'],
|
|
|
165 |
'5' => ['next' => 'fa fa-hand-o-right fa-xl', 'prev' => 'fa fa-hand-o-left fa-xl'],
|
|
|
166 |
'6' => ['next' => 'fa fa-arrow-right fa-xl', 'prev' => 'fa fa-arrow-left fa-xl'],
|
|
|
167 |
'7' => ['next' => 'fa fa-arrow-circle-right fa-xl', 'prev' => 'fa fa-arrow-circle-left fa-xl'],
|
|
|
168 |
'8' => ['next' => 'fa fa-arrow-circle-o-right fa-xl', 'prev' => 'fa fa-arrow-circle-o-left fa-xl'],
|
|
|
169 |
];
|
|
|
170 |
} else {
|
|
|
171 |
// The current Moodle version is 4.2 or later. So we load the fontawesome 6 items.
|
|
|
172 |
return [
|
|
|
173 |
'1' => ['next' => 'fa fa-solid fa-angle-right fa-xl', 'prev' => 'fa fa-solid fa-angle-left fa-xl'],
|
|
|
174 |
'2' => ['next' => 'fa fa-solid fa-angles-right fa-xl', 'prev' => 'fa fa-solid fa-angles-left fa-xl'],
|
|
|
175 |
'3' => ['next' => 'fa fa-solid fa-forward', 'prev' => 'fa fa-solid fa-backward'],
|
|
|
176 |
'4' => ['next' => 'fa fa-solid fa-caret-right fa-xl', 'prev' => 'fa fa-solid fa-caret-left fa-xl'],
|
|
|
177 |
'5' => ['next' => 'fa fa-regular fa-hand-point-right', 'prev' => 'fa fa-regular fa-hand-point-left'],
|
|
|
178 |
'6' => ['next' => 'fa fa-solid fa-arrow-right fa-xl', 'prev' => 'fa fa-solid fa-arrow-left fa-xl'],
|
|
|
179 |
'7' => ['next' => 'fa fa-regular fa-circle-right', 'prev' => 'fa fa-regular fa-circle-left'],
|
|
|
180 |
'8' => ['next' => 'fa fa-solid fa-circle-arrow-right', 'prev' => 'fa fa-solid fa-circle-arrow-left'],
|
|
|
181 |
];
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
}
|
|
|
185 |
}
|