mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-73397 adminpresets: Create new core_adminpresets component
The core_adminpresets component has been added and some data and methods from the tool_admin_presets have been moved here.
- Loading branch information
Showing
47 changed files
with
5,702 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
adminpresets/classes/local/setting/adminpresets_admin_setting_bloglevel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
adminpresets/classes/local/setting/adminpresets_admin_setting_configcheckbox.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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; | ||
|
||
/** | ||
* 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 { | ||
|
||
protected function set_value($value) { | ||
$this->value = clean_param($value, PARAM_BOOL); | ||
return true; | ||
} | ||
|
||
protected function set_visiblevalue() { | ||
if ($this->value) { | ||
$str = get_string('yes'); | ||
} else { | ||
$str = get_string('no'); | ||
} | ||
|
||
$this->visiblevalue = $str; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...presets/classes/local/setting/adminpresets_admin_setting_configcheckbox_with_advanced.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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(); | ||
$value = $this->attributesvalues[$this->attributes['adv']]; | ||
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'advanced'); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
adminpresets/classes/local/setting/adminpresets_admin_setting_configcheckbox_with_lock.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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(); | ||
$value = $this->attributesvalues[$this->attributes['locked']]; | ||
$this->visiblevalue .= $this->delegation->extra_set_visiblevalue($value, 'locked'); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
adminpresets/classes/local/setting/adminpresets_admin_setting_configiplist.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?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; | ||
return false; | ||
} | ||
|
||
$this->value = $value; | ||
return true; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
adminpresets/classes/local/setting/adminpresets_admin_setting_configmulticheckbox.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
adminpresets/classes/local/setting/adminpresets_admin_setting_configmultiselect.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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 { | ||
|
||
/** | ||
* Ensure that the $value values are setting choices. | ||
* | ||
* @param mixed $value Setting value | ||
* @return mixed Returns false if wrong param value | ||
*/ | ||
protected function set_value($value) { | ||
if ($value) { | ||
$options = explode(',', $value); | ||
foreach ($options as $option) { | ||
|
||
foreach ($this->settingdata->choices as $key => $choice) { | ||
|
||
if ($key == $option) { | ||
$this->value = $option; | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
$value = implode(',', $options); | ||
} | ||
|
||
$this->value = $value; | ||
} | ||
|
||
protected function set_visiblevalue() { | ||
$values = explode(',', $this->value); | ||
$visiblevalues = []; | ||
|
||
foreach ($values as $value) { | ||
|
||
if (!empty($this->settingdata->choices[$value])) { | ||
$visiblevalues[] = $this->settingdata->choices[$value]; | ||
} | ||
} | ||
|
||
if (empty($visiblevalues)) { | ||
$this->visiblevalue = ''; | ||
return false; | ||
} | ||
|
||
$this->visiblevalue = implode(', ', $visiblevalues); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...resets/classes/local/setting/adminpresets_admin_setting_configmultiselect_with_loader.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.