24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 | */
26 |
27 | defined('MOODLE_INTERNAL') || die();
28 |
29 | abstract class admin_preset_setting {
30 |
31 | /**
32 | * @var admin_setting
33 | */
34 | protected $settingdata;
35 |
36 | /**
37 | * @var admin_presets_delegation
38 | */
39 | protected $delegation;
40 |
41 | /**
42 | * The setting DB value
43 | *
44 | * @var mixed
45 | */
46 | protected $value;
47 |
48 | /**
49 | * Stores the visible value of the setting DB value
50 | *
51 | * @var string
52 | */
53 | protected $visiblevalue;
54 |
55 | /**
56 | * Text to display on the TreeView
57 | *
58 | * @var string
59 | */
60 | protected $text;
61 |
62 | /**
63 | * For multiple value settings, used to look for the other values
64 | *
65 | * @var string
66 | */
67 | protected $attributes = false;
68 |
69 | /**
70 | * To store the setting attributes
71 | *
72 | * @var array
73 | */
74 | protected $attributesvalues;
75 |
76 | /**
77 | * Stores the setting data and the selected value
78 | *
79 | * @param admin_setting $settingdata admin_setting subclass
80 | * @param mixed $dbsettingvalue Actual value
81 | */
82 | public function __construct(admin_setting $settingdata, $dbsettingvalue) {
83 |
84 | $this->settingdata = $settingdata;
85 | $this->delegation = new admin_presets_delegation();
86 |
87 | if ($this->settingdata->plugin == '') {
88 | $this->settingdata->plugin = 'none';
89 | }
90 |
91 | // Applies specific children behaviors
92 | $this->set_behaviors();
93 | $this->apply_behaviors();
94 |
95 | // Cleaning value.
96 | $this->set_value($dbsettingvalue);
97 | }
98 |
99 | /**
100 | * Each class can overwrite this method to specify extra processes
101 | */
102 | protected function set_behaviors() {
103 | }
104 |
105 | /**
106 | * Applies the children class specific behaviors
107 | *
108 | * See admin_presets_delegation() for the available extra behaviors
109 | */
110 | protected function apply_behaviors() {
111 |
112 | if (!empty($this->behaviors)) {
113 |
114 | foreach ($this->behaviors as $behavior => $arguments) {
115 |
116 | // The arguments of the behavior depends on the caller.
117 | $methodname = 'extra_' . $behavior;
118 | $this->delegation->{$methodname}($arguments);
119 | }
120 | }
121 | }
122 |
123 | /**
124 | * Returns the TreeView node identifier
125 | */
126 | public function get_id() {
127 | return $this->settingdata->name . '@@' . $this->settingdata->plugin;
128 | }
129 |
130 | public function get_value() {
131 | return $this->value;
132 | }
133 |
134 | /**
135 | * Sets the setting value cleaning it
136 | *
137 | * Child classes should overwrite method to clean more acurately
138 | *
139 | * @param mixed $value Setting value
140 | * @return mixed Returns false if wrong param value
141 | */
142 | protected function set_value($value) {
143 | $this->value = $value;
144 | }
145 |
146 | public function get_visiblevalue() {
147 | return $this->visiblevalue;
148 | }
149 |
150 | /**
151 | * Sets the visible name for the setting selected value
152 | *
153 | * In most cases the child classes will overwrite
154 | *
155 | * @return void
156 | */
157 | public function set_visiblevalue(): void {
158 | $this->visiblevalue = $this->value;
159 | }
160 |
161 | public function get_description() {
162 |
163 | // PARAM_TEXT clean because the alt attribute does not support html.
164 | $description = clean_param($this->settingdata->description, PARAM_TEXT);
165 | return $this->encode_string($description);
166 | }
167 |
168 | /**
169 | * Encodes a string to send it to js
170 | *
171 | * @param string $string
172 | * @return string
173 | */
174 | protected function encode_string($string) {
175 |
176 | $encoded = rawurlencode($string);
177 | return $encoded;
178 | }
179 |
180 | public function get_text() {
181 | return $this->encode_string($this->text);
182 | }
183 |
184 | /**
185 | * Sets the text to display on the settings tree
186 | *
187 | * Default format: I'm a setting visible name (setting value: "VALUE")
188 | */
189 | public function set_text() {
190 |
191 | $this->set_visiblevalue();
192 |
193 | $namediv = '' . $this->settingdata->visiblename . '
';
194 | $valuediv = '' . $this->visiblevalue . '
';
195 |
196 | $this->text = $namediv . $valuediv . '
';
197 | }
198 |
199 | public function get_attributes() {
200 | return $this->attributes;
201 | }
202 |
203 | public function get_attributes_values() {
204 | return $this->attributesvalues;
205 | }
206 |
207 | public function get_settingdata() {
208 | return $this->settingdata;
209 | }
210 |
211 | public function set_attribute_value($name, $value) {
212 | $this->attributesvalues[$name] = $value;
213 | }
214 |
215 | /**
216 | * Saves the setting attributes values
217 | *
218 | * @return array Array of inserted ids (in config_log)
219 | */
220 | public function save_attributes_values() {
221 |
222 | // Plugin name or null.
223 | $plugin = $this->settingdata->plugin;
224 | if ($plugin == 'none' || $plugin == '') {
225 | $plugin = null;
226 | }
227 |
228 | if (!$this->attributesvalues) {
229 | return false;
230 | }
231 |
232 | // To store inserted ids.
233 | $ids = array();
234 | foreach ($this->attributesvalues as $name => $value) {
235 |
236 | // Getting actual setting.
237 | $actualsetting = get_config($plugin, $name);
238 |
239 | // If it's the actual setting get off.
240 | if ($value == $actualsetting) {
241 | return false;
242 | }
243 |
244 | if ($id = $this->save_value($name, $value)) {
245 | $ids[] = $id;
246 | }
247 | }
248 |
249 | return $ids;
250 | }
251 |
252 | /**
253 | * Stores the setting into database, logs the change and returns the config_log inserted id
254 | *
255 | * @param bool $name
256 | * @param mixed $value
257 | * @return integer config_log inserted id
258 | * @throws dml_exception
259 | * @throws moodle_exception
260 | */
261 | public function save_value($name = false, $value = null) {
262 |
263 | // Object values if no arguments.
264 | if ($value === null) {
265 | $value = $this->value;
266 | }
267 | if (!$name) {
268 | $name = $this->settingdata->name;
269 | }
270 |
271 | // Plugin name or null.
272 | $plugin = $this->settingdata->plugin;
273 | if ($plugin == 'none' || $plugin == '') {
274 | $plugin = null;
275 | }
276 |
277 | // Getting the actual value.
278 | $actualvalue = get_config($plugin, $name);
279 |
280 | // If it's the same it's not necessary.
281 | if ($actualvalue == $value) {
282 | return false;
283 | }
284 |
285 | set_config($name, $value, $plugin);
286 |
287 | return $this->to_log($plugin, $name, $value, $actualvalue);
288 | }
289 |
290 | /**
291 | * Copy of config_write method of the admin_setting class
292 | *
293 | * @param string $plugin
294 | * @param string $name
295 | * @param mixed $value
296 | * @param mixed $actualvalue
297 | * @return integer The stored config_log id
298 | */
299 | protected function to_log($plugin, $name, $value, $actualvalue) {
300 |
301 | global $DB, $USER;
302 |
303 | // Log the change (pasted from admin_setting class).
304 | $log = new stdClass();
305 | $log->userid = during_initial_install() ? 0 : $USER->id; // 0 as user id during install.
306 | $log->timemodified = time();
307 | $log->plugin = $plugin;
308 | $log->name = $name;
309 | $log->value = $value;
310 | $log->oldvalue = $actualvalue;
311 |
312 | // Getting the inserted config_log id.
313 | if (!$id = $DB->insert_record('config_log', $log)) {
314 | print_error('errorinserting', 'block_admin_presets');
315 | }
316 |
317 | return $id;
318 | }
319 | }
320 |
321 | /**
322 | * Cross-class methods
323 | */
324 | class admin_presets_delegation {
325 |
326 | /**
327 | * Adds a piece of string to the $type setting
328 | *
329 | * @param boolean $value
330 | * @param string $type Indicates the "extra" setting
331 | * @return string
332 | */
333 | public function extra_set_visiblevalue($value, $type) {
334 |
335 | // Adding the advanced value to the text string if present.
336 | if ($value) {
337 | $string = get_string('markedas' . $type, 'block_admin_presets');
338 | } else {
339 | $string = get_string('markedasnon' . $type, 'block_admin_presets');
340 | }
341 |
342 | // Adding the advanced state.
343 | return ', ' . $string;
344 | }
345 |
346 | public function extra_loadchoices(admin_setting &$adminsetting) {
347 | $adminsetting->load_choices();
348 | }
349 | }
350 |
351 | /** TEXT **/
352 |
353 | /**
354 | * Basic text setting, cleans the param using the admin_setting paramtext attribute
355 | */
356 | class admin_preset_auth_ldap_admin_setting_special_contexts_configtext extends admin_preset_setting {
357 |
358 | /**
359 | * Validates the value using paramtype attribute
360 | *
361 | * @param string $value
362 | * @return boolean Cleaned or not, but always true
363 | */
364 | protected function set_value($value) {
365 |
366 | $this->value = $value;
367 |
368 | if (empty($this->settingdata->paramtype)) {
369 |
370 | // For configfile, configpasswordunmask...
371 | $this->settingdata->paramtype = 'RAW';
372 | }
373 |
374 | $paramtype = 'PARAM_' . strtoupper($this->settingdata->paramtype);
375 |
376 | // Regexp.
377 | if (!defined($paramtype)) {
378 | $this->value = preg_replace($this->settingdata->paramtype, '', $this->value);
379 |
380 | // Standard moodle param type.
381 | } else {
382 | $this->value = clean_param($this->value, constant($paramtype));
383 | }
384 |
385 | return true;
386 | }
387 | }
388 |
389 | /**
390 | * Basic text setting, cleans the param using the admin_setting paramtext attribute
391 | */
392 | class admin_preset_admin_setting_configtext extends admin_preset_setting {
393 |
394 | /**
395 | * Validates the value using paramtype attribute
396 | *
397 | * @param string $value
398 | * @return boolean Cleaned or not, but always true
399 | */
400 | protected function set_value($value) {
401 |
402 | $this->value = $value;
403 |
404 | if (empty($this->settingdata->paramtype)) {
405 |
406 | // For configfile, configpasswordunmask...
407 | $this->settingdata->paramtype = 'RAW';
408 | }
409 |
410 | $paramtype = 'PARAM_' . strtoupper($this->settingdata->paramtype);
411 |
412 | // Regexp.
413 | if (!defined($paramtype)) {
414 | $this->value = preg_replace($this->settingdata->paramtype, '', $this->value);
415 |
416 | // Standard moodle param type.
417 | } else {
418 | $this->value = clean_param($this->value, constant($paramtype));
419 | }
420 |
421 | return true;
422 | }
423 | }
424 |
425 | /**
426 | * Adds the advanced attribute
427 | */
428 | class admin_preset_admin_setting_configtext_with_advanced extends admin_preset_admin_setting_configtext {
429 |
430 | public function __construct(admin_setting $settingdata, $dbsettingvalue) {
431 |
432 | // To look for other values.
433 | $this->attributes = array('fix' => $settingdata->name . '_adv');
434 | parent::__construct($settingdata, $dbsettingvalue);
435 | }
436 |
437 | /**
438 | * Sets the visible name for the setting selected value
439 | *
440 | * @return void
441 | */
442 | public function set_visiblevalue(): void {
443 | parent::set_visiblevalue();
444 | $this->visiblevalue .= $this->delegation->extra_set_visiblevalue(
445 | $this->attributesvalues[$this->attributes['fix']], 'advanced');
446 | }
447 | }
448 |
449 | class admin_preset_admin_setting_configiplist extends admin_preset_admin_setting_configtext {
450 |
451 | protected function set_value($value) {
452 |
453 | // Just in wrong format case.
454 | $this->value = '';
455 |
456 | // Check ip format.
457 | if ($this->settingdata->validate($value) !== true) {
458 | $this->value = false;
459 | return false;
460 | }
461 |
462 | $this->value = $value;
463 | return true;
464 | }
465 | }
466 |
467 | /**
468 | * Reimplementation to allow human friendly view of the selected regexps
469 | */
470 | class admin_preset_admin_setting_devicedetectregex extends admin_preset_admin_setting_configtext {
471 |
472 | /**
473 | * Sets the visible name for the setting selected value
474 | *
475 | * In most cases the child classes will overwrite
476 | *
477 | * @return void
478 | */
479 | public function set_visiblevalue(): void {
480 |
481 | $values = json_decode($this->get_value());
482 |
483 | if (!$values) {
484 | parent::set_visiblevalue();
485 | }
486 |
487 | $this->visiblevalue = '';
488 | foreach ($values as $key => $value) {
489 | $this->visiblevalue .= $key . ' = ' . $value . ', ';
490 | }
491 | $this->visiblevalue = rtrim($this->visiblevalue, ', ');
492 | }
493 | }
494 |
495 | /**
496 | * Reimplemented to store values in course table, not in config or config_plugins
497 | */
498 | class admin_preset_admin_setting_sitesettext extends admin_preset_admin_setting_configtext {
499 |
500 | /**
501 | * Overwritten to store the value in the course table
502 | *
503 | * @param bool $name
504 | * @param mixed $value
505 | * @return integer
506 | */
507 | public function save_value($name = false, $value = false) {
508 |
509 | global $DB;
510 |
511 | // Object values if no arguments.
512 | if ($value === null) {
513 | $value = $this->value;
514 | }
515 | if (!$name) {
516 | $name = $this->settingdata->name;
517 | }
518 |
519 | $sitecourse = $DB->get_record('course', array('id' => 1));
520 | $actualvalue = $sitecourse->{$name};
521 |
522 | // If it's the same value skip.
523 | if ($actualvalue == $this->value) {
524 | return false;
525 | }
526 |
527 | // Plugin name or ''.
528 | $plugin = $this->settingdata->plugin;
529 | if ($plugin == 'none' || $plugin == '') {
530 | $plugin = null;
531 | }
532 |
533 | // Updating mdl_course.
534 | $sitecourse->{$name} = $this->value;
535 | $DB->update_record('course', $sitecourse);
536 |
537 | return $this->to_log($plugin, $name, $this->value, $actualvalue);
538 | }
539 | }
540 |
541 | class admin_preset_admin_setting_configselect extends admin_preset_setting {
542 |
543 | /**
544 | * $value must be one of the setting choices
545 | *
546 | * @return boolean true if the value one of the setting choices
547 | */
548 | protected function set_value($value) {
549 |
550 | // When we intantiate the class we need the choices.
551 | if (empty($this->settindata->choices) && method_exists($this->settingdata, 'load_choices')) {
552 | $this->settingdata->load_choices();
553 | }
554 |
555 | foreach ($this->settingdata->choices as $key => $choice) {
556 |
557 | if ($key == $value) {
558 | $this->value = $value;
559 | return true;
560 | }
561 | }
562 |
563 | $this->value = false;
564 | return false;
565 | }
566 |
567 | /**
568 | * Sets the visible name for the setting selected value
569 | *
570 | * In most cases the child classes will overwrite
571 | *
572 | * @return void
573 | */
574 | public function set_visiblevalue(): void {
575 |
576 | // Just to avoid heritage problems.
577 | if (empty($this->settingdata->choices[$this->value])) {
578 | $this->visiblevalue = '';
579 | } else {
580 | $this->visiblevalue = $this->settingdata->choices[$this->value];
581 | }
582 |
583 | }
584 | }
585 |
586 | class admin_preset_admin_setting_bloglevel extends admin_preset_admin_setting_configselect {
587 |
588 | /**
589 | * Extended to change the block visibility
590 | */
591 | public function save_value($name = false, $value = false) {
592 |
593 | global $DB;
594 |
595 | if (!$id = parent::save_value($name, $value)) {
596 | return false;
597 | }
598 |
599 | // Pasted from admin_setting_bloglevel (can't use write_config).
600 | if ($value == 0) {
601 | $DB->set_field('block', 'visible', 0, array('name' => 'blog_menu'));
602 | } else {
603 | $DB->set_field('block', 'visible', 1, array('name' => 'blog_menu'));
604 | }
605 |
606 | return $id;
607 | }
608 | }
609 |
610 | /**
611 | * Adds support for the "advanced" attribute
612 | */
613 | class admin_preset_admin_setting_configselect_with_advanced extends admin_preset_admin_setting_configselect {
614 |
615 | protected $advancedkey;
616 |
617 | public function __construct(admin_setting $settingdata, $dbsettingvalue) {
618 |
619 | // Getting the advanced defaultsetting attribute name.
620 | if (is_array($settingdata->defaultsetting)) {
621 | foreach ($settingdata->defaultsetting as $key => $defaultvalue) {
622 | if ($key != 'value') {
623 | $this->advancedkey = $key;
624 | }
625 | }
626 | }
627 |
628 | // To look for other values.
629 | $this->attributes = array($this->advancedkey => $settingdata->name . '_adv');
630 | parent::__construct($settingdata, $dbsettingvalue);
631 | }
632 |
633 | /**
634 | * Sets the visible name for the setting selected value
635 | *
636 | * In most cases the child classes will overwrite
637 | *
638 | * @return void
639 | */
640 | public function set_visiblevalue(): void {
641 | parent::set_visiblevalue();
642 | $this->visiblevalue .= $this->delegation->extra_set_visiblevalue(
643 | $this->attributesvalues[$this->attributes[$this->advancedkey]], 'advanced');
644 | }
645 | }
646 |
647 | class admin_preset_mod_quiz_admin_setting_browsersecurity extends admin_preset_admin_setting_configselect_with_advanced {
648 |
649 | public function set_behaviors() {
650 | $this->behaviors['loadchoices'] = &$this->settingdata;
651 | }
652 | }
653 |
654 | class admin_preset_mod_quiz_admin_setting_grademethod extends admin_preset_admin_setting_configselect_with_advanced {
655 |
656 | public function set_behaviors() {
657 | $this->behaviors['loadchoices'] = &$this->settingdata;
658 | }
659 | }
660 |
661 | class admin_preset_mod_quiz_admin_setting_overduehandling extends admin_preset_admin_setting_configselect_with_advanced {
662 |
663 | public function set_behaviors() {
664 | $this->behaviors['loadchoices'] = &$this->settingdata;
665 | }
666 | }
667 |
668 | class admin_preset_mod_quiz_admin_setting_user_image extends admin_preset_admin_setting_configselect_with_advanced {
669 |
670 | public function set_behaviors() {
671 | $this->behaviors['loadchoices'] = &$this->settingdata;
672 | }
673 | }
674 |
675 | /**
676 | * A select with force and advanced options
677 | */
678 | class admin_preset_admin_setting_gradecat_combo extends admin_preset_admin_setting_configselect {
679 |
680 | /**
681 | * One db value for two setting attributes
682 | *
683 | * @param admin_setting $settingdata
684 | * @param unknown_type $dbsettingvalue
685 | */
686 | public function __construct(admin_setting $settingdata, $dbsettingvalue) {
687 |
688 | // set_attribute_value() will mod the VARNAME_flag value.
689 | $this->attributes = array('forced' => $settingdata->name . '_flag',
690 | 'adv' => $settingdata->name . '_flag');
691 | parent::__construct($settingdata, $dbsettingvalue);
692 | }
693 |
694 | /**
695 | * Sets the visible name for the setting selected value
696 | *
697 | * In most cases the child classes will overwrite
698 | *
699 | * @return void
700 | */
701 | public function set_visiblevalue(): void {
702 | parent::set_visiblevalue();
703 |
704 | $flagvalue = $this->attributesvalues[$this->settingdata->name . '_flag'];
705 |
706 | if (isset($flagvalue)) {
707 |
708 | if (($flagvalue % 2) == 1) {
709 | $forcedvalue = '1';
710 | } else {
711 | $forcedvalue = '0';
712 | }
713 |
714 | if ($flagvalue >= 2) {
715 | $advancedvalue = '1';
716 | } else {
717 | $advancedvalue = '0';
718 | }
719 | $this->visiblevalue .= $this->delegation->extra_set_visiblevalue($forcedvalue, 'forced');
720 | $this->visiblevalue .= $this->delegation->extra_set_visiblevalue($advancedvalue, 'advanced');
721 | }
722 | }
723 | }
724 |
725 | /**
726 | * Extends the base class and lists the selected values separated by comma
727 | */
728 | class admin_preset_admin_setting_configmultiselect extends admin_preset_setting {
729 |
730 | /**
731 | * Ensure that the $value values are setting choices
732 | */
733 | protected function set_value($value) {
734 |
735 | if ($value) {
736 | $options = explode(',', $value);
737 | foreach ($options as $key => $option) {
738 |
739 | foreach ($this->settingdata->choices as $key => $choice) {
740 |
741 | if ($key == $value) {
742 | $this->value = $value;
743 | return true;
744 | }
745 | }
746 | }
747 |
748 | $value = implode(',', $options);
749 | }
750 |
751 | $this->value = $value;
752 | }
753 |
754 | /**
755 | * Sets the visible name for the setting selected value
756 | *
757 | * In most cases the child classes will overwrite
758 | *
759 | * @return void
760 | */
761 | public function set_visiblevalue(): void {
762 |
763 | $values = explode(',', $this->value);
764 | $visiblevalues = array();
765 |
766 | foreach ($values as $value) {
767 |
768 | if (!empty($this->settingdata->choices[$value])) {
769 | $visiblevalues[] = $this->settingdata->choices[$value];
770 | }
771 | }
772 |
773 | if (empty($visiblevalues)) {
774 | $this->visiblevalue = '';
775 | }
776 |
777 | $this->visiblevalue = implode(', ', $visiblevalues);
778 | }
779 | }
780 |
781 | /**
782 | * Extends configselect to reuse set_valuevisible
783 | */
784 | class admin_preset_admin_setting_users_with_capability extends admin_preset_admin_setting_configmultiselect {
785 |
786 | protected function set_behaviors() {
787 | $this->behaviors['loadchoices'] = &$this->settingdata;
788 | }
789 |
790 | protected function set_value($value) {
791 |
792 | // Dirty hack (the value stored in the DB is '').
793 | $this->settingdata->choices[''] = $this->settingdata->choices['$@NONE@$'];
794 |
795 | return parent::set_value($value);
796 | }
797 | }
798 |
799 | /**
800 | * Generalizes a configmultipleselect with load_choices()
801 | *
802 | * @abstract
803 | */
804 | abstract class admin_preset_admin_setting_configmultiselect_with_loader extends admin_preset_admin_setting_configmultiselect {
805 |
806 | public function set_behaviors() {
807 | $this->behaviors['loadchoices'] = &$this->settingdata;
808 | }
809 | }
810 |
811 | class admin_preset_admin_setting_configtime extends admin_preset_setting {
812 |
813 | /**
814 | * To check that the value is one of the options
815 | *
816 | * @param string $name
817 | * @param mixed $value
818 | */
819 | public function set_attribute_value($name, $value) {
820 |
821 | for ($i = 0; $i < 60; $i = $i + 5) {
822 | $minutes[$i] = $i;
823 | }
824 |
825 | if (!empty($minutes[$value])) {
826 | $this->attributesvalues[$name] = $value;
827 | } else {
828 | $this->attributesvalues[$name] = $this->settingdata->defaultsetting['m'];
829 | }
830 | }
831 |
832 | protected function set_value($value) {
833 |
834 | $this->attributes = array('m' => $this->settingdata->name2);
835 |
836 | for ($i = 0; $i < 24; $i++) {
837 | $hours[$i] = $i;
838 | }
839 |
840 | if (empty($hours[$value])) {
841 | $this->value = false;
842 | }
843 |
844 | $this->value = $value;
845 | }
846 |
847 | public function set_visiblevalue(): void {
848 | $this->visiblevalue = $this->value . ':' . $this->attributesvalues[$this->settingdata->name2];
849 | }
850 | }
851 |
852 | /** CHECKBOXES **/
853 | class admin_preset_admin_setting_configcheckbox extends admin_preset_setting {
854 |
855 | protected function set_value($value) {
856 | $this->value = clean_param($value, PARAM_BOOL);
857 | return true;
858 | }
859 |
860 | public function set_visiblevalue(): void {
861 |
862 | if ($this->value) {
863 | $str = get_string('yes');
864 | } else {
865 | $str = get_string('no');
866 | }
867 |
868 | $this->visiblevalue = $str;
869 | }
870 | }
871 |
872 | class admin_preset_admin_setting_configcheckbox_with_advanced extends admin_preset_admin_setting_configcheckbox {
873 |
874 | public function __construct(admin_setting $settingdata, $dbsettingvalue) {
875 |
876 | // To look for other values.
877 | $this->attributes = array('adv' => $settingdata->name . '_adv');
878 | parent::__construct($settingdata, $dbsettingvalue);
879 | }
880 |
881 | /**
882 | * Uses delegation
883 | */
884 | public function set_visiblevalue(): void {
885 | parent::set_visiblevalue();
886 | $this->visiblevalue .= $this->delegation->extra_set_visiblevalue(
887 | $this->attributesvalues[$this->attributes['adv']], 'advanced');
888 | }
889 | }
890 |
891 | class admin_preset_admin_setting_configcheckbox_with_lock extends admin_preset_admin_setting_configcheckbox {
892 |
893 | public function __construct(admin_setting $settingdata, $dbsettingvalue) {
894 |
895 | // To look for other values.
896 | $this->attributes = array('locked' => $settingdata->name . '_locked');
897 | parent::__construct($settingdata, $dbsettingvalue);
898 | }
899 |
900 | /**
901 | * Uses delegation
902 | */
903 | public function set_visiblevalue(): void {
904 | parent::set_visiblevalue();
905 | $this->visiblevalue .= $this->delegation->extra_set_visiblevalue(
906 | $this->attributesvalues[$this->attributes['locked']], 'locked');
907 | }
908 | }
909 |
910 | /**
911 | * Abstract class to be extended by multicheckbox settings
912 | *
913 | * Now it's a useless class, child classes could extend admin_preset_admin_setting_configmultiselect
914 | *
915 | * @abstract
916 | */
917 | class admin_preset_admin_setting_configmulticheckbox extends admin_preset_admin_setting_configmultiselect {
918 |
919 | public function set_behaviors() {
920 | $this->behaviors['loadchoices'] = &$this->settingdata;
921 | }
922 | }
923 |
924 | /**
925 | * It doesn't specify loadchoices behavior because is set_visiblevalue who needs it
926 | */
927 | class admin_preset_admin_setting_special_backupdays extends admin_preset_setting {
928 |
929 | protected function set_value($value) {
930 | $this->value = clean_param($value, PARAM_SEQUENCE);
931 | }
932 |
933 | public function set_visiblevalue(): void {
934 |
935 | // TODO Try to use $this->behaviors.
936 | $this->settingdata->load_choices();
937 |
938 | $days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
939 |
940 | $selecteddays = array();
941 |
942 | $week = str_split($this->value);
943 | foreach ($week as $key => $day) {
944 | if ($day) {
945 | $index = $days[$key];
946 | $selecteddays[] = $this->settingdata->choices[$index];
947 | }
948 | }
949 |
950 | $this->visiblevalue = implode(', ', $selecteddays);
951 | }
952 | }
953 |
954 | /** OTHERS **/
955 | class admin_preset_admin_setting_special_calendar_weekend extends admin_preset_setting {
956 |
957 | public function set_visiblevalue(): void {
958 |
959 | if (!$this->value) {
960 | parent::set_visiblevalue();
961 | return;
962 | }
963 |
964 | $days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
965 | for ($i = 0; $i < 7; $i++) {
966 | if ($this->value & (1 << $i)) {
967 | $settings[] = get_string($days[$i], 'calendar');
968 | }
969 | }
970 |
971 | $this->visiblevalue = implode(', ', $settings);
972 | }
973 | }
974 |
975 | /**
976 | * Backward compatibility for Moodle 2.0
977 | */
978 | class admin_preset_admin_setting_quiz_reviewoptions extends admin_preset_setting {
979 |
980 | // Caution VENOM! admin_setting_quiz_reviewoptions vars can't be accessed.
981 | private static $times = array(
982 | QUIZ_REVIEW_IMMEDIATELY => 'reviewimmediately',
983 | QUIZ_REVIEW_OPEN => 'reviewopen',
984 | QUIZ_REVIEW_CLOSED => 'reviewclosed');
985 |
986 | private static $things = array(
987 | QUIZ_REVIEW_RESPONSES => 'responses',
988 | QUIZ_REVIEW_ANSWERS => 'answers',
989 | QUIZ_REVIEW_FEEDBACK => 'feedback',
990 | QUIZ_REVIEW_GENERALFEEDBACK => 'generalfeedback',
991 | QUIZ_REVIEW_SCORES => 'scores',
992 | QUIZ_REVIEW_OVERALLFEEDBACK => 'overallfeedback');
993 |
994 | /**
995 | * Stores the setting data and the selected value
996 | *
997 | * @param admin_setting $settingdata admin_setting subclass
998 | * @param mixed $dbsettingvalue Actual value
999 | */
1000 | public function __construct(admin_setting $settingdata, $dbsettingvalue) {
1001 | $this->attributes = array('fix' => $settingdata->name . '_adv');
1002 | parent::__construct($settingdata, $dbsettingvalue);
1003 | }
1004 |
1005 | /**
1006 | * Delegates
1007 | */
1008 | public function set_visiblevalue(): void {
1009 |
1010 | $marked = array();
1011 |
1012 | foreach (self::$times as $timemask => $time) {
1013 | foreach (self::$things as $typemask => $type) {
1014 | if ($this->value & $timemask & $typemask) {
1015 | $marked[$time][] = get_string($type, "quiz");
1016 | }
1017 | }
1018 | }
1019 |
1020 | foreach ($marked as $time => $types) {
1021 | $visiblevalues[] = '' . get_string($time, "quiz") .
1022 | ': ' . implode(', ', $types);
1023 | }
1024 | $this->visiblevalue = implode('
', $visiblevalues);
1025 |
1026 | if ($this->attributesvalues[$this->attributes['fix']]) {
1027 | $string = get_string("markedasnonadvanced", "block_admin_presets");
1028 | } else {
1029 | $string = get_string("markedasadvanced", "block_admin_presets");
1030 | }
1031 |
1032 | $this->visiblevalue .= '
' . ucfirst($string);
1033 | }
1034 | }
1035 |
1036 | /**
1037 | * Compatible with moodle 2.1 onwards (20120314)
1038 | */
1039 | class admin_preset_mod_quiz_admin_review_setting extends admin_preset_setting {
1040 |
1041 | /**
1042 | * Overwrite to add the reviewoptions text
1043 | */
1044 | public function set_text() {
1045 |
1046 | $this->set_visiblevalue();
1047 |
1048 | $name = get_string('reviewoptionsheading', 'quiz') .
1049 | ': ' . $this->settingdata->visiblename;
1050 | $namediv = '' . $name . '
';
1051 | $valuediv = '' . $this->visiblevalue . '
';
1052 |
1053 | $this->text = $namediv . $valuediv . '
';
1054 | }
1055 |
1056 | /**
1057 | * The setting value is a sum of 'mod_quiz_admin_review_setting::times'
1058 | */
1059 | public function set_visiblevalue(): void {
1060 | // Getting the masks descriptions (mod_quiz_admin_review_setting protected method).
1061 | $reflectiontimes = new ReflectionMethod('mod_quiz_admin_review_setting', 'times');
1062 | $reflectiontimes->setAccessible(true);
1063 | $times = $reflectiontimes->invoke(null);
1064 |
1065 | $visiblevalue = '';
1066 | foreach ($times as $timemask => $namestring) {
1067 |
1068 | // If the value is checked.
1069 | if ($this->value & $timemask) {
1070 | $visiblevalue .= $namestring . ', ';
1071 | }
1072 | }
1073 | $visiblevalue = rtrim($visiblevalue, ', ');
1074 |
1075 | $this->visiblevalue = $visiblevalue;
1076 | }
1077 | }
1078 |
1079 | /* We need to extend all those class */
1080 |
1081 | class admin_preset_admin_setting_configtextarea extends admin_preset_admin_setting_configtext {
1082 | }
1083 |
1084 | class admin_preset_admin_setting_configfile extends admin_preset_admin_setting_configtext {
1085 | }
1086 |
1087 | class admin_preset_admin_setting_configexecutable extends admin_preset_admin_setting_configfile {
1088 | }
1089 |
1090 | class admin_preset_admin_setting_configdirectory extends admin_preset_admin_setting_configfile {
1091 | }
1092 |
1093 | class admin_preset_admin_setting_special_backup_auto_destination extends admin_preset_admin_setting_configdirectory {
1094 | }
1095 |
1096 | class admin_preset_admin_setting_configpasswordunmask extends admin_preset_admin_setting_configtext {
1097 | }
1098 |
1099 | class admin_preset_admin_setting_langlist extends admin_preset_admin_setting_configtext {
1100 | }
1101 |
1102 | class admin_preset_admin_setting_configcolourpicker extends admin_preset_admin_setting_configtext {
1103 | }
1104 |
1105 | class admin_preset_admin_setting_emoticons extends admin_preset_setting {
1106 | }
1107 |
1108 | class admin_preset_admin_setting_confightmleditor extends admin_preset_admin_setting_configtext {
1109 | }
1110 |
1111 | class admin_preset_admin_setting_configtext_trim_lower extends admin_preset_admin_setting_configtext {
1112 | }
1113 |
1114 | class admin_preset_admin_setting_special_gradepointmax extends admin_preset_admin_setting_configtext {
1115 | }
1116 |
1117 | class admin_preset_admin_setting_special_gradepointdefault extends admin_preset_admin_setting_configtext {
1118 | }
1119 |
1120 | class admin_preset_admin_setting_configempty extends admin_preset_admin_setting_configtext {
1121 | }
1122 |
1123 | class admin_preset_admin_setting_configtext_with_maxlength extends admin_preset_admin_setting_configtext {
1124 | }
1125 |
1126 | class admin_preset_editor_tinymce_json_setting_textarea extends admin_preset_admin_setting_configtext {
1127 | }
1128 |
1129 | /**
1130 | * I'm not overwriting set_visiblevalue() as there is a lot of logic to duplicate.
1131 | */
1132 | class admin_preset_admin_setting_configduration extends admin_preset_admin_setting_configtext {
1133 | }
1134 |
1135 | class admin_preset_enrol_flatfile_role_setting extends admin_preset_admin_setting_configtext {
1136 | }
1137 |
1138 | /**
1139 | * I'm not overwriting set_visiblevalue() as there is a lot of logic to duplicate.
1140 | *
1141 | * @see admin_preset_admin_setting_configduration
1142 | */
1143 | class admin_preset_admin_setting_configduration_with_advanced extends admin_preset_admin_setting_configtext_with_advanced {
1144 | }
1145 |
1146 | class admin_preset_admin_setting_special_frontpagedesc extends admin_preset_admin_setting_sitesettext {
1147 | }
1148 |
1149 | class admin_preset_admin_setting_special_selectsetup extends admin_preset_admin_setting_configselect {
1150 | }
1151 |
1152 | class admin_preset_admin_setting_sitesetselect extends admin_preset_admin_setting_configselect {
1153 | }
1154 |
1155 | class admin_preset_admin_setting_special_grademinmaxtouse extends admin_preset_admin_setting_configselect {
1156 | }
1157 |
1158 | class admin_preset_admin_setting_my_grades_report extends admin_preset_admin_setting_configselect {
1159 | }
1160 |
1161 | class admin_preset_admin_setting_servertimezone extends admin_preset_admin_setting_configselect {
1162 | }
1163 |
1164 | class admin_preset_admin_setting_forcetimezone extends admin_preset_admin_setting_configselect {
1165 | }
1166 |
1167 | class admin_preset_enrol_database_admin_setting_category extends admin_preset_admin_setting_configselect {
1168 | }
1169 |
1170 | class admin_preset_enrol_ldap_admin_setting_category extends admin_preset_admin_setting_configselect {
1171 | }
1172 |
1173 | class admin_preset_format_singleactivity_admin_setting_activitytype extends admin_preset_admin_setting_configselect {
1174 | }
1175 |
1176 | class admin_preset_admin_setting_courselist_frontpage extends admin_preset_admin_setting_configmultiselect_with_loader {
1177 | }
1178 |
1179 | class admin_preset_admin_setting_configmultiselect_modules extends admin_preset_admin_setting_configmultiselect_with_loader {
1180 | }
1181 |
1182 | class admin_preset_admin_settings_country_select extends admin_preset_admin_setting_configmultiselect_with_loader {
1183 | }
1184 |
1185 | class admin_preset_admin_setting_special_registerauth extends admin_preset_admin_setting_configmultiselect_with_loader {
1186 | }
1187 |
1188 | class admin_preset_admin_setting_special_debug extends admin_preset_admin_setting_configmultiselect_with_loader {
1189 | }
1190 |
1191 | class admin_preset_admin_settings_coursecat_select extends admin_preset_admin_setting_configmultiselect_with_loader {
1192 | }
1193 |
1194 | class admin_preset_admin_setting_grade_profilereport extends admin_preset_admin_setting_configmultiselect_with_loader {
1195 | }
1196 |
1197 | class admin_preset_admin_settings_num_course_sections extends admin_preset_admin_setting_configmultiselect_with_loader {
1198 | }
1199 |
1200 | class admin_preset_admin_setting_question_behaviour extends admin_preset_admin_setting_configmultiselect_with_loader {
1201 | }
1202 |
1203 | class admin_preset_admin_setting_sitesetcheckbox extends admin_preset_admin_setting_configcheckbox {
1204 | }
1205 |
1206 | class admin_preset_admin_setting_special_adminseesall extends admin_preset_admin_setting_configcheckbox {
1207 | }
1208 |
1209 | class admin_preset_admin_setting_regradingcheckbox extends admin_preset_admin_setting_configcheckbox {
1210 | }
1211 |
1212 | class admin_preset_admin_setting_special_gradelimiting extends admin_preset_admin_setting_configcheckbox {
1213 | }
1214 |
1215 | class admin_preset_admin_setting_enablemobileservice extends admin_preset_admin_setting_configcheckbox {
1216 | }
1217 |
1218 | class admin_preset_admin_setting_pickroles extends admin_preset_admin_setting_configmulticheckbox {
1219 | }
1220 |
1221 | class admin_preset_admin_setting_special_coursemanager extends admin_preset_admin_setting_configmulticheckbox {
1222 | }
1223 |
1224 | class admin_preset_admin_setting_special_coursecontact extends admin_preset_admin_setting_configmulticheckbox {
1225 | }
1226 |
1227 | class admin_preset_admin_setting_special_gradebookroles extends admin_preset_admin_setting_configmulticheckbox {
1228 | }
1229 |
1230 | class admin_preset_admin_setting_special_gradeexport extends admin_preset_admin_setting_configmulticheckbox {
1231 | }
--------------------------------------------------------------------------------
/module.js:
--------------------------------------------------------------------------------
1 | M.block_admin_presets = {
2 |
3 | tree: null,
4 | nodes: null,
5 |
6 |
7 | /**
8 | * Initializes the TreeView object and adds the submit listener
9 | */
10 | init: function (Y) {
11 |
12 | Y.use('yui2-treeview', function (Y) {
13 |
14 | var context = M.block_admin_presets;
15 |
16 | context.tree = new Y.YUI2.widget.TreeView("settings_tree_div");
17 |
18 | context.nodes = [];
19 | context.nodes.root = context.tree.getRoot();
20 | });
21 | },
22 |
23 | /**
24 | * Creates a tree branch
25 | */
26 | addNodes: function (Y, ids, nodeids, labels, descriptions, parents) {
27 |
28 | var context = M.block_admin_presets;
29 |
30 | var nelements = ids.length;
31 | for (var i = 0; i < nelements; i++) {
32 |
33 | var settingId = ids[i];
34 | var nodeId = nodeids[i];
35 | var label = decodeURIComponent(labels[i]);
36 | var description = decodeURIComponent(descriptions[i]);
37 | var parent = parents[i];
38 |
39 | var newNode = new Y.YUI2.widget.HTMLNode(label, context.nodes[parent]);
40 |
41 | newNode.settingId = settingId;
42 | newNode.setNodesProperty('title', description);
43 | newNode.highlightState = 1;
44 |
45 | context.nodes[nodeId] = newNode;
46 | }
47 | },
48 |
49 | render: function (Y) {
50 |
51 | var context = M.block_admin_presets;
52 | var categories = context.tree.getNodesByProperty('settingId', 'category');
53 | // Cleaning categories without children.
54 | if (categories) {
55 | for (var i = 0; i < categories.length; i++) {
56 | if (!categories[i].hasChildren()) {
57 | context.tree.popNode(categories[i]);
58 | }
59 | }
60 | }
61 | categories = context.tree.getRoot().children;
62 | if (categories) {
63 | for (var j = 0; j < categories.length; j++) {
64 | if (!categories[j].hasChildren()) {
65 | context.tree.popNode(categories[j]);
66 | }
67 | }
68 | }
69 |
70 | // Context.tree.expandAll();.
71 | context.tree.setNodesProperty('propagateHighlightUp', true);
72 | context.tree.setNodesProperty('propagateHighlightDown', true);
73 | context.tree.subscribe('clickEvent', context.tree.onEventToggleHighlight);
74 | context.tree.render();
75 |
76 | // Listener to create one node for each selected setting.
77 | Y.YUI2.util.Event.on('id_admin_presets_submit', 'click', function () {
78 |
79 | // We need the moodle form to add the checked settings.
80 | var settingsPresetsForm = document.getElementById('id_admin_presets_submit').parentNode;
81 |
82 | var hiLit = context.tree.getNodesByProperty('highlightState', 1);
83 | if (Y.YUI2.lang.isNull(hiLit)) {
84 | Y.YUI2.log("Nothing selected");
85 |
86 | } else {
87 |
88 | // Only for debugging.
89 | var labels = [];
90 |
91 | for (var i = 0; i < hiLit.length; i++) {
92 |
93 | var treeNode = hiLit[i];
94 |
95 | // Only settings not setting categories nor settings pages.
96 | if (treeNode.settingId !== 'category' && treeNode.settingId !== 'page') {
97 | labels.push(treeNode.settingId);
98 |
99 | // If the node does not exists we add it.
100 | if (!document.getElementById(treeNode.settingId)) {
101 |
102 | var settingInput = document.createElement('input');
103 | settingInput.setAttribute('type', 'hidden');
104 | settingInput.setAttribute('name', treeNode.settingId);
105 | settingInput.setAttribute('value', '1');
106 | settingsPresetsForm.appendChild(settingInput);
107 | }
108 | }
109 | }
110 |
111 | Y.YUI2.log("Checked settings:\n" + labels.join("\n"), "info");
112 | }
113 | });
114 | }
115 | };
116 |
--------------------------------------------------------------------------------
/pix/check0.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigiDago/moodle-block_admin_presets/59e883469523a89f1eca2b364555e1ce61df33fa/pix/check0.gif
--------------------------------------------------------------------------------
/pix/check1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigiDago/moodle-block_admin_presets/59e883469523a89f1eca2b364555e1ce61df33fa/pix/check1.gif
--------------------------------------------------------------------------------
/pix/check2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DigiDago/moodle-block_admin_presets/59e883469523a89f1eca2b364555e1ce61df33fa/pix/check2.gif
--------------------------------------------------------------------------------
/settings.php:
--------------------------------------------------------------------------------
1 | .
16 |
17 | /**
18 | * Admin presets block main controller
19 | *
20 | * @package blocks/admin_presets
21 | * @copyright 2019 Pimenko
22 | * @author Jordan Kesraoui | DigiDago
23 | * @orignalauthor David Monllaó
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 | */
26 |
27 | defined('MOODLE_INTERNAL') || die();
28 |
29 | if ($ADMIN->fulltree) {
30 |
31 | $sensiblesettingsdefault = 'recaptchapublickey@@none, recaptchaprivatekey@@none, googlemapkey@@none, ';
32 | $sensiblesettingsdefault .= 'secretphrase@@none, cronremotepassword@@none, smtpuser@@none, ';
33 | $sensiblesettingsdefault .= 'smtppass@none, proxypassword@@none, password@@quiz, ';
34 | $sensiblesettingsdefault .= 'enrolpassword@@moodlecourse, allowedip@@none, blockedip@@none';
35 |
36 | $settings->add(new admin_setting_configtextarea('admin_presets/sensiblesettings',
37 | get_string('sensiblesettings', 'block_admin_presets'),
38 | get_string('sensiblesettingstext', 'block_admin_presets'),
39 | $sensiblesettingsdefault, PARAM_TEXT));
40 | }
41 |
--------------------------------------------------------------------------------
/styles.css:
--------------------------------------------------------------------------------
1 | .admin_presets_tree_name {
2 | padding: 0 0 4px 2px;
3 | }
4 |
5 | .admin_presets_tree_value {
6 | border: 1px solid #ccc;
7 | padding: 0 0 4px 2px;
8 | }
9 |
10 | .admin_presets_error {
11 | color: red;
12 | text-align: center;
13 | }
14 |
15 | .admin_presets_success {
16 | color: green;
17 | text-align: center;
18 | }
19 |
20 | #page-blocks-admin_presets-index #settings_tree_div .catnode {
21 | display: inline;
22 | margin-left: 5px;
23 | }
24 |
25 | #page-blocks-admin_presets-index #settings_tree_div .ygtv-checkbox .ygtv-highlight0 .ygtvcontent {
26 | background: url([[pix:block_admin_presets|check0]]) no-repeat;
27 | padding-left: 1em;
28 | }
29 |
30 | #page-blocks-admin_presets-index #settings_tree_div .ygtv-checkbox .ygtv-highlight0 .ygtvfocus.ygtvcontent,
31 | .ygtv-checkbox .ygtv-highlight1 .ygtvfocus.ygtvcontent,
32 | .ygtv-checkbox .ygtv-highlight2 .ygtvfocus.ygtvcontent {
33 | background-color: #c0e0e0;
34 | }
35 |
36 | #page-blocks-admin_presets-index #settings_tree_div .ygtv-checkbox .ygtv-highlight1 .ygtvcontent {
37 | background: url([[pix:block_admin_presets|check1]]) no-repeat;
38 | padding-left: 1em;
39 | }
40 |
41 | #page-blocks-admin_presets-index #settings_tree_div .ygtv-checkbox .ygtv-highlight2 .ygtvcontent {
42 | background: url([[pix:block_admin_presets|check2]]) no-repeat;
43 | padding-left: 1em;
44 | }
45 |
--------------------------------------------------------------------------------
/tabs.php:
--------------------------------------------------------------------------------
1 | .
16 |
17 | /**
18 | * Admin presets block main controller
19 | *
20 | * @package blocks/admin_presets
21 | * @copyright 2019 Pimenko
22 | * @author Jordan Kesraoui | DigiDago
23 | * @orignalauthor David Monllaó
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 | */
26 |
27 | defined('MOODLE_INTERNAL') || die();
28 |
29 | $adminpresetsurl = $CFG->wwwroot . '/blocks/admin_presets/index.php';
30 |
31 | $adminpresetstabs = array('base' => 'base',
32 | 'export' => 'export',
33 | 'import' => 'import');
34 |
35 | if (!array_key_exists($this->action, $adminpresetstabs)) {
36 | $row[] = new tabobject($this->action, $adminpresetsurl .
37 | '?action=' . $this->action, get_string('action' . $this->action, 'block_admin_presets'));
38 | }
39 |
40 | foreach ($adminpresetstabs as $actionname) {
41 | $row[] = new tabobject($actionname, $adminpresetsurl .
42 | '?action=' . $actionname, get_string('action' . $actionname, 'block_admin_presets'));
43 | }
44 |
45 | print_tabs(array($row), $this->action);
46 |
--------------------------------------------------------------------------------
/tests/behat/import_settings.feature:
--------------------------------------------------------------------------------
1 | @block @block_admin_presets
2 | Feature: I can export and import site settings
3 | In order to save time
4 | As an admin
5 | I need to export and import settings presets
6 |
7 | Background:
8 | Given I log in as "admin"
9 | And I am on site homepage
10 | And I follow "Turn editing on"
11 | And I add the "Admin presets" block
12 | And I follow "Export settings"
13 | And I set the following fields to these values:
14 | | Name | My preset |
15 | And I press "Save changes"
16 |
17 | @javascript
18 | Scenario: Preset settings are applied
19 | Given I follow "Advanced features"
20 | And I set the field "Enable portfolios" to "1"
21 | And I set the field "Enable badges" to "0"
22 | And I press "Save changes"
23 | And I navigate to "Assignment settings" node in "Site administration > Plugins > Activity modules > Assignment"
24 | And I set the field "Feedback plugin" to "File feedback"
25 | And I press "Save changes"
26 | And I navigate to "Course overview" node in "Site administration > Plugins > Blocks"
27 | And I set the field "Default maximum courses" to "5"
28 | And I press "Save changes"
29 | When I am on site homepage
30 | And I follow "Presets"
31 | And I click on "load" "link" in the "My preset" "table_row"
32 | And I press "Load selected settings"
33 | Then I should not see "All preset settings skipped, they are already loaded"
34 | And I should see "Settings applied"
35 | And I should see "Enable portfolios" in the ".admin_presets_applied" "css_element"
36 | And I should see "Enable badges" in the ".admin_presets_applied" "css_element"
37 | And I should see "Feedback plugin" in the ".admin_presets_applied" "css_element"
38 | And I should see "File feedback" in the ".admin_presets_applied" "css_element"
39 | And I should see "Default maximum courses" in the ".admin_presets_applied" "css_element"
40 | And I should see "Enable outcomes" in the ".admin_presets_skipped" "css_element"
41 | And I should see "Show recent submissions" in the ".admin_presets_skipped" "css_element"
42 | And I should see "Force maximum courses" in the ".admin_presets_skipped" "css_element"
43 | And I follow "Advanced features"
44 | And the field "Enable portfolios" matches value "0"
45 | And the field "Enable badges" matches value "1"
46 | And I navigate to "Assignment settings" node in "Site administration > Plugins > Activity modules > Assignment"
47 | And the field "Feedback plugin" matches value "Feedback comments"
48 | And I navigate to "Course overview" node in "Site administration > Plugins > Blocks"
49 | And the field "Default maximum courses" matches value "10"
50 |
51 | @javascript
52 | Scenario: Settings don't change if you import what you just exported
53 | When I click on "load" "link" in the "My preset" "table_row"
54 | And I press "Load selected settings"
55 | Then I should see "All preset settings skipped, they are already loaded"
56 | And I should not see "Settings applied"
57 |
--------------------------------------------------------------------------------
/tests/behat/revert_changes.feature:
--------------------------------------------------------------------------------
1 | @block @block_admin_presets
2 | Feature: I can revert changes
3 | In order to save time
4 | As an admin
5 | I need to export and import settings presets
6 |
7 | @javascript
8 | Scenario: Load changes and revert them
9 | Given I log in as "admin"
10 | And I am on site homepage
11 | And I follow "Turn editing on"
12 | And I add the "Admin presets" block
13 | And I follow "Export settings"
14 | And I set the following fields to these values:
15 | | Name | My preset |
16 | And I press "Save changes"
17 | And I follow "Advanced features"
18 | And I set the field "Enable portfolios" to "1"
19 | And I set the field "Enable badges" to "0"
20 | And I press "Save changes"
21 | And I navigate to "Assignment settings" node in "Site administration > Plugins > Activity modules > Assignment"
22 | And I set the field "Feedback plugin" to "File feedback"
23 | And I press "Save changes"
24 | And I navigate to "Course overview" node in "Site administration > Plugins > Blocks"
25 | And I set the field "Default maximum courses" to "5"
26 | And I press "Save changes"
27 | And I am on site homepage
28 | And I follow "Presets"
29 | And I click on "load" "link" in the "My preset" "table_row"
30 | And I press "Load selected settings"
31 | And I am on site homepage
32 | When I follow "Presets"
33 | And I click on "revert" "link" in the "My preset" "table_row"
34 | And I follow "revert"
35 | Then I should see "Settings successfully restored"
36 | And I should see "Enable portfolios" in the ".admin_presets_applied" "css_element"
37 | And I should see "Enable badges" in the ".admin_presets_applied" "css_element"
38 | And I should see "Feedback plugin" in the ".admin_presets_applied" "css_element"
39 | And I should see "File feedback" in the ".admin_presets_applied" "css_element"
40 | And I follow "Advanced features"
41 | And the field "Enable portfolios" matches value "1"
42 | And the field "Enable badges" matches value "0"
43 | And I navigate to "Assignment settings" node in "Site administration > Plugins > Activity modules > Assignment"
44 | And the field "Feedback plugin" matches value "File feedback"
45 | And I navigate to "Course overview" node in "Site administration > Plugins > Blocks"
46 | And the field "Default maximum courses" matches value "5"
47 |
--------------------------------------------------------------------------------
/version.php:
--------------------------------------------------------------------------------
1 | .
16 |
17 | /**
18 | * Admin presets block main controller
19 | *
20 | * @package blocks/admin_presets
21 | * @copyright 2019 Pimenko
22 | * @author Jordan Kesraoui | DigiDago
23 | * @orignalauthor David Monllaó
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 | */
26 |
27 | defined('MOODLE_INTERNAL') || die();
28 |
29 | $plugin->version = 2022121300;
30 | $plugin->requires = 2022041905; // Requires this Moodle version
31 | $plugin->component = 'block_admin_presets';
32 | $plugin->release = '4.1';
33 | $plugin->cron = 0;
34 | $plugin->maturity = MATURITY_STABLE;
35 |
--------------------------------------------------------------------------------