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 |
namespace core_adminpresets\local\setting;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Reimplemented to store values in course table, not in config or config_plugins.
|
|
|
21 |
*
|
|
|
22 |
* @package core_adminpresets
|
|
|
23 |
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
|
|
|
24 |
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
*/
|
|
|
27 |
class adminpresets_admin_setting_sitesettext extends adminpresets_admin_setting_configtext {
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Overwritten to store the value in the course table
|
|
|
31 |
*
|
|
|
32 |
* @param bool $name
|
|
|
33 |
* @param mixed $value
|
|
|
34 |
* @return int|false config_log inserted id or false whenever the new value is the same as old value.
|
|
|
35 |
*/
|
|
|
36 |
public function save_value($name = false, $value = null) {
|
|
|
37 |
global $DB;
|
|
|
38 |
|
|
|
39 |
// Object values if no arguments.
|
|
|
40 |
if ($value === null) {
|
|
|
41 |
$value = $this->value;
|
|
|
42 |
}
|
|
|
43 |
if (!$name) {
|
|
|
44 |
$name = $this->settingdata->name;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
$sitecourse = $DB->get_record('course', ['id' => 1]);
|
|
|
48 |
$actualvalue = $sitecourse->{$name};
|
|
|
49 |
|
|
|
50 |
// If it's the same value skip.
|
|
|
51 |
if ($actualvalue == $value) {
|
|
|
52 |
return false;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
// Plugin name or ''.
|
|
|
56 |
$plugin = $this->settingdata->plugin;
|
|
|
57 |
if ($plugin == 'none' || $plugin == '') {
|
|
|
58 |
$plugin = null;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
// Updating mdl_course.
|
|
|
62 |
$sitecourse->{$name} = $value;
|
|
|
63 |
$DB->update_record('course', $sitecourse);
|
|
|
64 |
|
|
|
65 |
return $this->to_log($plugin, $name, $this->value, $actualvalue);
|
|
|
66 |
}
|
|
|
67 |
}
|