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 |
* Form for editing Dash block instances.
|
|
|
19 |
*
|
|
|
20 |
* @package block_dash
|
|
|
21 |
* @copyright 2019 bdecent gmbh <https://bdecent.de>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
use block_dash\local\data_source\data_source_factory;
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Form for editing Dash block instances.
|
|
|
31 |
*
|
|
|
32 |
* @package block_dash
|
|
|
33 |
* @copyright 2019 bdecent gmbh <https://bdecent.de>
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class block_dash_edit_form extends block_edit_form {
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Add form fields.
|
|
|
40 |
*
|
|
|
41 |
* @param MoodleQuickForm $mform
|
|
|
42 |
* @throws coding_exception
|
|
|
43 |
*/
|
|
|
44 |
protected function specific_definition($mform) {
|
|
|
45 |
global $CFG;
|
|
|
46 |
// Fields for editing HTML block title and contents.
|
|
|
47 |
$mform->addElement('header', 'dashconfigheader', get_string('blocksettings', 'block'));
|
|
|
48 |
|
|
|
49 |
$mform->addElement('text', 'config_title', get_string('blocktitle', 'block_dash'));
|
|
|
50 |
$mform->setType('config_title', PARAM_TEXT);
|
|
|
51 |
|
|
|
52 |
$this->add_datasource_group($mform, $this->block->config);
|
|
|
53 |
|
|
|
54 |
$mform->addElement('header', 'headerfooter', get_string('headerfooter', 'block_dash'));
|
|
|
55 |
|
|
|
56 |
$mform->addElement('editor', 'config_header_content', get_string('headercontent', 'block_dash'));
|
|
|
57 |
$mform->setType('config_header_content', PARAM_RAW);
|
|
|
58 |
$mform->addHelpButton('config_header_content', 'headercontent', 'block_dash');
|
|
|
59 |
|
|
|
60 |
$mform->addElement('editor', 'config_footer_content', get_string('footercontent', 'block_dash'));
|
|
|
61 |
$mform->setType('config_footer_content', PARAM_RAW);
|
|
|
62 |
$mform->addHelpButton('config_footer_content', 'footercontent', 'block_dash');
|
|
|
63 |
|
|
|
64 |
$mform->addElement('header', 'apperance', get_string('appearance'));
|
|
|
65 |
|
|
|
66 |
$mform->addElement('select', 'config_showheader', get_string('showheader', 'block_dash'), [
|
|
|
67 |
|
|
|
68 |
1 => get_string('visible'),
|
|
|
69 |
]);
|
|
|
70 |
$mform->setType('config_showheader', PARAM_INT);
|
|
|
71 |
$mform->setDefault('config_showheader', get_config('block_dash', 'showheader'));
|
|
|
72 |
$mform->addHelpButton('config_showheader', 'showheader', 'block_dash');
|
|
|
73 |
|
|
|
74 |
$mform->addElement('select', 'config_width', get_string('blockwidth', 'block_dash'), [
|
|
|
75 |
100 => '100',
|
|
|
76 |
50 => '1/2',
|
|
|
77 |
33 => '1/3',
|
|
|
78 |
66 => '2/3',
|
|
|
79 |
25 => '1/4',
|
|
|
80 |
20 => '1/5',
|
|
|
81 |
16 => '1/6',
|
|
|
82 |
]);
|
|
|
83 |
$mform->setType('config_width', PARAM_INT);
|
|
|
84 |
$mform->setDefault('config_width', 100);
|
|
|
85 |
|
|
|
86 |
$mform->addElement('select', 'config_hide_when_empty', get_string('hidewhenempty', 'block_dash'), [
|
|
|
87 |
|
|
|
88 |
1 => get_string('yes'),
|
|
|
89 |
]);
|
|
|
90 |
|
|
|
91 |
$mform->setType('config_hide_when_empty', PARAM_INT);
|
|
|
92 |
$mform->setDefault('config_hide_when_empty', get_config('block_dash', 'hide_when_empty'));
|
|
|
93 |
|
|
|
94 |
$attributes['tags'] = true;
|
|
|
95 |
$attributes['multiple'] = 'multiple';
|
|
|
96 |
$attributes['placeholder'] = get_string('enterclasses', 'block_dash');
|
|
|
97 |
|
|
|
98 |
$cssclassses = explode(',', get_config('block_dash', 'cssclass'));
|
|
|
99 |
$cssclassses = array_combine($cssclassses, $cssclassses);
|
|
|
100 |
$mform->addElement('autocomplete', 'config_css_class', get_string('cssclass', 'block_dash'), $cssclassses, $attributes);
|
|
|
101 |
$mform->setType('config_css_class', PARAM_TEXT);
|
|
|
102 |
$mform->addHelpButton('config_css_class', 'cssclass', 'block_dash');
|
|
|
103 |
|
|
|
104 |
$mform->addElement('filemanager', 'config_backgroundimage', get_string('backgroundimage', 'block_dash'), null,
|
|
|
105 |
['subdirs' => 0, 'maxfiles' => 1, 'accepted_types' => ['image'], 'return_types' => FILE_INTERNAL | FILE_EXTERNAL]);
|
|
|
106 |
$mform->addHelpButton('config_backgroundimage', 'backgroundimage', 'block_dash');
|
|
|
107 |
|
|
|
108 |
$postions = [
|
|
|
109 |
'initial' => get_string('initial', 'block_dash'),
|
|
|
110 |
'left top' => get_string('lefttop', 'block_dash'),
|
|
|
111 |
'left center' => get_string('leftcenter', 'block_dash'),
|
|
|
112 |
'left bottom' => get_string('leftbottom', 'block_dash'),
|
|
|
113 |
'right top' => get_string('righttop', 'block_dash'),
|
|
|
114 |
'right center' => get_string('rightcenter', 'block_dash'),
|
|
|
115 |
'right bottom' => get_string('rightbottom', 'block_dash'),
|
|
|
116 |
'center top' => get_string('centertop', 'block_dash'),
|
|
|
117 |
'center center' => get_string('centercenter', 'block_dash'),
|
|
|
118 |
'center bottom' => get_string('centerbottom', 'block_dash'),
|
|
|
119 |
'custom' => get_string('strcustom', 'block_dash'),
|
|
|
120 |
];
|
|
|
121 |
// Module background image poisiton.
|
|
|
122 |
$mform->addElement('select', 'config_backgroundimage_position', get_string('backgroundposition', 'block_dash'),
|
|
|
123 |
$postions);
|
|
|
124 |
$mform->setType('config_backgroundimage_position', PARAM_RAW);
|
|
|
125 |
$mform->addHelpButton('config_backgroundimage_position', 'backgroundposition', 'block_dash');
|
|
|
126 |
|
|
|
127 |
// Module background image custom poisiton.
|
|
|
128 |
$mform->addElement('text', 'config_backgroundimage_customposition',
|
|
|
129 |
get_string('designercustombgposition', 'block_dash'));
|
|
|
130 |
$mform->setType('config_backgroundimage_customposition', PARAM_RAW);
|
|
|
131 |
$mform->addHelpButton('config_backgroundimage_customposition', 'backgroundposition', 'block_dash');
|
|
|
132 |
$mform->hideIf('config_backgroundimage_customposition', 'config_backgroundimage_position', 'neq', 'custom');
|
|
|
133 |
|
|
|
134 |
// Module background image size.
|
|
|
135 |
$sizes = [
|
|
|
136 |
'auto' => get_string('auto', 'block_dash'),
|
|
|
137 |
'cover' => get_string('cover', 'block_dash'),
|
|
|
138 |
'contain' => get_string('contain', 'block_dash'),
|
|
|
139 |
'custom' => get_string('strcustom', 'block_dash'),
|
|
|
140 |
];
|
|
|
141 |
$mform->addElement('select', 'config_backgroundimage_size', get_string('backgroundsize',
|
|
|
142 |
'block_dash'), $sizes);
|
|
|
143 |
$mform->setType('config_backgroundimage_size', PARAM_RAW);
|
|
|
144 |
$mform->addHelpButton('config_backgroundimage_size', 'backgroundsize', 'block_dash');
|
|
|
145 |
|
|
|
146 |
// Module background image custom size.
|
|
|
147 |
$mform->addElement('text', 'config_backgroundimage_customsize', get_string('designercustombgsize', 'block_dash'));
|
|
|
148 |
$mform->setType('config_backgroundimage_customsize', PARAM_RAW);
|
|
|
149 |
$mform->addHelpButton('config_backgroundimage_customsize', 'backgroundsize', 'block_dash');
|
|
|
150 |
$mform->hideIf('config_backgroundimage_customsize', 'config_backgroundimage_size', 'neq', 'custom');
|
|
|
151 |
|
|
|
152 |
require_once($CFG->dirroot.'/blocks/dash/form/gradientpicker.php');
|
|
|
153 |
MoodleQuickForm::registerElementType('dashgradientpicker', $CFG->dirroot.'/blocks/dash/form/gradientpicker.php',
|
|
|
154 |
'moodlequickform_dashgradientpicker');
|
|
|
155 |
|
|
|
156 |
$mform->addElement('dashgradientpicker', 'config_backgroundgradient', get_string('backgroundgradient', 'block_dash'),
|
|
|
157 |
['placeholder' => 'linear-gradient(#e66465, #9198e5)']);
|
|
|
158 |
$mform->setType('config_backgroundgradient', PARAM_TEXT);
|
|
|
159 |
$mform->addHelpButton('config_backgroundgradient', 'backgroundgradient', 'block_dash');
|
|
|
160 |
|
|
|
161 |
require_once($CFG->dirroot.'/blocks/dash/form/element-colorpicker.php');
|
|
|
162 |
MoodleQuickForm::registerElementType('dashcolorpicker', $CFG->dirroot.'/blocks/dash/form/element-colorpicker.php',
|
|
|
163 |
'moodlequickform_dashcolorpicker');
|
|
|
164 |
|
|
|
165 |
$mform->addElement('dashcolorpicker', 'config_headerfootercolor', get_string('fontcolor', 'block_dash'));
|
|
|
166 |
$mform->setType('config_headerfootercolor', PARAM_RAW);
|
|
|
167 |
$mform->addHelpButton('config_headerfootercolor', 'fontcolor', 'block_dash');
|
|
|
168 |
|
|
|
169 |
$mform->addElement('select', 'config_border_option', get_string('border_option', 'block_dash'), [
|
|
|
170 |
|
|
|
171 |
1 => get_string('visible'),
|
|
|
172 |
]);
|
|
|
173 |
$mform->setType('config_border_option', PARAM_INT);
|
|
|
174 |
$mform->setDefault('config_border_option', 1);
|
|
|
175 |
$mform->addHelpButton('config_border_option', 'border_option', 'block_dash');
|
|
|
176 |
|
|
|
177 |
$mform->addElement('text', 'config_border', get_string('bordervalue', 'block_dash'));
|
|
|
178 |
$mform->setType('config_border', PARAM_TEXT);
|
|
|
179 |
$mform->addHelpButton('config_border', 'border', 'block_dash');
|
|
|
180 |
$mform->hideIf('config_border', 'config_border_option', 'eq', 0);
|
|
|
181 |
|
|
|
182 |
$mform->addElement('text', 'config_css[min-height]', get_string('minheight', 'block_dash'));
|
|
|
183 |
$mform->setType('config_css[min-height]', PARAM_TEXT);
|
|
|
184 |
$mform->addHelpButton('config_css[min-height]', 'minheight', 'block_dash');
|
|
|
185 |
|
|
|
186 |
$mform->addElement('header', 'emptystateheading', get_string('emptystateheading', 'block_dash'));
|
|
|
187 |
|
|
|
188 |
$mform->addElement('editor', 'config_emptystate', get_string('content'), ['rows' => 5]);
|
|
|
189 |
$mform->setType('config_emptystate', PARAM_CLEANHTML);
|
|
|
190 |
|
|
|
191 |
$widgetlist = data_source_factory::get_data_source_form_options('widget');
|
|
|
192 |
foreach ($widgetlist as $id => $source) {
|
|
|
193 |
if (method_exists($id, 'extend_config_form')) {
|
|
|
194 |
$id::extend_config_form($mform, $source, $this);
|
|
|
195 |
$showcustom = true;
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* Add available data source groups.
|
|
|
202 |
*
|
|
|
203 |
* @param moodleform $mform
|
|
|
204 |
* @param stdclass $config
|
|
|
205 |
* @return void
|
|
|
206 |
*/
|
|
|
207 |
public function add_datasource_group(&$mform, $config) {
|
|
|
208 |
global $OUTPUT;
|
|
|
209 |
|
|
|
210 |
$label[] = $mform->createElement('html', html_writer::start_div('datasource-content heading'));
|
|
|
211 |
$label[] = $mform->createElement('html', html_writer::end_div());
|
|
|
212 |
|
|
|
213 |
$mform->addGroup($label, 'datasources_label', get_string('choosefeature', 'block_dash'), [' '], false);
|
|
|
214 |
$mform->setType('datasources_label', PARAM_TEXT);
|
|
|
215 |
|
|
|
216 |
if (!isset($config->data_source_idnumber)) {
|
|
|
217 |
|
|
|
218 |
self::dash_features_list($mform, $this->block->context, $this->page);
|
|
|
219 |
$mform->addElement('hidden', 'config_dash_configure_options', 1);
|
|
|
220 |
$mform->setType('config_dash_configure_options', PARAM_INT);
|
|
|
221 |
|
|
|
222 |
} else {
|
|
|
223 |
if ($ds = data_source_factory::build_data_source($config->data_source_idnumber,
|
|
|
224 |
$this->block->context)) {
|
|
|
225 |
$label = $ds->get_name();
|
|
|
226 |
} else {
|
|
|
227 |
$label = get_string('datasourcemissing', 'block_dash');
|
|
|
228 |
}
|
|
|
229 |
$datalabel = ($ds && $ds->is_widget())
|
|
|
230 |
? get_string('widget', 'block_dash') : get_string('datasource', 'block_dash');
|
|
|
231 |
|
|
|
232 |
$mform->addElement('static', 'data_source_label', $datalabel.' : ', $label);
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
/**
|
|
|
237 |
* Data features list.
|
|
|
238 |
*
|
|
|
239 |
* @param \moodleform $mform
|
|
|
240 |
* @param \context $context
|
|
|
241 |
* @param \moodle_page $page
|
|
|
242 |
* @return void
|
|
|
243 |
*/
|
|
|
244 |
public static function dash_features_list(&$mform, $context, $page) {
|
|
|
245 |
global $OUTPUT;
|
|
|
246 |
// Group of datasources.
|
|
|
247 |
if (has_capability('block/dash:managedatasource', $context)) {
|
|
|
248 |
$datasources = data_source_factory::get_data_source_form_options();
|
|
|
249 |
// Description of the datasources.
|
|
|
250 |
$group[] = $mform->createElement('html',
|
|
|
251 |
html_writer::tag('p', get_string('datasourcedesc', 'block_dash'), ['class' => 'dash-source-desc']));
|
|
|
252 |
|
|
|
253 |
$group[] = $mform->createElement('html', html_writer::start_div('datasource-content'));
|
|
|
254 |
foreach ($datasources as $id => $source) {
|
|
|
255 |
if (block_dash_visible_addons($id)) {
|
|
|
256 |
$group[] = $mform->createElement('html', html_writer::start_div('datasource-item'));
|
|
|
257 |
$group[] = $mform->createElement('radio', 'config_data_source_idnumber', '', $source['name'], $id);
|
|
|
258 |
if ($help = $source['help']) {
|
|
|
259 |
$helpcontent = $OUTPUT->help_icon($help['name'], $help['component'], $help['name']);
|
|
|
260 |
$group[] = $mform->createElement('html', $helpcontent);
|
|
|
261 |
}
|
|
|
262 |
$group[] = $mform->createElement('html', html_writer::end_div());
|
|
|
263 |
}
|
|
|
264 |
}
|
|
|
265 |
$group[] = $mform->createElement('html', html_writer::end_div());
|
|
|
266 |
$mform->addGroup($group, 'datasources', get_string('buildown', 'block_dash'), [' '], false);
|
|
|
267 |
$mform->setType('datasources', PARAM_TEXT);
|
|
|
268 |
$mform->addHelpButton('datasources', 'buildown', 'block_dash');
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
// Widgets data source.
|
|
|
272 |
if (has_capability('block/dash:managewidget', $context)) {
|
|
|
273 |
$widgetlist = data_source_factory::get_data_source_form_options('widget');
|
|
|
274 |
$widgets[] = $mform->createElement('html',
|
|
|
275 |
html_writer::tag('p', get_string('widgetsdesc', 'block_dash'), ['class' => 'dash-source-desc']));
|
|
|
276 |
$widgets[] = $mform->createElement('html', html_writer::start_div('datasource-content'));
|
|
|
277 |
foreach ($widgetlist as $id => $source) {
|
|
|
278 |
if (block_dash_visible_addons($id)) {
|
|
|
279 |
$widgets[] = $mform->createElement('html', html_writer::start_div('datasource-item'));
|
|
|
280 |
$widgets[] = $mform->createElement('radio', 'config_data_source_idnumber', '', $source['name'], $id);
|
|
|
281 |
if ($source['help']) {
|
|
|
282 |
$widgets[] = $mform->createElement('html', $OUTPUT->help_icon($source['help'], 'block_dash',
|
|
|
283 |
$source['help']));
|
|
|
284 |
}
|
|
|
285 |
$widgets[] = $mform->createElement('html', html_writer::end_div());
|
|
|
286 |
}
|
|
|
287 |
}
|
|
|
288 |
$widgets[] = $mform->createElement('html', html_writer::end_div());
|
|
|
289 |
$mform->addGroup($widgets, 'widgets', get_string('readymatewidgets', 'block_dash'), [' '], false);
|
|
|
290 |
$mform->setType('widgets', PARAM_TEXT);
|
|
|
291 |
$mform->addHelpButton('widgets', 'readymatewidgets', 'block_dash');
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
// Content layout.
|
|
|
295 |
$customfeatures = data_source_factory::get_data_source_form_options('custom');
|
|
|
296 |
if ($customfeatures) {
|
|
|
297 |
foreach ($customfeatures as $id => $source) {
|
|
|
298 |
if ($id::has_capbility($context)) {
|
|
|
299 |
$id::get_features_config($mform, $source);
|
|
|
300 |
$showcustom = true;
|
|
|
301 |
}
|
|
|
302 |
}
|
|
|
303 |
if (isset($showcustom)) {
|
|
|
304 |
|
|
|
305 |
$page->requires->js_amd_inline('require(["jquery"], function($) {
|
|
|
306 |
$("body").on("change", "[data-target=\"subsource-config\"] [type=radio]", function(e) {
|
|
|
307 |
var subConfig;
|
|
|
308 |
if (subConfig = e.target.closest("[data-target=\"subsource-config\"]")) {
|
|
|
309 |
if (subConfig.parentNode !== null) {
|
|
|
310 |
var dataSource = subConfig.parentNode.querySelector("[name=\"config_data_source_idnumber\"]");
|
|
|
311 |
dataSource.click(); // = true;
|
|
|
312 |
}
|
|
|
313 |
}
|
|
|
314 |
});
|
|
|
315 |
})'
|
|
|
316 |
);
|
|
|
317 |
}
|
|
|
318 |
}
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
/**
|
|
|
322 |
* Display the configuration form when block is being added to the page
|
|
|
323 |
*
|
|
|
324 |
* @return bool
|
|
|
325 |
*/
|
|
|
326 |
public static function display_form_when_adding(): bool {
|
|
|
327 |
return false;
|
|
|
328 |
}
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
/**
|
|
|
332 |
* Dash features form to configure the data source or widget.
|
|
|
333 |
*/
|
|
|
334 |
class block_dash_featuresform extends \moodleform {
|
|
|
335 |
|
|
|
336 |
/**
|
|
|
337 |
* Defined the form fields for the datasource selector list.
|
|
|
338 |
*
|
|
|
339 |
* @return void
|
|
|
340 |
*/
|
|
|
341 |
public function definition() {
|
|
|
342 |
// @codingStandardsIgnoreStart
|
|
|
343 |
global $PAGE;
|
|
|
344 |
// Ignore the phplint due to block class not allowed to include the PAGE global variable.
|
|
|
345 |
// @codingStandardsIgnoreEnd
|
|
|
346 |
|
|
|
347 |
$mform = $this->_form;
|
|
|
348 |
|
|
|
349 |
$mform->updateAttributes(['class' => 'form-inline']);
|
|
|
350 |
$mform->updateAttributes(['id' => 'dash-configuration']);
|
|
|
351 |
|
|
|
352 |
$block = $this->_customdata['block'] ?? '';
|
|
|
353 |
// @codingStandardsIgnoreStart
|
|
|
354 |
// Ignore the phplint due to block class not allowed to include the PAGE global variable.
|
|
|
355 |
block_dash_edit_form::dash_features_list($mform, $block, $PAGE);
|
|
|
356 |
// @codingStandardsIgnoreEnd
|
|
|
357 |
}
|
|
|
358 |
}
|