first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,57 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Select setting for blog's bloglevel setting.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_bloglevel extends adminpresets_admin_setting_configselect {
/**
* Extended to change the block visibility.
*
* @param bool $name Setting name to store.
* @param mixed $value Setting value to store.
* @return int|false config_log inserted id or false whenever the value has not been saved.
*/
public function save_value($name = false, $value = null) {
global $DB;
if (!$id = parent::save_value($name, $value)) {
return false;
}
// Object values if no arguments.
if ($value === null) {
$value = $this->value;
}
// Pasted from admin_setting_bloglevel (can't use write_config).
if ($value == 0) {
$DB->set_field('block', 'visible', 0, ['name' => 'blog_menu']);
} else {
$DB->set_field('block', 'visible', 1, ['name' => 'blog_menu']);
}
return $id;
}
}
@@ -0,0 +1,47 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
use admin_setting_configcheckbox;
/**
* Checkbox setting.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configcheckbox extends adminpresets_setting {
/**
* Sets the visible name for the setting selected value
*/
protected function set_visiblevalue() {
/** @var admin_setting_configcheckbox $settingdata */
$settingdata = $this->get_settingdata();
// We need to compare the "yes" value of the inner checkbox, which isn't necessarily boolean.
if ($this->value == $settingdata->yes) {
$str = get_string('yes');
} else {
$str = get_string('no');
}
$this->visiblevalue = $str;
}
}
@@ -0,0 +1,48 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
use admin_setting;
/**
* Checkbox with an advanced checkbox that controls an additional $name.'_adv' config setting.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configcheckbox_with_advanced extends adminpresets_admin_setting_configcheckbox {
public function __construct(admin_setting $settingdata, $dbsettingvalue) {
// To look for other values.
$this->attributes = ['adv' => $settingdata->name . '_adv'];
parent::__construct($settingdata, $dbsettingvalue);
}
/**
* Uses delegation
*/
protected function set_visiblevalue() {
parent::set_visiblevalue();
if (!is_null($this->attributesvalues) && array_key_exists($this->attributes['adv'], $this->attributesvalues)) {
$value = $this->attributesvalues[$this->attributes['adv']];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'advanced');
}
}
}
@@ -0,0 +1,47 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
use admin_setting;
/**
* Checkbox with an advanced checkbox that controls an additional $name.'_locked' config setting.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configcheckbox_with_lock extends adminpresets_admin_setting_configcheckbox {
public function __construct(admin_setting $settingdata, $dbsettingvalue) {
// To look for other values.
$this->attributes = ['locked' => $settingdata->name . '_locked'];
parent::__construct($settingdata, $dbsettingvalue);
}
/**
* Uses delegation
*/
protected function set_visiblevalue() {
parent::set_visiblevalue();
if (!is_null($this->attributesvalues) && array_key_exists($this->attributes['locked'], $this->attributesvalues)) {
$value = $this->attributesvalues[$this->attributes['locked']];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'locked');
}
}
}
@@ -0,0 +1,41 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Used to validate a textarea used for ip addresses.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configiplist extends adminpresets_admin_setting_configtext {
protected function set_value($value) {
// Check ip format.
if ($this->settingdata->validate($value) !== true) {
$this->value = false;
$this->set_visiblevalue();
return false;
}
$this->value = $value;
$this->set_visiblevalue();
return true;
}
}
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Class to be extended by multicheckbox settings.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configmulticheckbox extends adminpresets_admin_setting_configmultiselect {
public function set_behaviors() {
$this->behaviors['loadchoices'] = &$this->settingdata;
}
}
@@ -0,0 +1,51 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Extends the base class and lists the selected values separated by comma.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configmultiselect extends adminpresets_setting {
/** @var \admin_setting_configmultiselect $settingdata */
protected $settingdata;
protected function set_visiblevalue() {
$values = explode(',', $this->value);
$visiblevalues = [];
foreach ($values as $value) {
// Ensure that each value exists as a setting choice.
if (array_key_exists($value, $this->settingdata->choices)) {
$visiblevalues[] = $this->settingdata->choices[$value];
}
}
if (empty($visiblevalues)) {
$this->visiblevalue = '';
return false;
}
$this->visiblevalue = implode(', ', $visiblevalues);
}
}
@@ -0,0 +1,32 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Generalizes a configmultipleselect with load_choices().
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configmultiselect_with_loader extends adminpresets_admin_setting_configmultiselect {
public function set_behaviors() {
$this->behaviors['loadchoices'] = &$this->settingdata;
}
}
@@ -0,0 +1,68 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Select one value from list.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configselect extends adminpresets_setting {
/** @var \admin_setting_configselect $settingdata */
protected $settingdata;
/**
* Sets the setting value cleaning it.
*
* @param mixed $value must be one of the setting choices.
* @return bool true if the value one of the setting choices
*/
protected function set_value($value) {
// When we intantiate the class we need the choices.
if (empty($this->settingdata->choices) && method_exists($this->settingdata, 'load_choices')) {
$this->settingdata->load_choices();
}
if (!is_null($this->settingdata->choices) and is_array($this->settingdata->choices)) {
foreach ($this->settingdata->choices as $key => $choice) {
if ($key == $value) {
$this->value = $value;
$this->set_visiblevalue();
return true;
}
}
}
$this->value = false;
$this->set_visiblevalue();
return false;
}
protected function set_visiblevalue() {
// Just to avoid heritage problems.
if (empty($this->settingdata->choices[$this->value])) {
$this->visiblevalue = '';
} else {
$this->visiblevalue = $this->settingdata->choices[$this->value];
}
}
}
@@ -0,0 +1,59 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
use admin_setting;
/**
* Adds support for the "advanced" attribute.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configselect_with_advanced extends adminpresets_admin_setting_configselect {
/** @var string Name of the advanced setting. **/
protected $advancedkey;
public function __construct(admin_setting $settingdata, $dbsettingvalue) {
// Getting the advanced defaultsetting attribute name.
if (is_array($settingdata->defaultsetting)) {
foreach ($settingdata->defaultsetting as $key => $defaultvalue) {
if ($key != 'value') {
$this->advancedkey = $key;
}
}
}
// To look for other values.
$this->attributes = [$this->advancedkey => $settingdata->name . '_adv'];
parent::__construct($settingdata, $dbsettingvalue);
}
/**
* Funcionality used by other _with_advanced settings
*/
protected function set_visiblevalue() {
parent::set_visiblevalue();
if (!is_null($this->attributesvalues)) {
$attribute = $this->attributes[$this->advancedkey];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($this->attributesvalues[$attribute], 'advanced');
}
}
}
@@ -0,0 +1,58 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Basic text setting, cleans the param using the admin_setting paramtext attribute.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configtext extends adminpresets_setting {
/**
* Validates the value using paramtype attribute
*
* @param mixed $value
* @return boolean Cleaned or not, but always true.
*/
protected function set_value($value) {
$this->value = $value;
if (empty($this->settingdata->paramtype)) {
// For configfile, configpasswordunmask....
$this->settingdata->paramtype = 'RAW';
}
$paramtype = 'PARAM_' . strtoupper($this->settingdata->paramtype);
// Regexp.
if (!defined($paramtype)) {
$this->value = preg_replace($this->settingdata->paramtype, '', $this->value);
// Standard moodle param type.
} else {
$this->value = clean_param($this->value, constant($paramtype));
}
$this->set_visiblevalue();
return true;
}
}
@@ -0,0 +1,47 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
use admin_setting;
/**
* Adds the advanced attribute.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configtext_with_advanced extends adminpresets_admin_setting_configtext {
public function __construct(admin_setting $settingdata, $dbsettingvalue) {
// To look for other values.
$this->attributes = ['fix' => $settingdata->name . '_adv'];
parent::__construct($settingdata, $dbsettingvalue);
}
/**
* Delegates
*/
protected function set_visiblevalue() {
parent::set_visiblevalue();
if (!is_null($this->attributesvalues) && array_key_exists($this->attributes['fix'], $this->attributesvalues)) {
$value = $this->attributesvalues[$this->attributes['fix']];
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'advanced');
}
}
}
@@ -0,0 +1,70 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Time selector.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_configtime extends adminpresets_setting {
/** @var \admin_setting_configtime $settingdata */
protected $settingdata;
/**
* To check that the value is one of the options
*
* @param string $name
* @param mixed $value
*/
public function set_attribute_value($name, $value) {
for ($i = 0; $i < 60; $i = $i + 5) {
$minutes[$i] = $i;
}
if (!empty($minutes[$value])) {
$this->attributesvalues[$name] = $value;
} else {
$this->attributesvalues[$name] = $this->settingdata->defaultsetting['m'];
}
}
protected function set_value($value) {
$this->attributes = ['m' => $this->settingdata->name2];
for ($i = 0; $i < 24; $i++) {
$hours[$i] = $i;
}
if (empty($hours[$value])) {
$this->value = false;
}
$this->value = $value;
$this->set_visiblevalue();
}
protected function set_visiblevalue() {
if (!is_null($this->attributesvalues) && array_key_exists($this->settingdata->name2, $this->attributesvalues)) {
$this->visiblevalue = $this->value . ':' . $this->attributesvalues[$this->settingdata->name2];
}
}
}
@@ -0,0 +1,54 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Reimplementation to allow human friendly view of the selected regexps.
*
* @deprecated Moodle 4.3 MDL-78468 - No longer used since the devicedetectregex was removed.
* @todo Final deprecation on Moodle 4.7 MDL-79052
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_devicedetectregex extends adminpresets_admin_setting_configtext {
/**
* @deprecated Moodle 4.3 MDL-78468 - No longer used since the devicedetectregex was removed.
* @todo Final deprecation on Moodle 4.7 MDL-79052
*/
public function set_visiblevalue() {
debugging(
__FUNCTION__ . '() is deprecated.' .
'All functions associated with devicedetectregex theme setting are being removed.',
DEBUG_DEVELOPER
);
$values = json_decode($this->get_value());
if (!$values) {
parent::set_visiblevalue();
return;
}
$this->visiblevalue = '';
foreach ($values as $key => $value) {
$this->visiblevalue .= $key . ' = ' . $value . ', ';
}
$this->visiblevalue = rtrim($this->visiblevalue, ', ');
}
}
@@ -0,0 +1,61 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
use admin_setting;
/**
* A select with force and advanced options
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_gradecat_combo extends adminpresets_admin_setting_configselect {
/**
* One db value for two setting attributes
*
* @param admin_setting $settingdata
* @param mixed $dbsettingvalue
*/
public function __construct(admin_setting $settingdata, $dbsettingvalue) {
// The set_attribute_value() method will mod the VARNAME_flag value.
$this->attributes = ['forced' => $settingdata->name . '_flag', 'adv' => $settingdata->name . '_flag'];
parent::__construct($settingdata, $dbsettingvalue);
}
/**
* Special treatment! the value be extracted from the $value argument
*/
protected function set_visiblevalue() {
parent::set_visiblevalue();
if (!is_null($this->attributesvalues) && array_key_exists($this->settingdata->name . '_flag', $this->attributesvalues)) {
$flagvalue = $this->attributesvalues[$this->settingdata->name . '_flag'];
if (isset($flagvalue)) {
$forcedvalue = (($flagvalue % 2) == 1);
$advancedvalue = ($flagvalue >= 2);
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($forcedvalue, 'forced');
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($advancedvalue, 'advanced');
}
}
}
}
@@ -0,0 +1,67 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Reimplemented to store values in course table, not in config or config_plugins.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_sitesettext extends adminpresets_admin_setting_configtext {
/**
* Overwritten to store the value in the course table
*
* @param bool $name
* @param mixed $value
* @return int|false config_log inserted id or false whenever the new value is the same as old value.
*/
public function save_value($name = false, $value = null) {
global $DB;
// Object values if no arguments.
if ($value === null) {
$value = $this->value;
}
if (!$name) {
$name = $this->settingdata->name;
}
$sitecourse = $DB->get_record('course', ['id' => 1]);
$actualvalue = $sitecourse->{$name};
// If it's the same value skip.
if ($actualvalue == $value) {
return false;
}
// Plugin name or ''.
$plugin = $this->settingdata->plugin;
if ($plugin == 'none' || $plugin == '') {
$plugin = null;
}
// Updating mdl_course.
$sitecourse->{$name} = $value;
$DB->update_record('course', $sitecourse);
return $this->to_log($plugin, $name, $this->value, $actualvalue);
}
}
@@ -0,0 +1,56 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Special control for selecting days to backup.
*
* It doesn't specify loadchoices behavior because is set_visiblevalue who needs it.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_special_backupdays extends adminpresets_setting {
/** @var \admin_setting_special_backupdays $settingdata */
protected $settingdata;
protected function set_value($value) {
$this->value = clean_param($value, PARAM_SEQUENCE);
$this->set_visiblevalue();
}
protected function set_visiblevalue() {
$this->settingdata->load_choices();
$days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
$selecteddays = [];
$week = str_split($this->value);
foreach ($week as $key => $day) {
if ($day) {
$index = $days[$key];
$selecteddays[] = $this->settingdata->choices[$index];
}
}
$this->visiblevalue = implode(', ', $selecteddays);
}
}
@@ -0,0 +1,44 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Special admin control for calendar weekend.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_special_calendar_weekend extends adminpresets_setting {
protected function set_visiblevalue() {
if (!$this->value) {
parent::set_visiblevalue();
return;
}
$days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
for ($i = 0; $i < 7; $i++) {
if ($this->value & (1 << $i)) {
$settings[] = get_string($days[$i], 'calendar');
}
}
$this->visiblevalue = implode(', ', $settings);
}
}
@@ -0,0 +1,42 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
/**
* Extends configselect to reuse set_valuevisible.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_admin_setting_users_with_capability extends adminpresets_admin_setting_configmultiselect {
/** @var \admin_setting_configmultiselect $settingdata */
protected $settingdata;
protected function set_behaviors() {
$this->behaviors['loadchoices'] = &$this->settingdata;
}
protected function set_value($value) {
// Dirty hack (the value stored in the DB is '').
$this->settingdata->choices[''] = $this->settingdata->choices['$@NONE@$'];
return parent::set_value($value);
}
}
@@ -0,0 +1,269 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
use admin_setting;
use moodle_exception;
use stdClass;
/**
* Admin tool presets plugin to load some settings.
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class adminpresets_setting {
/**
* @var admin_setting
*/
protected $settingdata;
/**
* @var delegation
*/
protected $delegation;
/**
* The setting DB value
*
* @var mixed
*/
protected $value;
/**
* Stores the visible value of the setting DB value
*
* @var string
*/
protected $visiblevalue;
/**
* For multiple value settings, used to look for the other values
*
* @var string
*/
protected $attributes = false;
/**
* To store the setting attributes
*
* @var array
*/
protected $attributesvalues;
/** @var array To store the behaviors. */
protected array $behaviors = [];
/**
* Stores the setting data and the selected value
*
* @param admin_setting $settingdata admin_setting subclass
* @param mixed $dbsettingvalue Actual value
*/
public function __construct(admin_setting $settingdata, $dbsettingvalue) {
$this->settingdata = $settingdata;
$this->delegation = new delegation();
if ($this->settingdata->plugin == '') {
$this->settingdata->plugin = 'none';
}
// Applies specific children behaviors.
$this->set_behaviors();
$this->apply_behaviors();
// Cleaning value.
$this->set_value($dbsettingvalue);
}
/**
* Each class can overwrite this method to specify extra processes
*/
protected function set_behaviors() {
}
/**
* Applies the children class specific behaviors
*
* See delegation class for the available extra behaviors
*/
protected function apply_behaviors() {
if (!empty($this->behaviors)) {
foreach ($this->behaviors as $behavior => $arguments) {
// The arguments of the behavior depends on the caller.
$methodname = 'extra_' . $behavior;
$this->delegation->{$methodname}($arguments);
}
}
}
/**
* Gets the setting value.
*
* @return mixed The setting value
*/
public function get_value() {
return $this->value;
}
/**
* Sets the setting value cleaning it
*
* Child classes should overwrite method to clean more acurately
*
* @param mixed $value Setting value
* @return mixed Returns false if wrong param value
*/
protected function set_value($value) {
$this->value = $value;
$this->set_visiblevalue();
}
public function get_visiblevalue() {
return $this->visiblevalue;
}
/**
* Sets the visible name for the setting selected value
*
* In most cases the child classes will overwrite
*/
protected function set_visiblevalue() {
$this->visiblevalue = $this->value;
}
public function get_attributes() {
return $this->attributes;
}
public function get_attributes_values() {
return $this->attributesvalues;
}
public function get_settingdata() {
return $this->settingdata;
}
public function set_attribute_value($name, $value) {
$this->attributesvalues[$name] = $value;
}
/**
* Saves the setting attributes values
*
* @return array|false Array of inserted ids (in config_log) or false if nothing was inserted
*/
public function save_attributes_values() {
// Plugin name or null.
$plugin = $this->settingdata->plugin;
if ($plugin == 'none' || $plugin == '') {
$plugin = null;
}
if (!$this->attributesvalues) {
return false;
}
// To store inserted ids.
$ids = [];
foreach ($this->attributesvalues as $name => $value) {
// Getting actual setting.
$actualsetting = get_config($plugin, $name);
// If it's the actual setting get off.
if ($value == $actualsetting) {
return false;
}
if ($id = $this->save_value($name, $value)) {
$ids[] = $id;
}
}
return $ids;
}
/**
* Stores the setting into database, logs the change and returns the config_log inserted id
*
* @param bool $name Setting name to store.
* @param mixed $value Setting value to store.
* @return int|false config_log inserted id or false whenever the new value is the same as old value.
*/
public function save_value($name = false, $value = null) {
// Object values if no arguments.
if ($value === null) {
$value = $this->value;
}
if (!$name) {
$name = $this->settingdata->name;
}
// Plugin name or null.
$plugin = $this->settingdata->plugin;
if ($plugin == 'none' || $plugin == '') {
$plugin = null;
}
// Getting the actual value.
$actualvalue = get_config($plugin, $name);
// If it's the same it's not necessary.
if ($actualvalue == $value) {
return false;
}
set_config($name, $value, $plugin);
return $this->to_log($plugin, $name, $value, $actualvalue);
}
/**
* Copy of config_write method of the admin_setting class
*
* @param string $plugin
* @param string $name
* @param mixed $value
* @param mixed $actualvalue
* @return integer The stored config_log id
*/
protected function to_log($plugin, $name, $value, $actualvalue) {
global $DB, $USER;
// Log the change (pasted from admin_setting class).
$log = new stdClass();
$log->userid = during_initial_install() ? 0 : $USER->id; // 0 as user id during install.
$log->timemodified = time();
$log->plugin = $plugin;
$log->name = $name;
$log->value = $value;
$log->oldvalue = $actualvalue;
// Getting the inserted config_log id.
if (!$id = $DB->insert_record('config_log', $log)) {
throw new moodle_exception('errorinserting', 'core_adminpresets');
}
return $id;
}
}
@@ -0,0 +1,53 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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/>.
namespace core_adminpresets\local\setting;
use admin_setting;
/**
* Cross-class methods
*
* @package core_adminpresets
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class delegation {
/**
* Adds a piece of string to the $type setting
*
* @param boolean $value
* @param string $type Indicates the "extra" setting
* @return string
*/
public function extra_set_visiblevalue(bool $value, string $type): string {
// Adding the advanced value to the text string if present.
if ($value) {
$string = get_string('markedas' . $type, 'core_adminpresets');
} else {
$string = get_string('markedasnon' . $type, 'core_adminpresets');
}
// Adding the advanced state.
return ', ' . $string;
}
public function extra_loadchoices(admin_setting &$adminsetting) {
$adminsetting->load_choices();
}
}