+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class base {
protected static $eventsactionsmap = array(
- 'base' => 'presets_listed',
- 'delete' => 'preset_deleted',
- 'export' => 'preset_exported',
- 'import' => 'preset_imported',
- 'preview' => 'preset_previewed',
- 'load' => 'preset_loaded',
- 'rollback' => 'preset_reverted',
- 'download_xml' => 'preset_downloaded'
+ 'base' => 'presets_listed',
+ 'delete' => 'preset_deleted',
+ 'export' => 'preset_exported',
+ 'import' => 'preset_imported',
+ 'preview' => 'preset_previewed',
+ 'load' => 'preset_loaded',
+ 'rollback' => 'preset_reverted',
+ 'download_xml' => 'preset_downloaded'
);
protected $action;
protected $mode;
@@ -59,12 +77,12 @@ public function __construct() {
// DB - XML relations.
$this->rel = array('name' => 'NAME', 'comments' => 'COMMENTS',
- 'timecreated' => 'PRESET_DATE', 'site' => 'SITE_URL', 'author' => 'AUTHOR',
- 'moodleversion' => 'MOODLE_VERSION', 'moodlerelease' => 'MOODLE_RELEASE');
+ 'timecreated' => 'PRESET_DATE', 'site' => 'SITE_URL', 'author' => 'AUTHOR',
+ 'moodleversion' => 'MOODLE_VERSION', 'moodlerelease' => 'MOODLE_RELEASE');
// Sensible settings.
$sensiblesettings = explode(',',
- str_replace(' ', '', get_config('admin_presets', 'sensiblesettings')));
+ str_replace(' ', '', get_config('admin_presets', 'sensiblesettings')));
$this->sensiblesettings = array_combine($sensiblesettings, $sensiblesettings);
}
@@ -74,7 +92,7 @@ public function __construct() {
* It allows users to access the different preset
* actions (preview, load, download, delete and rollback)
*/
- public function show() {
+ public function show(): void {
global $CFG, $DB, $OUTPUT;
@@ -90,28 +108,28 @@ public function show() {
// Preset actions.
$previewlink = $CFG->wwwroot .
- '/admin/tool/admin_presets/index.php?action=load&mode=preview&id=' . $preset->id;
+ '/admin/tool/admin_presets/index.php?action=load&mode=preview&id=' . $preset->id;
$loadlink = $CFG->wwwroot .
- '/admin/tool/admin_presets/index.php?action=load&id=' . $preset->id;
+ '/admin/tool/admin_presets/index.php?action=load&id=' . $preset->id;
$downloadlink = $CFG->wwwroot .
- '/admin/tool/admin_presets/index.php?action=export&mode=download_xml&sesskey=' .
- sesskey() . '&id=' . $preset->id;
+ '/admin/tool/admin_presets/index.php?action=export&mode=download_xml&sesskey=' .
+ sesskey() . '&id=' . $preset->id;
$deletelink = $CFG->wwwroot .
- '/admin/tool/admin_presets/index.php?action=delete&id=' . $preset->id;
+ '/admin/tool/admin_presets/index.php?action=delete&id=' . $preset->id;
$rollbacklink = $CFG->wwwroot .
- '/admin/tool/admin_presets/index.php?action=rollback&id=' . $preset->id;
+ '/admin/tool/admin_presets/index.php?action=rollback&id=' . $preset->id;
$actions = array();
$actions[] = html_writer::link($previewlink, strtolower(get_string("preview")));
$actions[] = html_writer::link($loadlink, get_string("load",
- "tool_admin_presets"));
+ "tool_admin_presets"));
$actions[] = html_writer::link($downloadlink, strtolower(get_string("download")));
$actions[] = html_writer::link($deletelink, strtolower(get_string("delete")));
// Look for preset applications.
if ($DB->get_records('tool_admin_presets_app', array('adminpresetid' => $preset->id))) {
$actions[] = html_writer::link($rollbacklink,
- get_string("rollback", "tool_admin_presets"));
+ get_string("rollback", "tool_admin_presets"));
}
if ($preset->timeimported) {
@@ -122,13 +140,13 @@ public function show() {
// Populate table.
$table->data[] = array(format_text($preset->name, FORMAT_PLAIN),
- format_text($preset->comments, FORMAT_HTML),
- format_text($preset->moodlerelease, FORMAT_PLAIN),
- format_text($preset->author, FORMAT_PLAIN),
- format_text(clean_text($preset->site, PARAM_URL), FORMAT_PLAIN),
- userdate($preset->timecreated),
- $timeimportedstring,
- '' . implode('
', $actions) . '
');
+ format_text($preset->comments, FORMAT_HTML),
+ format_text($preset->moodlerelease, FORMAT_PLAIN),
+ format_text($preset->author, FORMAT_PLAIN),
+ format_text(clean_text($preset->site, PARAM_URL), FORMAT_PLAIN),
+ userdate($preset->timecreated),
+ $timeimportedstring,
+ '' . implode('
', $actions) . '
');
}
$this->outputs .= html_writer::table($table);
@@ -137,18 +155,18 @@ public function show() {
} else {
$exportlink = '' .
- strtolower(get_string("actionexport", "tool_admin_presets")) . '';
+ '/admin/tool/admin_presets/index.php?action=export">' .
+ strtolower(get_string("actionexport", "tool_admin_presets")) . '';
$importlink = '' .
- strtolower(get_string("actionimport", "tool_admin_presets")) . '';
+ $CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=import">' .
+ strtolower(get_string("actionimport", "tool_admin_presets")) . '';
$this->outputs = $OUTPUT->box_start('generalbox', 'id_nopresets');
$this->outputs .= '' . get_string('nopresets', 'tool_admin_presets');
$this->outputs .= '- ' . get_string('toexportclick',
- 'tool_admin_presets', $exportlink) . '
';
+ 'tool_admin_presets', $exportlink) . '';
$this->outputs .= '- ' . get_string('toimportclick',
- 'tool_admin_presets', $importlink) . '
';
+ 'tool_admin_presets', $importlink) . '';
$this->outputs .= '
';
$this->outputs .= $OUTPUT->box_end();
}
@@ -160,19 +178,18 @@ public function show() {
*
* @param boolean $actionstable If is set to true adds a column to display actions
* @return html_table
- * @throws coding_exception
*/
- protected function _create_preset_data_table($actionstable = true) {
+ protected function _create_preset_data_table($actionstable = true): html_table {
$table = new html_table();
$table->attributes['class'] = 'generaltable boxaligncenter';
$table->align = array('left', 'left', 'center', 'left', 'left', 'center', 'center');
$table->head = array(get_string('name'), get_string('description'),
- get_string('presetmoodlerelease', 'tool_admin_presets'),
- get_string('author', 'tool_admin_presets'),
- get_string('site', 'tool_admin_presets'),
- get_string('created', 'tool_admin_presets'),
- get_string('imported', 'tool_admin_presets'));
+ get_string('presetmoodlerelease', 'tool_admin_presets'),
+ get_string('author', 'tool_admin_presets'),
+ get_string('site', 'tool_admin_presets'),
+ get_string('created', 'tool_admin_presets'),
+ get_string('imported', 'tool_admin_presets'));
if ($actionstable) {
$table->align[] = 'left';
@@ -193,7 +210,7 @@ protected function _create_preset_data_table($actionstable = true) {
*
* $outputs value depends on $mode and $action selected
*/
- public function display() {
+ public function display(): void {
global $OUTPUT;
$this->_display_header();
@@ -215,7 +232,7 @@ public function display() {
/**
* Displays the header
*/
- protected function _display_header() {
+ protected function _display_header(): void {
global $CFG, $PAGE, $OUTPUT, $SITE;
@@ -229,7 +246,7 @@ protected function _display_header() {
$PAGE->set_heading($SITE->fullname);
$PAGE->navbar->add(get_string('pluginname', 'tool_admin_presets'),
- new moodle_url($CFG->wwwroot . '/admin/tool/admin_presets/index.php'));
+ new moodle_url($CFG->wwwroot . '/admin/tool/admin_presets/index.php'));
$PAGE->navbar->add($actionstr . ': ' . $modestr);
@@ -240,12 +257,12 @@ protected function _display_header() {
echo $OUTPUT->heading($actionstr . ': ' . $modestr, 1);
}
- public function log() {
+ public function log(): void {
// TODO please, me of the future, fix this ununderstandable code.
// The only read action we store is list presets.
if ($this->mode != 'show' ||
- ($this->mode == 'show' && $this->action == 'base')) {
+ ($this->mode == 'show' && $this->action == 'base')) {
$action = $this->action;
if ($this->mode != 'execute' && $this->mode != 'show') {
@@ -254,8 +271,8 @@ public function log() {
$eventnamespace = '\\tool_admin_presets\\event\\' . self::$eventsactionsmap[$action];
$eventdata = array(
- 'context' => context_system::instance(),
- 'objectid' => $this->id
+ 'context' => context_system::instance(),
+ 'objectid' => $this->id
);
$event = $eventnamespace::create($eventdata);
$event->trigger();
@@ -269,10 +286,9 @@ public function log() {
* $CFG->prefix.'config_plugins' values and redirects
* the flow through $this->_get_settings()
*
- * @return array $settings Array format $array['plugin']['settingname'] = admin_preset_setting child class
- * @throws dml_exception
+ * @return array $settings Array format $array['plugin']['settingname'] = settings_types child class
*/
- protected function _get_site_settings() {
+ protected function _get_site_settings(): array {
global $DB;
@@ -281,7 +297,7 @@ protected function _get_site_settings() {
// Adding site settings in course table.
$frontpagevalues = $DB->get_record_select('course', 'id = 1',
- array(), 'fullname, shortname, summary');
+ array(), 'fullname, shortname, summary');
foreach ($frontpagevalues as $field => $value) {
$dbconfig[$field] = new StdClass();
$dbconfig[$field]->name = $field;
@@ -314,12 +330,11 @@ protected function _get_site_settings() {
* @param array $dbsettings Standarized array,
* format $array['plugin']['name'] = obj('name'=>'settingname', 'value'=>'settingvalue')
* @param boolean $sitedbvalues Indicates if $dbsettings comes from the site db or not
- * @param array $settings Array format $array['plugin']['settingname'] = admin_preset_setting child class
+ * @param array $settings Array format $array['plugin']['settingname'] = settings_types child class
* @param bool $children admin_category children
- * @return array Array format $array['plugin']['settingname'] = admin_preset_setting child class
- * @throws dml_exception
+ * @return array Array format $array['plugin']['settingname'] = settings_types child class
*/
- protected function _get_settings($dbsettings, $sitedbvalues = false, $settings, $children = false) {
+ protected function _get_settings($dbsettings, $sitedbvalues = false, $settings, $children = false): array {
global $DB;
// If there are no children, load admin tree and iterate through.
@@ -382,15 +397,15 @@ protected function _get_settings($dbsettings, $sitedbvalues = false, $settings,
continue;
}
- // Admin_preset_setting childs with.
- // attributes provides an attributes array.
+ // settings_types childs with.
+ // attributes provides an attributes array.
if ($attributes = $setting->get_attributes()) {
// Look for settings attributes if it is a presets.
if (!$sitedbvalues) {
$itemid = $dbsettings[$values->plugin][$settingname]->itemid;
$attrs = $DB->get_records('tool_admin_presets_it_a',
- array('itemid' => $itemid), '', 'name, value');
+ array('itemid' => $itemid), '', 'name, value');
}
foreach ($attributes as $defaultvarname => $varname) {
@@ -439,7 +454,7 @@ protected function _get_settings($dbsettings, $sitedbvalues = false, $settings,
*
* @param object $settingdata Setting data
* @param mixed $currentvalue
- * @return bool
+ * @return mixed
*/
protected function _get_setting($settingdata, $currentvalue) {
@@ -451,20 +466,19 @@ protected function _get_setting($settingdata, $currentvalue) {
// TODO: Implement all the settings types.
if (!class_exists($classname)) {
+ var_dump($classname);
return false;
}
- $setting = new $classname($settingdata, $currentvalue);
-
- return $setting;
+ return new $classname($settingdata, $currentvalue);
}
/**
* Gets the javascript to populate the settings tree
*
- * @param array $settings Array format $array['plugin']['settingname'] = admin_preset_setting child class
+ * @param array $settings Array format $array['plugin']['settingname'] = settings_types child class
*/
- protected function _get_settings_branches($settings) {
+ protected function _get_settings_branches($settings): void {
global $PAGE;
@@ -485,20 +499,20 @@ protected function _get_settings_branches($settings) {
}
}
$PAGE->requires->js_init_call('M.tool_admin_presets.addNodes',
- array($ids, $nodes, $labels, $descriptions, $parents), true);
+ array($ids, $nodes, $labels, $descriptions, $parents), true);
$PAGE->requires->js_init_call('M.tool_admin_presets.render', null, true);
}
/**
* Gets the html code to select the settings to export/import/load
*
- * @param array $allsettings Array format $array['plugin']['settingname'] = admin_preset_setting child class
+ * @param array $allsettings Array format $array['plugin']['settingname'] = settings_types child class
* @param bool $admintree The admin tree branche object or false if we are in the root
* @param bool $jsparentnode Name of the javascript parent category node
* @param array $nodes Tree nodes
* @return array Code to output
*/
- protected function _get_settings_elements($allsettings, $admintree = false, $jsparentnode = false, &$nodes) {
+ protected function _get_settings_elements($allsettings, $admintree = false, $jsparentnode = false, &$nodes): array {
if (empty($this->adminroot)) {
$this->adminroot = admin_get_root(false, true);
@@ -525,7 +539,7 @@ protected function _get_settings_elements($allsettings, $admintree = false, $jsp
$categorynode = $child->name . 'Node';
$nodehtml = '' . $child->visiblename . '
';
$nodes['categories'][$categorynode] = array("category",
- $categorynode, (String) $nodehtml, "", $jsparentnode);
+ $categorynode, (string) $nodehtml, "", $jsparentnode);
// Not all admin_categories have admin_settingpages.
$this->_get_settings_elements($allsettings, $child->children, $categorynode, $nodes);
@@ -557,13 +571,13 @@ protected function _get_settings_elements($allsettings, $admintree = false, $jsp
// String to add the setting to js tree.
$pagesettings[$settingid] = array($settingid, $settingid,
- $setting->get_text(), $setting->get_description(), $pagenode);
+ $setting->get_text(), $setting->get_description(), $pagenode);
}
// The page node only should be added if it have children.
if ($pagesettings) {
$nodehtml = '' . $child->visiblename . '
';
- $nodes['pages'][$pagenode] = array("page", $pagenode, (String) $nodehtml, "", $jsparentnode);
+ $nodes['pages'][$pagenode] = array("page", $pagenode, (string) $nodehtml, "", $jsparentnode);
$nodes['settings'] = array_merge($nodes['settings'], $pagesettings);
}
}
@@ -580,13 +594,13 @@ protected function _get_settings_elements($allsettings, $admintree = false, $jsp
* @return array Standarized array,
* format $array['plugin']['name'] = obj('name'=>'settingname', 'value'=>'settingvalue')
*/
- protected function _get_settings_from_db($dbsettings) {
+ protected function _get_settings_from_db($dbsettings): array {
+ $settings = array();
if (!$dbsettings) {
- return false;
+ return $settings;
}
- $settings = array();
foreach ($dbsettings as $dbsetting) {
$settings[$dbsetting->plugin][$dbsetting->name] = new StdClass();
$settings[$dbsetting->plugin][$dbsetting->name]->itemid = $dbsetting->id;
@@ -597,22 +611,22 @@ protected function _get_settings_from_db($dbsettings) {
return $settings;
}
- protected function _output_applied_changes($appliedchanges) {
+ protected function _output_applied_changes($appliedchanges): void {
$appliedtable = new html_table();
$appliedtable->attributes['class'] = 'generaltable boxaligncenter admin_presets_applied';
$appliedtable->head = array(get_string('plugin'),
- get_string('settingname', 'tool_admin_presets'),
- get_string('oldvalue', 'tool_admin_presets'),
- get_string('newvalue', 'tool_admin_presets'));
+ get_string('settingname', 'tool_admin_presets'),
+ get_string('oldvalue', 'tool_admin_presets'),
+ get_string('newvalue', 'tool_admin_presets'));
$appliedtable->align = array('center', 'center');
foreach ($appliedchanges as $setting) {
$appliedtable->data[] = array($setting->plugin,
- $setting->visiblename,
- $setting->oldvisiblevalue,
- $setting->visiblevalue);
+ $setting->visiblename,
+ $setting->oldvisiblevalue,
+ $setting->visiblevalue);
}
$this->outputs .= html_writer::table($appliedtable);
@@ -622,10 +636,9 @@ protected function _output_applied_changes($appliedchanges) {
* Returns a table with the preset data
*
* @param object $preset
- * @return string|string
- * @throws coding_exception
+ * @return string
*/
- protected function _html_writer_preset_info_table($preset) {
+ protected function _html_writer_preset_info_table($preset): string {
if (!$preset) {
return '';
@@ -638,12 +651,12 @@ protected function _html_writer_preset_info_table($preset) {
}
$infotable = $this->_create_preset_data_table(false);
$infotable->data[] = array(format_text($preset->name, FORMAT_PLAIN),
- format_text($preset->comments, FORMAT_HTML),
- format_text($preset->moodlerelease, FORMAT_PLAIN),
- format_text($preset->author, FORMAT_PLAIN),
- format_text(clean_text($preset->site, PARAM_URL), FORMAT_PLAIN),
- userdate($preset->timecreated),
- $timeimportedstring);
+ format_text($preset->comments, FORMAT_HTML),
+ format_text($preset->moodlerelease, FORMAT_PLAIN),
+ format_text($preset->author, FORMAT_PLAIN),
+ format_text(clean_text($preset->site, PARAM_URL), FORMAT_PLAIN),
+ userdate($preset->timecreated),
+ $timeimportedstring);
return html_writer::table($infotable);
}
diff --git a/admin/tool/admin_presets/lib/admin_presets_delete.class.php b/admin/tool/admin_presets/classes/delete.php
old mode 100755
new mode 100644
similarity index 76%
rename from admin/tool/admin_presets/lib/admin_presets_delete.class.php
rename to admin/tool/admin_presets/classes/delete.php
index ba095fc98e1f7..3f0b3cd9e2956
--- a/admin/tool/admin_presets/lib/admin_presets_delete.class.php
+++ b/admin/tool/admin_presets/classes/delete.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+ * Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -24,16 +24,29 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace admin_tool_presets;
+
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->dirroot . '/admin/tool/admin_presets/lib/admin_presets_base.class.php');
+global $CFG;
+
+require_once($CFG->dirroot . '/admin/tool/admin_presets/classes/base.php');
-class admin_presets_delete extends admin_presets_base {
+/**
+ * Admin tool presets plugin this class extend base class and handle delete function.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class delete extends base {
/**
* Shows a confirm box
*/
- public function show() {
+ public function show(): void {
global $DB, $CFG, $OUTPUT;
@@ -42,15 +55,15 @@ public function show() {
$deletetext = get_string("deletepreset", "tool_admin_presets", $presetdata->name);
$confirmurl = $CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=' .
- $this->action . '&mode=execute&id=' . $this->id . '&sesskey=' . sesskey();
+ $this->action . '&mode=execute&id=' . $this->id . '&sesskey=' . sesskey();
$cancelurl = $CFG->wwwroot . '/admin/tool/admin_presets/index.php';
// If the preset was applied add a warning text.
if ($previouslyapplied = $DB->get_records('tool_admin_presets_app',
- array('adminpresetid' => $this->id))) {
+ array('adminpresetid' => $this->id))) {
$deletetext .= '
' .
- get_string("deletepreviouslyapplied", "tool_admin_presets") . '';
+ get_string("deletepreviouslyapplied", "tool_admin_presets") . '';
}
$this->outputs = $OUTPUT->confirm($deletetext, $confirmurl, $cancelurl);
@@ -59,7 +72,7 @@ public function show() {
/**
* Delete the DB preset
*/
- public function execute() {
+ public function execute(): void {
global $DB, $CFG;
@@ -81,27 +94,27 @@ public function execute() {
// Deleting the preset applications.
if ($previouslyapplied = $DB->get_records('tool_admin_presets_app',
- array('adminpresetid' => $this->id), 'id')) {
+ array('adminpresetid' => $this->id), 'id')) {
foreach ($previouslyapplied as $application) {
// Deleting items.
if (!$DB->delete_records('tool_admin_presets_app_it',
- array('adminpresetapplyid' => $application->id))) {
+ array('adminpresetapplyid' => $application->id))) {
print_error('errordeleting', 'tool_admin_presets');
}
// Deleting attributes.
if (!$DB->delete_records('tool_admin_presets_app_it_a',
- array('adminpresetapplyid' => $application->id))) {
+ array('adminpresetapplyid' => $application->id))) {
print_error('errordeleting', 'tool_admin_presets');
}
}
if (!$DB->delete_records('tool_admin_presets_app',
- array('adminpresetid' => $this->id))) {
+ array('adminpresetid' => $this->id))) {
print_error('errordeleting', 'tool_admin_presets');
}
@@ -113,4 +126,4 @@ public function execute() {
redirect($CFG->wwwroot . '/admin/tool/admin_presets/index.php');
}
-}
+}
\ No newline at end of file
diff --git a/admin/tool/admin_presets/classes/event/preset_deleted.php b/admin/tool/admin_presets/classes/event/preset_deleted.php
index 72e20fe44d644..e57f022df19b0 100755
--- a/admin/tool/admin_presets/classes/event/preset_deleted.php
+++ b/admin/tool/admin_presets/classes/event/preset_deleted.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+ * Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -26,24 +26,35 @@
namespace tool_admin_presets\event;
+use core\event\base;
+
defined('MOODLE_INTERNAL') || die();
-class preset_deleted extends \core\event\base {
+/**
+ * Admin tool presets event class deleted.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class preset_deleted extends base {
- public static function get_name() {
+ public static function get_name(): string {
return get_string('eventpresetdeleted', 'tool_admin_presets');
}
- public function get_description() {
+ public function get_description(): string {
return "User {$this->userid} has deleted the preset with id {$this->objectid}.";
}
- public function get_legacy_logdata() {
+ public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'delete', '',
- $this->objectid, $this->contextinstanceid);
+ $this->objectid, $this->contextinstanceid);
}
- protected function init() {
+ protected function init(): void {
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
diff --git a/admin/tool/admin_presets/classes/event/preset_downloaded.php b/admin/tool/admin_presets/classes/event/preset_downloaded.php
index ba8cdc8489032..d8fbf87d0d18b 100755
--- a/admin/tool/admin_presets/classes/event/preset_downloaded.php
+++ b/admin/tool/admin_presets/classes/event/preset_downloaded.php
@@ -14,26 +14,47 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+/**
+ * Admin tool presets plugin to load some settings.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
namespace tool_admin_presets\event;
+use core\event\base;
+
defined('MOODLE_INTERNAL') || die();
-class preset_downloaded extends \core\event\base {
+/**
+ * Admin tool presets event class downloaded.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class preset_downloaded extends base {
- public static function get_name() {
+ public static function get_name(): string {
return get_string('eventpresetdownloaded', 'tool_admin_presets');
}
- public function get_description() {
+ public function get_description(): string {
return "User {$this->userid} has downloaded the preset with id {$this->objectid}.";
}
- public function get_url() {
+ public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
- array('action' => 'export', 'mode' => 'download_xml', 'id' => $this->objectid, 'sesskey' => sesskey()));
+ array('action' => 'export', 'mode' => 'download_xml', 'id' => $this->objectid, 'sesskey' => sesskey()));
}
- protected function init() {
+ protected function init(): void {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
diff --git a/admin/tool/admin_presets/classes/event/preset_exported.php b/admin/tool/admin_presets/classes/event/preset_exported.php
index 18a3b6d9c5024..8e5e0d698bbac 100755
--- a/admin/tool/admin_presets/classes/event/preset_exported.php
+++ b/admin/tool/admin_presets/classes/event/preset_exported.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+ * Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -26,29 +26,40 @@
namespace tool_admin_presets\event;
+use core\event\base;
+
defined('MOODLE_INTERNAL') || die();
-class preset_exported extends \core\event\base {
+/**
+ * Admin tool presets event class exported.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class preset_exported extends base {
- public static function get_name() {
+ public static function get_name(): string {
return get_string('eventpresetexported', 'tool_admin_presets');
}
- public function get_description() {
+ public function get_description(): string {
return "User {$this->userid} has exported the preset with id {$this->objectid}.";
}
- public function get_url() {
+ public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
- array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
+ array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
}
- public function get_legacy_logdata() {
+ public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'export', '',
- $this->objectid, $this->contextinstanceid);
+ $this->objectid, $this->contextinstanceid);
}
- protected function init() {
+ protected function init(): void {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
diff --git a/admin/tool/admin_presets/classes/event/preset_imported.php b/admin/tool/admin_presets/classes/event/preset_imported.php
index 2ba3aac012c59..72ce726490a3e 100755
--- a/admin/tool/admin_presets/classes/event/preset_imported.php
+++ b/admin/tool/admin_presets/classes/event/preset_imported.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+ * Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -26,29 +26,40 @@
namespace tool_admin_presets\event;
+use core\event\base;
+
defined('MOODLE_INTERNAL') || die();
-class preset_imported extends \core\event\base {
+/**
+ * Admin tool presets event class imported.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class preset_imported extends base {
- public static function get_name() {
+ public static function get_name(): string {
return get_string('eventpresetimported', 'tool_admin_presets');
}
- public function get_description() {
+ public function get_description(): string {
return "User {$this->userid} has imported the preset with id {$this->objectid}.";
}
- public function get_url() {
+ public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
- array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
+ array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
}
- public function get_legacy_logdata() {
+ public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'import', '',
- $this->objectid, $this->contextinstanceid);
+ $this->objectid, $this->contextinstanceid);
}
- protected function init() {
+ protected function init(): void {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
diff --git a/admin/tool/admin_presets/classes/event/preset_loaded.php b/admin/tool/admin_presets/classes/event/preset_loaded.php
index 67cab6a436d95..2e7314f56033d 100755
--- a/admin/tool/admin_presets/classes/event/preset_loaded.php
+++ b/admin/tool/admin_presets/classes/event/preset_loaded.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+ * Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -26,29 +26,40 @@
namespace tool_admin_presets\event;
+use core\event\base;
+
defined('MOODLE_INTERNAL') || die();
-class preset_loaded extends \core\event\base {
+/**
+ * Admin tool presets event class loaded.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class preset_loaded extends base {
- public static function get_name() {
+ public static function get_name(): string {
return get_string('eventpresetloaded', 'tool_admin_presets');
}
- public function get_description() {
+ public function get_description(): string {
return "User {$this->userid} has loaded the preset with id {$this->objectid}.";
}
- public function get_url() {
+ public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
- array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
+ array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
}
- public function get_legacy_logdata() {
+ public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'load', '',
- $this->objectid, $this->contextinstanceid);
+ $this->objectid, $this->contextinstanceid);
}
- protected function init() {
+ protected function init(): void {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
diff --git a/admin/tool/admin_presets/classes/event/preset_previewed.php b/admin/tool/admin_presets/classes/event/preset_previewed.php
index cbdc9aa81e623..3bf33bed2d105 100755
--- a/admin/tool/admin_presets/classes/event/preset_previewed.php
+++ b/admin/tool/admin_presets/classes/event/preset_previewed.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+ * Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -26,24 +26,35 @@
namespace tool_admin_presets\event;
+use core\event\base;
+
defined('MOODLE_INTERNAL') || die();
-class preset_previewed extends \core\event\base {
+/**
+ * Admin tool presets event class previewed.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class preset_previewed extends base {
- public static function get_name() {
+ public static function get_name(): string {
return get_string('eventpresetpreviewed', 'tool_admin_presets');
}
- public function get_description() {
+ public function get_description(): string {
return "User {$this->userid} has previewed the preset with id {$this->objectid}.";
}
- public function get_url() {
+ public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
- array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
+ array('action' => 'load', 'mode' => 'preview', 'id' => $this->objectid));
}
- protected function init() {
+ protected function init(): void {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
diff --git a/admin/tool/admin_presets/classes/event/preset_reverted.php b/admin/tool/admin_presets/classes/event/preset_reverted.php
index 0f1e5d4aef763..3b0f5a7b5f5ad 100755
--- a/admin/tool/admin_presets/classes/event/preset_reverted.php
+++ b/admin/tool/admin_presets/classes/event/preset_reverted.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+ * Admin tool presets plugin to load some settings
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -26,24 +26,35 @@
namespace tool_admin_presets\event;
+use core\event\base;
+
defined('MOODLE_INTERNAL') || die();
-class preset_reverted extends \core\event\base {
+/**
+ * Admin tool presets event class reverted.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class preset_reverted extends base {
- public static function get_name() {
+ public static function get_name(): string {
return get_string('eventpresetreverted', 'tool_admin_presets');
}
- public function get_description() {
+ public function get_description(): string {
return "User {$this->userid} has reverted the preset with id {$this->objectid}.";
}
- public function get_legacy_logdata() {
+ public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'rollback', '',
- $this->objectid, $this->contextinstanceid);
+ $this->objectid, $this->contextinstanceid);
}
- protected function init() {
+ protected function init(): void {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
diff --git a/admin/tool/admin_presets/classes/event/presets_listed.php b/admin/tool/admin_presets/classes/event/presets_listed.php
index fd79d94ec9b5c..ce5bc1dcda381 100755
--- a/admin/tool/admin_presets/classes/event/presets_listed.php
+++ b/admin/tool/admin_presets/classes/event/presets_listed.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+ * Admin tool presets plugin to load some settings
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -26,28 +26,39 @@
namespace tool_admin_presets\event;
+use core\event\base;
+
defined('MOODLE_INTERNAL') || die();
-class presets_listed extends \core\event\base {
+/**
+ * Admin tool presets event class listed.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class presets_listed extends base {
- public static function get_name() {
+ public static function get_name(): string {
return get_string('eventpresetslisted', 'tool_admin_presets');
}
- public function get_description() {
+ public function get_description(): string {
return "User {$this->userid} listed the system presets.";
}
- public function get_url() {
+ public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php');
}
- public function get_legacy_logdata() {
+ public function get_legacy_logdata(): array {
return array($this->courseid, 'tool_admin_presets', 'base', '',
- $this->objectid, $this->contextinstanceid);
+ $this->objectid, $this->contextinstanceid);
}
- protected function init() {
+ protected function init(): void {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'tool_admin_presets';
diff --git a/admin/tool/admin_presets/lib/admin_presets_export.class.php b/admin/tool/admin_presets/classes/export.php
similarity index 86%
rename from admin/tool/admin_presets/lib/admin_presets_export.class.php
rename to admin/tool/admin_presets/classes/export.php
index 5f3b5e70ede17..85900495a6746 100755
--- a/admin/tool/admin_presets/lib/admin_presets_export.class.php
+++ b/admin/tool/admin_presets/classes/export.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+ * Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -24,14 +24,33 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace admin_tool_presets;
+
+use \StdClass;
+use admin_tool_presets\forms\export_form;
+use memory_xml_output;
+use xml_writer;
+
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->dirroot . '/admin/tool/admin_presets/lib/admin_presets_base.class.php');
+global $CFG;
+
+require_once($CFG->dirroot . '/admin/tool/admin_presets/classes/base.php');
+require_once($CFG->dirroot . '/admin/tool/admin_presets/forms/export_form.php');
require_once($CFG->dirroot . '/backup/util/xml/xml_writer.class.php');
require_once($CFG->dirroot . '/backup/util/xml/output/xml_output.class.php');
require_once($CFG->dirroot . '/backup/util/xml/output/memory_xml_output.class.php');
-class admin_presets_export extends admin_presets_base {
+/**
+ * Admin tool presets plugin this class extend base class and handle export function.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class export extends base {
/**
* Shows the initial form to export/save admin settings
@@ -39,7 +58,7 @@ class admin_presets_export extends admin_presets_base {
* Loads the database configuration and prints
* the settings in a hierical table
*/
- public function show() {
+ public function show(): void {
global $CFG;
@@ -48,27 +67,27 @@ public function show() {
$this->_get_settings_branches($settings);
$url = $CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=export&mode=execute';
- $this->moodleform = new admin_presets_export_form($url);
+ $this->moodleform = new export_form($url);
}
/**
* Stores the preset into the DB
*/
- public function execute() {
+ public function execute(): void {
global $CFG, $USER, $DB;
confirm_sesskey();
$url = $CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=export&mode=execute';
- $this->moodleform = new admin_presets_export_form($url);
+ $this->moodleform = new export_form($url);
// Reload site settings.
$sitesettings = $this->_get_site_settings();
if ($data = $this->moodleform->get_data()) {
- // admin_preset record.
+ // Admin_preset record.
$preset = new StdClass();
$preset->userid = $USER->id;
$preset->name = $data->name;
@@ -113,12 +132,12 @@ public function execute() {
// Setting attributes must also be exported.
if ($attributes = $sitesettings[$setting->plugin][$setting->name]->get_attributes_values()) {
- foreach ($attributes as $attributename => $value) {
+ foreach ($attributes as $attributename => $valueattr) {
$attr = new StdClass();
$attr->itemid = $setting->id;
$attr->name = $attributename;
- $attr->value = $value;
+ $attr->value = $valueattr;
$DB->insert_record('tool_admin_presets_it_a', $attr);
}
@@ -130,7 +149,7 @@ public function execute() {
if (empty($settingsfound)) {
$DB->delete_records('tool_admin_presets', array('id' => $preset->id));
redirect($CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=export',
- get_string('novalidsettingsselected', 'tool_admin_presets'), 4);
+ get_string('novalidsettingsselected', 'tool_admin_presets'), 4);
}
}
@@ -149,7 +168,7 @@ public function execute() {
* @throws xml_output_exception
* @throws xml_writer_exception
*/
- public function download_xml() {
+ public function download_xml(): void {
global $DB;
@@ -221,7 +240,7 @@ public function download_xml() {
$xmlwriter->end_tag('ADMIN_SETTINGS');
}
- // End
+ // End.
$xmlwriter->end_tag('PRESET');
$xmlwriter->stop();
$xmlstr = $xmloutput->get_allcontents();
diff --git a/admin/tool/admin_presets/lib/admin_presets_import.class.php b/admin/tool/admin_presets/classes/import.php
similarity index 87%
rename from admin/tool/admin_presets/lib/admin_presets_import.class.php
rename to admin/tool/admin_presets/classes/import.php
index 50c8300891432..a981bae32458c 100755
--- a/admin/tool/admin_presets/lib/admin_presets_import.class.php
+++ b/admin/tool/admin_presets/classes/import.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -24,27 +24,45 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace admin_tool_presets;
+
+use \StdClass;
+use admin_tool_presets\forms\import_form;
+use context_user;
+
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->dirroot . '/admin/tool/admin_presets/lib/admin_presets_base.class.php');
+global $CFG;
+
+require_once($CFG->dirroot . '/admin/tool/admin_presets/classes/base.php');
+require_once($CFG->dirroot . '/admin/tool/admin_presets/forms/import_form.php');
-class admin_presets_import extends admin_presets_base {
+/**
+ * Admin tool presets plugin this class extend base class and handle import function.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class import extends base {
/**
* Displays the import moodleform
*/
- public function show() {
+ public function show(): void {
global $CFG;
$url = $CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=import&mode=execute';
- $this->moodleform = new admin_presets_import_form($url);
+ $this->moodleform = new import_form($url);
}
/**
* Imports the xmlfile into DB
*/
- public function execute() {
+ public function execute(): void {
global $CFG, $USER, $DB;
@@ -53,7 +71,7 @@ public function execute() {
$sitesettings = $this->_get_site_settings();
$url = $CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=import&mode=execute';
- $this->moodleform = new admin_presets_import_form($url);
+ $this->moodleform = new import_form($url);
if ($data = $this->moodleform->get_data()) {
diff --git a/admin/tool/admin_presets/lib/admin_presets_load.class.php b/admin/tool/admin_presets/classes/load.php
similarity index 85%
rename from admin/tool/admin_presets/lib/admin_presets_load.class.php
rename to admin/tool/admin_presets/classes/load.php
index 0facf4218ac4c..a7718e781a1d0 100755
--- a/admin/tool/admin_presets/lib/admin_presets_load.class.php
+++ b/admin/tool/admin_presets/classes/load.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -24,23 +24,43 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace admin_tool_presets;
+
+use \StdClass;
+use admin_tool_presets\forms\load_form;
+
+use html_table;
+use html_writer;
+
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->dirroot . '/admin/tool/admin_presets/lib/admin_presets_base.class.php');
+global $CFG;
-class admin_presets_load extends admin_presets_base {
+require_once($CFG->dirroot . '/admin/tool/admin_presets/classes/base.php');
+require_once($CFG->dirroot . '/admin/tool/admin_presets/forms/load_form.php');
+
+/**
+ * Admin tool presets plugin this class extend base class and handle load function.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class load extends base {
/**
* Executes the settings load into the system
*/
- public function execute() {
+ public function execute(): void {
global $CFG, $DB, $OUTPUT, $USER;
confirm_sesskey();
$url = $CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=load&mode=execute';
- $this->moodleform = new admin_presets_load_form($url);
+ $this->moodleform = new load_form($url);
if ($data = $this->moodleform->get_data()) {
@@ -83,8 +103,8 @@ public function execute() {
// Wrong setting, set_value() method has previously cleaned the value.
if ($presetsetting->get_value() === false) {
debugging($presetsetting->get_settingdata()->plugin . '/' .
- $presetsetting->get_settingdata()->name .
- ' setting has a wrong value!', DEBUG_DEVELOPER);
+ $presetsetting->get_settingdata()->name .
+ ' setting has a wrong value!', DEBUG_DEVELOPER);
continue;
}
@@ -116,7 +136,7 @@ public function execute() {
$presetapplied->userid = $USER->id;
$presetapplied->time = time();
if (!$adminpresetapplyid = $DB->insert_record('tool_admin_presets_app',
- $presetapplied)) {
+ $presetapplied)) {
print_error('errorinserting', 'tool_admin_presets');
}
}
@@ -159,11 +179,11 @@ public function execute() {
// Output applied changes.
if (!empty($appliedchanges)) {
$this->outputs .= '
' . $OUTPUT->heading(get_string('settingsapplied',
- 'tool_admin_presets'), 3, 'admin_presets_success');
+ 'tool_admin_presets'), 3, 'admin_presets_success');
$this->_output_applied_changes($appliedchanges);
} else {
$this->outputs .= '
' . $OUTPUT->heading(get_string('nothingloaded',
- 'tool_admin_presets'), 3, 'admin_presets_error');
+ 'tool_admin_presets'), 3, 'admin_presets_error');
}
// Show skipped changes.
@@ -172,19 +192,19 @@ public function execute() {
$skippedtable = new html_table();
$skippedtable->attributes['class'] = 'generaltable boxaligncenter admin_presets_skipped';
$skippedtable->head = array(get_string('plugin'),
- get_string('settingname', 'tool_admin_presets'),
- get_string('actualvalue', 'tool_admin_presets')
+ get_string('settingname', 'tool_admin_presets'),
+ get_string('actualvalue', 'tool_admin_presets')
);
$skippedtable->align = array('center', 'center');
$this->outputs .= '
' . $OUTPUT->heading(get_string('settingsnotapplied',
- 'tool_admin_presets'), 3);
+ 'tool_admin_presets'), 3);
foreach ($unnecessarychanges as $setting) {
$skippedtable->data[] = array($setting->get_settingdata()->plugin,
- $setting->get_settingdata()->visiblename,
- $setting->get_visiblevalue()
+ $setting->get_settingdata()->visiblename,
+ $setting->get_visiblevalue()
);
}
@@ -198,7 +218,7 @@ public function execute() {
/**
* Lists the preset available settings
*/
- public function preview() {
+ public function preview(): void {
$this->show(1);
}
@@ -211,11 +231,8 @@ public function preview() {
* to import the preset available settings
*
* @param boolean $preview If it's a preview it only lists the preset applicable settings
- * @throws coding_exception
- * @throws dml_exception
- * @throws moodle_exception
*/
- public function show($preview = false) {
+ public function show($preview = false): void {
global $CFG, $DB, $OUTPUT;
@@ -266,13 +283,13 @@ public function show($preview = false) {
if (!empty($notapplicable)) {
$this->outputs .= '
' . $OUTPUT->heading(get_string('settingsnotapplicable',
- 'tool_admin_presets'), 3, 'admin_presets_error');
+ 'tool_admin_presets'), 3, 'admin_presets_error');
$table = new html_table();
$table->attributes['class'] = 'generaltable boxaligncenter';
$table->head = array(get_string('plugin'),
- get_string('settingname', 'tool_admin_presets'),
- get_string('value', 'tool_admin_presets'));
+ get_string('settingname', 'tool_admin_presets'),
+ get_string('value', 'tool_admin_presets'));
$table->align = array('center', 'center');
@@ -285,7 +302,7 @@ public function show($preview = false) {
}
$url = $CFG->wwwroot . '/admin/tool/admin_presets/index.php?action=load&mode=execute';
- $this->moodleform = new admin_presets_load_form($url, $preview);
+ $this->moodleform = new load_form($url, $preview);
$this->moodleform->set_data($data);
}
diff --git a/admin/tool/admin_presets/classes/privacy/provider.php b/admin/tool/admin_presets/classes/privacy/provider.php
index 69bcf85168be7..bf9bd6aa5c3c0 100755
--- a/admin/tool/admin_presets/classes/privacy/provider.php
+++ b/admin/tool/admin_presets/classes/privacy/provider.php
@@ -14,15 +14,34 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+/**
+ * Admin tool presets plugin to load some settings.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
namespace tool_admin_presets\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\metadata\null_provider;
+/**
+ * Admin tool presets this file handle privacy provider.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
class provider implements
- // This plugin does not store any personal user data.
- null_provider {
+ // This plugin does not store any personal user data.
+ null_provider {
/**
* Get the language string identifier with the component's language
@@ -30,7 +49,7 @@ class provider implements
*
* @return string
*/
- public static function get_reason() : string {
+ public static function get_reason(): string {
return 'privacy:null_reason';
}
}
diff --git a/admin/tool/admin_presets/lib/admin_presets_rollback.class.php b/admin/tool/admin_presets/classes/rollback.php
similarity index 93%
rename from admin/tool/admin_presets/lib/admin_presets_rollback.class.php
rename to admin/tool/admin_presets/classes/rollback.php
index f0eb4361065c4..a67e5d5208535 100755
--- a/admin/tool/admin_presets/lib/admin_presets_rollback.class.php
+++ b/admin/tool/admin_presets/classes/rollback.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -24,16 +24,33 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace admin_tool_presets;
+
+use html_table;
+use html_writer;
+use \stdClass;
+
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->dirroot . '/admin/tool/admin_presets/lib/admin_presets_base.class.php');
+global $CFG;
+
+require_once($CFG->dirroot . '/admin/tool/admin_presets/classes/base.php');
-class admin_presets_rollback extends admin_presets_base {
+/**
+ * Admin tool presets plugin this class extend base class and handle rollback function.
+ *
+ * @package tool_admin_presets
+ * @copyright 2021 Pimenko
+ * @author Jordan Kesraoui | Sylvain Revenu | Pimenko
+ * @orignalauthor David Monllaó
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class rollback extends base {
/**
* Displays the different previous applications of the preset
*/
- public function show() {
+ public function show(): void {
global $CFG, $DB, $OUTPUT;
@@ -80,7 +97,7 @@ public function show() {
*
* Each setting value is checked against the config_log->value
*/
- public function execute() {
+ public function execute(): void {
global $DB, $OUTPUT;
diff --git a/admin/tool/admin_presets/db/upgrade.php b/admin/tool/admin_presets/db/upgrade.php
index 712ca8da92c31..cbf5b5e946122 100755
--- a/admin/tool/admin_presets/db/upgrade.php
+++ b/admin/tool/admin_presets/db/upgrade.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -28,18 +28,9 @@
/**
* @param int $oldversion
- * @param object $tool
* @return bool
- * @throws coding_exception
- * @throws ddl_exception
- * @throws ddl_field_missing_exception
- * @throws ddl_table_missing_exception
- * @throws downgrade_exception
- * @throws moodle_exception
- * @throws upgrade_exception
- * @global moodle_database $DB
*/
-function xmldb_tool_admin_presets_upgrade($oldversion, $tool) {
+function xmldb_tool_admin_presets_upgrade($oldversion): bool {
return true;
}
diff --git a/admin/tool/admin_presets/forms/admin_presets_export_form.php b/admin/tool/admin_presets/forms/export_form.php
similarity index 77%
rename from admin/tool/admin_presets/forms/admin_presets_export_form.php
rename to admin/tool/admin_presets/forms/export_form.php
index f025487f86d1d..efc6e1f3629cc 100755
--- a/admin/tool/admin_presets/forms/admin_presets_export_form.php
+++ b/admin/tool/admin_presets/forms/export_form.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -24,13 +24,19 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace admin_tool_presets\forms;
+
+use moodleform;
+
defined('MOODLE_INTERNAL') || die();
+global $CFG;
+
require_once($CFG->dirroot . '/lib/formslib.php');
-class admin_presets_export_form extends moodleform {
+class export_form extends moodleform {
- public function definition() {
+ public function definition(): void {
global $USER, $OUTPUT;
@@ -38,7 +44,7 @@ public function definition() {
// Preset attributes.
$mform->addElement('header', 'general',
- get_string('presetsettings', 'tool_admin_presets'));
+ get_string('presetsettings', 'tool_admin_presets'));
$mform->addElement('text', 'name', get_string('name'), 'maxlength="254" size="60"');
$mform->addRule('name', null, 'required', null, 'client');
@@ -48,20 +54,20 @@ public function definition() {
$mform->setType('comments', PARAM_CLEANHTML);
$mform->addElement('text', 'author',
- get_string('author', 'tool_admin_presets'), 'maxlength="254" size="60"');
+ get_string('author', 'tool_admin_presets'), 'maxlength="254" size="60"');
$mform->setType('author', PARAM_TEXT);
$mform->setDefault('author', $USER->firstname . ' ' . $USER->lastname);
$mform->addElement('checkbox', 'excludesensiblesettings',
- get_string('autohidesensiblesettings', 'tool_admin_presets'));
+ get_string('autohidesensiblesettings', 'tool_admin_presets'));
$mform->setDefault('excludesensiblesettings', 1);
// Moodle settings table.
$mform->addElement('header', 'general',
- get_string('adminsettings', 'tool_admin_presets'));
+ get_string('adminsettings', 'tool_admin_presets'));
$mform->addElement('html', '
');
+ $OUTPUT->pix_icon('i/loading_small', get_string('loading',
+ 'tool_admin_presets')) . '"/>
');
// Submit.
$mform->addElement('submit', 'admin_presets_submit', get_string('savechanges'));
diff --git a/admin/tool/admin_presets/forms/admin_presets_import_form.php b/admin/tool/admin_presets/forms/import_form.php
similarity index 76%
rename from admin/tool/admin_presets/forms/admin_presets_import_form.php
rename to admin/tool/admin_presets/forms/import_form.php
index 1045b0df86973..bbe8c2ea3de91 100755
--- a/admin/tool/admin_presets/forms/admin_presets_import_form.php
+++ b/admin/tool/admin_presets/forms/import_form.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -24,27 +24,33 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace admin_tool_presets\forms;
+
+use moodleform;
+
defined('MOODLE_INTERNAL') || die();
+global $CFG;
+
require_once($CFG->dirroot . '/lib/formslib.php');
-class admin_presets_import_form extends moodleform {
+class import_form extends moodleform {
- public function definition() {
+ public function definition(): void {
$mform = &$this->_form;
$mform->addElement('header', 'general',
- get_string('selectfile', 'tool_admin_presets'));
+ get_string('selectfile', 'tool_admin_presets'));
- // File upload
+ // File upload.
$mform->addElement('filepicker', 'xmlfile',
- get_string('selectfile', 'tool_admin_presets'));
+ get_string('selectfile', 'tool_admin_presets'));
$mform->addRule('xmlfile', null, 'required');
- // Rename input
+ // Rename input.
$mform->addElement('text', 'name',
- get_string('renamepreset', 'tool_admin_presets'), 'maxlength="254" size="40"');
+ get_string('renamepreset', 'tool_admin_presets'), 'maxlength="254" size="40"');
$mform->setType('name', PARAM_TEXT);
$mform->addElement('submit', 'admin_presets_submit', get_string('savechanges'));
diff --git a/admin/tool/admin_presets/forms/admin_presets_load_form.php b/admin/tool/admin_presets/forms/load_form.php
similarity index 79%
rename from admin/tool/admin_presets/forms/admin_presets_load_form.php
rename to admin/tool/admin_presets/forms/load_form.php
index 4c627a75ce228..44196ce9f380f 100755
--- a/admin/tool/admin_presets/forms/admin_presets_load_form.php
+++ b/admin/tool/admin_presets/forms/load_form.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -24,11 +24,17 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+namespace admin_tool_presets\forms;
+
+use moodleform;
+
defined('MOODLE_INTERNAL') || die();
+global $CFG;
+
require_once($CFG->dirroot . '/lib/formslib.php');
-class admin_presets_load_form extends moodleform {
+class load_form extends moodleform {
private $preview;
@@ -37,7 +43,7 @@ public function __construct($url, $preview = false) {
parent::__construct($url);
}
- public function definition() {
+ public function definition(): void {
global $OUTPUT;
@@ -45,15 +51,15 @@ public function definition() {
// Moodle settings table.
$mform->addElement('header', 'general',
- get_string('adminsettings', 'tool_admin_presets'));
+ get_string('adminsettings', 'tool_admin_presets'));
$class = '';
if (!$this->preview) {
$class = 'ygtv-checkbox';
}
$mform->addElement('html', '');
+ '">');
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
@@ -61,7 +67,7 @@ public function definition() {
// Submit.
if (!$this->preview) {
$mform->addElement('submit', 'admin_presets_submit',
- get_string('loadselected', 'tool_admin_presets'));
+ get_string('loadselected', 'tool_admin_presets'));
}
}
}
diff --git a/admin/tool/admin_presets/index.php b/admin/tool/admin_presets/index.php
index d2c184a34b247..5b70cda46ecf3 100755
--- a/admin/tool/admin_presets/index.php
+++ b/admin/tool/admin_presets/index.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -26,6 +26,8 @@
require_once(__DIR__ . '/../../../config.php');
+global $CFG, $PAGE;
+
$action = optional_param('action', 'base', PARAM_ALPHA);
$mode = optional_param('mode', 'show', PARAM_ALPHAEXT);
@@ -38,10 +40,13 @@
require_capability('moodle/site:config', $context);
// Loads the required action class and form.
-$classname = 'admin_presets_' . $action;
+$fileclassname = $action;
+$classname = 'admin_tool_presets\\'.$action;
$formname = $classname . '_form';
+
$formpath = $CFG->dirroot . '/admin/tool/admin_presets/forms/' . $formname . '.php';
-require_once($CFG->dirroot . '/admin/tool/admin_presets/lib/' . $classname . '.class.php');
+require_once($CFG->dirroot . '/admin/tool/admin_presets/classes/' . $fileclassname . '.php');
+
if (file_exists($formpath)) {
require_once($formpath);
}
diff --git a/admin/tool/admin_presets/lang/en/tool_admin_presets.php b/admin/tool/admin_presets/lang/en/tool_admin_presets.php
index 101197a251705..7b2a8dea398db 100755
--- a/admin/tool/admin_presets/lang/en/tool_admin_presets.php
+++ b/admin/tool/admin_presets/lang/en/tool_admin_presets.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
diff --git a/admin/tool/admin_presets/lib/admin_presets_settings_types.php b/admin/tool/admin_presets/lib/settings_types.php
similarity index 99%
rename from admin/tool/admin_presets/lib/admin_presets_settings_types.php
rename to admin/tool/admin_presets/lib/settings_types.php
index 39d85a786c767..2deb8b6687dfe 100755
--- a/admin/tool/admin_presets/lib/admin_presets_settings_types.php
+++ b/admin/tool/admin_presets/lib/settings_types.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
diff --git a/admin/tool/admin_presets/settings.php b/admin/tool/admin_presets/settings.php
index 87a9bd17b0943..6b6658ceda97a 100755
--- a/admin/tool/admin_presets/settings.php
+++ b/admin/tool/admin_presets/settings.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
diff --git a/admin/tool/admin_presets/tabs.php b/admin/tool/admin_presets/tabs.php
index cee1883a18ad0..74c95a609ca73 100755
--- a/admin/tool/admin_presets/tabs.php
+++ b/admin/tool/admin_presets/tabs.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
diff --git a/admin/tool/admin_presets/version.php b/admin/tool/admin_presets/version.php
index 0ac541501139b..7829ddddcf66e 100755
--- a/admin/tool/admin_presets/version.php
+++ b/admin/tool/admin_presets/version.php
@@ -15,7 +15,7 @@
// along with Moodle. If not, see .
/**
- * Admin presets tool main controller
+* Admin tool presets plugin to load some settings.
*
* @package tool_admin_presets
* @copyright 2021 Pimenko
@@ -26,7 +26,7 @@
defined('MOODLE_INTERNAL') || die();
-$plugin->version = 2021052700;
+$plugin->version = 2021052701;
$plugin->requires = 2016052300; // Requires this Moodle version
$plugin->component = 'tool_admin_presets';
$plugin->release = '3.4';