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,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 tool_admin_presets\event;
use core\event\base;
/**
* Admin tool presets event class deleted.
*
* @package tool_admin_presets
* @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 preset_deleted extends base {
public static function get_name(): string {
return get_string('eventpresetdeleted', 'tool_admin_presets');
}
public function get_description(): string {
return "User {$this->userid} has deleted the preset with id {$this->objectid}.";
}
protected function init(): void {
$this->data['crud'] = 'd';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'adminpresets';
}
}
@@ -0,0 +1,49 @@
<?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 tool_admin_presets\event;
use core\event\base;
/**
* Admin tool presets event class downloaded.
*
* @package tool_admin_presets
* @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 preset_downloaded extends base {
public static function get_name(): string {
return get_string('eventpresetdownloaded', 'tool_admin_presets');
}
public function get_description(): string {
return "User {$this->userid} has downloaded the preset with id {$this->objectid}.";
}
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
['action' => 'export', 'mode' => 'download_xml', 'id' => $this->objectid, 'sesskey' => sesskey()]);
}
protected function init(): void {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'adminpresets';
}
}
@@ -0,0 +1,49 @@
<?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 tool_admin_presets\event;
use core\event\base;
/**
* Admin tool presets event class exported.
*
* @package tool_admin_presets
* @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 preset_exported extends base {
public static function get_name(): string {
return get_string('eventpresetexported', 'tool_admin_presets');
}
public function get_description(): string {
return "User {$this->userid} has exported the preset with id {$this->objectid}.";
}
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
['action' => 'load', 'mode' => 'preview', 'id' => $this->objectid]);
}
protected function init(): void {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'adminpresets';
}
}
@@ -0,0 +1,49 @@
<?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 tool_admin_presets\event;
use core\event\base;
/**
* Admin tool presets event class imported.
*
* @package tool_admin_presets
* @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 preset_imported extends base {
public static function get_name(): string {
return get_string('eventpresetimported', 'tool_admin_presets');
}
public function get_description(): string {
return "User {$this->userid} has imported the preset with id {$this->objectid}.";
}
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
['action' => 'load', 'mode' => 'preview', 'id' => $this->objectid]);
}
protected function init(): void {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'adminpresets';
}
}
@@ -0,0 +1,49 @@
<?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 tool_admin_presets\event;
use core\event\base;
/**
* Admin tool presets event class loaded.
*
* @package tool_admin_presets
* @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 preset_loaded extends base {
public static function get_name(): string {
return get_string('eventpresetloaded', 'tool_admin_presets');
}
public function get_description(): string {
return "User {$this->userid} has loaded the preset with id {$this->objectid}.";
}
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
['action' => 'load', 'mode' => 'preview', 'id' => $this->objectid]);
}
protected function init(): void {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'adminpresets';
}
}
@@ -0,0 +1,49 @@
<?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 tool_admin_presets\event;
use core\event\base;
/**
* Admin tool presets event class previewed.
*
* @package tool_admin_presets
* @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 preset_previewed extends base {
public static function get_name(): string {
return get_string('eventpresetpreviewed', 'tool_admin_presets');
}
public function get_description(): string {
return "User {$this->userid} has previewed the preset with id {$this->objectid}.";
}
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php',
['action' => 'load', 'mode' => 'preview', 'id' => $this->objectid]);
}
protected function init(): void {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'adminpresets';
}
}
@@ -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 tool_admin_presets\event;
use core\event\base;
/**
* Admin tool presets event class reverted.
*
* @package tool_admin_presets
* @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 preset_reverted extends base {
public static function get_name(): string {
return get_string('eventpresetreverted', 'tool_admin_presets');
}
public function get_description(): string {
return "User {$this->userid} has reverted the preset with id {$this->objectid}.";
}
protected function init(): void {
$this->data['crud'] = 'u';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'adminpresets';
}
}
@@ -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 tool_admin_presets\event;
use core\event\base;
/**
* Admin tool presets event class listed.
*
* @package tool_admin_presets
* @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 presets_listed extends base {
public static function get_name(): string {
return get_string('eventpresetslisted', 'tool_admin_presets');
}
public function get_description(): string {
return "User {$this->userid} listed the system presets.";
}
public function get_url(): \moodle_url {
return new \moodle_url('/admin/tool/admin_presets/index.php');
}
protected function init(): void {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'adminpresets';
}
}
@@ -0,0 +1,38 @@
<?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 tool_admin_presets\form;
defined('MOODLE_INTERNAL') || die();
use moodleform;
global $CFG;
require_once($CFG->dirroot . '/lib/formslib.php');
/**
* Form for loading continue button.
*
* @package tool_admin_presets
* @copyright 2021 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class continue_form extends moodleform {
public function definition(): void {
$this->add_action_buttons(false, get_string('continue'));
}
}
@@ -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 tool_admin_presets\form;
use moodleform;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/lib/formslib.php');
/**
* Form for exporting settings.
*
* @package tool_admin_presets
* @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 export_form extends moodleform {
public function definition(): void {
global $USER;
$mform = &$this->_form;
// Preset attributes.
$mform->addElement('text', 'name', get_string('name'), 'maxlength="254" size="60"');
$mform->addRule('name', null, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
$mform->addElement('editor', 'comments', get_string('description'));
$mform->setType('comments', PARAM_CLEANHTML);
$mform->addElement('text', 'author',
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', 'includesensiblesettings',
get_string('includesensiblesettings', 'tool_admin_presets'));
$mform->setDefault('includesensiblesettings', 0);
$mform->addHelpButton('includesensiblesettings', 'includesensiblesettings', 'tool_admin_presets');
$this->add_action_buttons(true, get_string('actionexportbutton', 'tool_admin_presets'));
}
}
@@ -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 tool_admin_presets\form;
defined('MOODLE_INTERNAL') || die();
use moodleform;
global $CFG;
require_once($CFG->dirroot . '/lib/formslib.php');
/**
* Form for importting settings.
*
* @package tool_admin_presets
* @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 import_form extends moodleform {
public function definition(): void {
$mform = &$this->_form;
// Rename preset input.
$mform->addElement('text', 'name',
get_string('renamepreset', 'tool_admin_presets'), 'maxlength="254" size="40"');
$mform->setType('name', PARAM_TEXT);
// File upload.
$mform->addElement('filepicker', 'xmlfile', get_string('selectfile', 'tool_admin_presets'), null,
['accepted_types' => ['.xml']]);
$mform->addRule('xmlfile', null, 'required');
$this->add_action_buttons(true, get_string('import', 'tool_admin_presets'));
}
}
@@ -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 tool_admin_presets\form;
defined('MOODLE_INTERNAL') || die();
use moodleform;
global $CFG;
require_once($CFG->dirroot . '/lib/formslib.php');
/**
* Form for loading settings.
*
* @package tool_admin_presets
* @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 load_form extends moodleform {
public function definition(): void {
$mform = &$this->_form;
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$html = '<div class="alert alert-info">' . get_string('applypresetdescription', 'tool_admin_presets') . '</div>';
$mform->addElement('html', $html);
$this->add_action_buttons(true, get_string('loadselected', 'tool_admin_presets'));
}
}
@@ -0,0 +1,209 @@
<?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 tool_admin_presets\local\action;
use context_system;
use moodle_url;
use core_adminpresets\manager;
use tool_admin_presets\output\presets_list;
use tool_admin_presets\output\export_import;
/**
* Admin tool presets main controller class.
*
* @package tool_admin_presets
* @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 base {
/** @var array Array map for the events. **/
protected static $eventsactionsmap = [
'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'
];
/** @var string The main action (delete, export, import, load...). **/
protected $action;
/** @var string The mode (show, execute...). **/
protected $mode;
/** @var int Admin preset identifier. **/
protected $id;
/** @var int The output content to display in the page. **/
protected $outputs;
/** @var \moodleform The moodle form to display in the page. **/
protected $moodleform;
/** @var manager The manager helper class instance. **/
protected $manager;
/**
* Loads common class attributes.
*/
public function __construct() {
$this->manager = new manager();
$this->action = optional_param('action', 'base', PARAM_ALPHA);
$this->mode = optional_param('mode', 'show', PARAM_ALPHAEXT);
$this->id = optional_param('id', false, PARAM_INT);
}
/**
* Method to list the presets available on the system
*
* It allows users to access the different preset
* actions (preview, load, download, delete and rollback)
*/
public function show(): void {
global $DB, $OUTPUT;
$options = new export_import();
$this->outputs = $OUTPUT->render($options);
$presets = $DB->get_records('adminpresets');
$list = new presets_list($presets, true);
$this->outputs .= $OUTPUT->render($list);
}
/**
* Main display method
*
* Prints the block header and the common block outputs, the
* selected action outputs, his form and the footer
*
* $outputs value depends on $mode and $action selected
*/
public function display(): void {
global $OUTPUT;
$this->display_header();
// Other outputs.
if (!empty($this->outputs)) {
echo $this->outputs;
}
// Form.
if ($this->moodleform) {
$this->moodleform->display();
}
// Footer.
echo $OUTPUT->footer();
}
/**
* Displays the header
*/
protected function display_header(): void {
global $PAGE, $OUTPUT, $SITE;
// Strings.
$titlestr = get_string('pluginname', 'tool_admin_presets');
// Header.
$PAGE->set_title($titlestr);
$PAGE->set_heading($SITE->fullname);
$title = $this->get_title();
$text = $this->get_explanatory_description();
// Only add it to the navbar if it's different to the plugin name (to avoid duplicates in the navbar).
if ($title != get_string('pluginname', 'tool_admin_presets')) {
$PAGE->navbar->add($title);
}
if ($node = $PAGE->settingsnav->find('tool_admin_presets', \navigation_node::TYPE_SETTING)) {
$node->make_active();
}
echo $OUTPUT->header();
echo $OUTPUT->heading($title);
if ($text) {
echo $OUTPUT->box($text);
}
}
/**
* Get page title for this action.
*
* @return string The page title to display into the page.
*/
protected function get_title(): string {
if ($this->action == 'base') {
return get_string('pluginname', 'tool_admin_presets');
}
return get_string($this->action . $this->mode, 'tool_admin_presets');
}
/**
* Get explanatory description to be displayed below the heading. It's optional and might change depending on the
* action and the mode.
*
* @return string|null The explanatory description for the current action and mode.
*/
protected function get_explanatory_description(): ?string {
$text = null;
if ($this->action == 'base') {
$text = get_string('basedescription', 'tool_admin_presets');
}
return $text;
}
/**
* Trigger an event based on the current action.
*
* @return void
*/
public function log(): void {
// The only read action we store is list presets and preview.
$islist = ($this->action == 'base' && $this->mode == 'show');
$ispreview = ($this->action == 'load' && $this->mode == 'show');
if ($this->mode != 'show' || $islist || $ispreview) {
$action = $this->action;
if ($ispreview) {
$action = 'preview';
}
if ($this->mode != 'execute' && $this->mode != 'show') {
$action = $this->mode;
}
if (array_key_exists($action, self::$eventsactionsmap)) {
$eventnamespace = '\\tool_admin_presets\\event\\' . self::$eventsactionsmap[$action];
$eventdata = [
'context' => context_system::instance(),
'objectid' => $this->id
];
$event = $eventnamespace::create($eventdata);
$event->trigger();
}
}
}
}
@@ -0,0 +1,78 @@
<?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 tool_admin_presets\local\action;
use core_adminpresets\manager;
use moodle_exception;
/**
* This class extends base class and handles delete function.
*
* @package tool_admin_presets
* @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 delete extends base {
/**
* Shows a confirm box
*/
public function show(): void {
global $DB, $OUTPUT;
// Check the preset exists (cannot delete the pre-installed core "Starter" and "Full" presets).
$presetdata = $DB->get_record('adminpresets', ['id' => $this->id, 'iscore' => manager::NONCORE_PRESET], 'name');
if ($presetdata) {
$deletetext = get_string('deletepreset', 'tool_admin_presets', $presetdata->name);
$params = ['action' => $this->action, 'mode' => 'execute', 'id' => $this->id, 'sesskey' => sesskey()];
$confirmurl = new \moodle_url('/admin/tool/admin_presets/index.php', $params);
$cancelurl = new \moodle_url('/admin/tool/admin_presets/index.php');
// If the preset was applied add a warning text.
if ($DB->get_records('adminpresets_app', ['adminpresetid' => $this->id])) {
$deletetext .= '<p><strong>' .
get_string("deletepreviouslyapplied", "tool_admin_presets") . '</strong></p>';
}
$displayoptions = [
'confirmtitle' => get_string('deletepresettitle', 'tool_admin_presets', $presetdata->name),
'continuestr' => get_string('delete')
];
$this->outputs = $OUTPUT->confirm($deletetext, $confirmurl, $cancelurl, $displayoptions);
} else {
throw new moodle_exception('errordeleting', 'core_adminpresets');
}
}
/**
* Delete the DB preset
*/
public function execute(): void {
require_sesskey();
$this->manager->delete_preset($this->id);
// Trigger the as it is usually triggered after execute finishes.
$this->log();
$url = new \moodle_url('/admin/tool/admin_presets/index.php');
redirect($url);
}
}
@@ -0,0 +1,101 @@
<?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 tool_admin_presets\local\action;
defined('MOODLE_INTERNAL') || die();
use tool_admin_presets\form\export_form;
use moodle_exception;
global $CFG;
require_once($CFG->dirroot . '/lib/filelib.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');
/**
* This class extends base class and handles export function.
*
* @package tool_admin_presets
* @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 export extends base {
/**
* Shows the initial form to export/save admin settings.
*
* Loads the database configuration and prints
* the settings in a hierarchical table
*/
public function show(): void {
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'export', 'mode' => 'execute']);
$this->moodleform = new export_form($url);
}
/**
* Stores a preset into the DB.
*/
public function execute(): void {
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'export', 'mode' => 'execute']);
$this->moodleform = new export_form($url);
if ($data = $this->moodleform->get_data()) {
list($presetid, $settingsfound, $pluginsfound) = $this->manager->export_preset($data);
// Store it here for logging and other future id-oriented stuff.
$this->id = $presetid;
// If there are no settings nor plugins, an error should be raised.
if (!$settingsfound && !$pluginsfound) {
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'export']);
redirect($url, get_string('novalidsettingsselected', 'tool_admin_presets'));
}
}
// Trigger the as it is usually triggered after execute finishes.
$this->log();
$url = new \moodle_url('/admin/tool/admin_presets/index.php');
redirect($url);
}
/**
* To download system presets.
*
* @return void preset file
* @throws dml_exception
* @throws moodle_exception
* @throws xml_output_exception
* @throws xml_writer_exception
*/
public function download_xml(): void {
require_sesskey();
list($xmlstr, $filename) = $this->manager->download_preset($this->id);
// Trigger the as it is usually triggered after execute finishes.
$this->log();
send_file($xmlstr, $filename, 0, 0, true, true);
}
protected function get_explanatory_description(): ?string {
return get_string('exportdescription', 'tool_admin_presets');
}
}
@@ -0,0 +1,88 @@
<?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 tool_admin_presets\local\action;
use tool_admin_presets\form\import_form;
/**
* This class extends base class and handles import function.
*
* @package tool_admin_presets
* @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 import extends base {
/**
* Displays the import moodleform
*/
public function show(): void {
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'import', 'mode' => 'execute']);
$this->moodleform = new import_form($url);
}
/**
* Imports the xmlfile into DB
*/
public function execute(): void {
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'import', 'mode' => 'execute']);
$this->moodleform = new import_form($url);
if ($this->moodleform->is_cancelled()) {
$url = new \moodle_url('/admin/tool/admin_presets/index.php');
redirect($url);
}
if ($data = $this->moodleform->get_data()) {
// Getting the file.
$xmlcontent = $this->moodleform->get_file_content('xmlfile');
list($xml, $preset, $settingsfound, $pluginsfound) = $this->manager->import_preset($xmlcontent, $data->name);
if (!$xml) {
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'import']);
redirect($url, get_string('wrongfile', 'tool_admin_presets'));
}
// Store it here for logging and other future id-oriented stuff.
if (!is_null($preset)) {
$this->id = $preset->id;
}
// If there are no valid or selected settings, raise an error.
if (!$settingsfound && !$pluginsfound) {
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'import']);
redirect($url, get_string('novalidsettings', 'tool_admin_presets'));
}
// Trigger it after execute finishes.
$this->log();
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'load', 'id' => $preset->id]);
redirect($url);
}
}
protected function get_explanatory_description(): ?string {
$text = null;
if ($this->mode == 'show') {
$text = get_string('importdescription', 'tool_admin_presets');
}
return $text;
}
}
@@ -0,0 +1,176 @@
<?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 tool_admin_presets\local\action;
use moodle_exception;
use stdClass;
use tool_admin_presets\form\continue_form;
use tool_admin_presets\form\load_form;
use tool_admin_presets\output\presets_list;
/**
* This class extends base class and handles load function.
*
* @package tool_admin_presets
* @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 load extends base {
/**
* Executes the settings load into the system
*/
public function execute(): void {
global $OUTPUT;
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'load', 'mode' => 'execute']);
$this->moodleform = new load_form($url);
if ($this->moodleform->is_cancelled()) {
redirect(new \moodle_url('/admin/tool/admin_presets/index.php?action=base'));
}
if ($this->moodleform->is_submitted() && $this->moodleform->is_validated() && ($this->moodleform->get_data())) {
// Apply preset settings and set plugins visibility.
[$applied, $skipped] = $this->manager->apply_preset($this->id);
if (empty($applied)) {
$message = [
'message' => get_string('nothingloaded', 'tool_admin_presets'),
'closebutton' => true,
'announce' => true,
];
} else {
$message = [
'message' => get_string('settingsappliednotification', 'tool_admin_presets'),
'closebutton' => true,
'announce' => true,
];
}
$application = new stdClass();
$applieddata = new stdClass();
$applieddata->show = !empty($applied);
$applieddata->message = $message;
$applieddata->heading = get_string('settingsapplied', 'tool_admin_presets');
$applieddata->caption = get_string('settingsapplied', 'tool_admin_presets');
$applieddata->settings = $applied;
$application->appliedchanges = $applieddata;
$skippeddata = new stdClass();
$skippeddata->show = !empty($skipped);
$skippeddata->heading = get_string('settingsnotapplied', 'tool_admin_presets');
$skippeddata->caption = get_string('settingsnotapplicable', 'tool_admin_presets');
$skippeddata->settings = $skipped;
$application->skippedchanges = $skippeddata;
$this->outputs = $OUTPUT->render_from_template('tool_admin_presets/settings_application', $application);
$url = new \moodle_url('/admin/tool/admin_presets/index.php');
$this->moodleform = new continue_form($url);
}
}
/**
* Displays the select preset settings to select what to import.
* Loads the preset data and displays a settings tree.
*
* It checks the Moodle version and it only allows users to import
* the preset available settings.
*/
public function show(): void {
$this->display_preset(true);
}
/**
* Displays a preset information (name, description, settings different from the current configuration...).
*/
public function preview(): void {
$this->display_preset(false, false);
}
/**
* Method to prepare the information to preview/load the preset.
*
* @param bool $displayform Whether the form should be displayed in the page or not.
* @param bool $raiseexception Whether the exception should be raised or not when the preset doesn't exist. When it's set
* to false, a message is displayed, instead of raising the exception.
*/
protected function display_preset(bool $displayform = true, bool $raiseexception = true) {
global $DB, $OUTPUT;
$data = new stdClass();
$data->id = $this->id;
// Preset data.
if (!$preset = $DB->get_record('adminpresets', ['id' => $data->id])) {
if ($raiseexception) {
throw new moodle_exception('errornopreset', 'core_adminpresets');
} else {
$this->outputs = get_string('errornopreset', 'core_adminpresets');
return;
}
}
// Print preset basic data.
$list = new presets_list([$preset]);
$this->outputs = $OUTPUT->render($list);
// Simulate preset application to display settings and plugins that will change.
[$applied] = $this->manager->apply_preset($this->id, true);
// Order the applied array by the visiblename column.
if (!empty($applied)) {
$visiblenamecolumn = array_column($applied, 'visiblename');
array_multisort($visiblenamecolumn, SORT_ASC, $applied);
}
$application = new stdClass();
$applieddata = new stdClass();
$applieddata->show = !empty($applied);
$applieddata->heading = get_string('settingstobeapplied', 'tool_admin_presets');
$applieddata->caption = get_string('settingsapplied', 'tool_admin_presets');
$applieddata->settings = $applied;
$applieddata->beforeapplying = true;
$application->appliedchanges = $applieddata;
if ($displayform) {
if (empty($applied)) {
// Display a warning when no settings will be applied.
$applieddata->message = get_string('nosettingswillbeapplied', 'tool_admin_presets');
// Only display the Continue button.
$url = new \moodle_url('/admin/tool/admin_presets/index.php');
$this->moodleform = new continue_form($url);
} else {
// Display the form to apply the preset.
$url = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'load', 'mode' => 'execute']);
$this->moodleform = new load_form($url);
$this->moodleform->set_data($data);
}
}
$this->outputs .= $OUTPUT->render_from_template('tool_admin_presets/settings_application', $application);
}
protected function get_explanatory_description(): ?string {
$text = null;
if ($this->mode == 'show') {
$text = get_string('loaddescription', 'tool_admin_presets');
}
return $text;
}
}
@@ -0,0 +1,124 @@
<?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 tool_admin_presets\local\action;
use stdClass;
use tool_admin_presets\form\continue_form;
/**
* This class extends base class and handles rollback function.
*
* @package tool_admin_presets
* @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 rollback extends base {
/**
* Displays the different previous applications of the preset
*/
public function show(): void {
global $DB, $OUTPUT;
// Preset data.
$preset = $DB->get_record('adminpresets', ['id' => $this->id]);
// Applications data.
$context = new stdClass();
$applications = $DB->get_records('adminpresets_app', ['adminpresetid' => $this->id], 'time DESC');
$context->noapplications = !empty($applications);
$context->applications = [];
foreach ($applications as $application) {
$format = get_string('strftimedatetime', 'langconfig');
$user = $DB->get_record('user', ['id' => $application->userid]);
$rollbacklink = new \moodle_url(
'/admin/tool/admin_presets/index.php',
['action' => 'rollback', 'mode' => 'execute', 'id' => $application->id, 'sesskey' => sesskey()]
);
$context->applications[] = [
'timeapplied' => \core_date::strftime($format, (int)$application->time),
'user' => fullname($user),
'action' => $rollbacklink->out(false),
];
}
$this->outputs .= '<br/>' . $OUTPUT->heading(get_string('presetname', 'tool_admin_presets') . ': ' . $preset->name, 3);
$this->outputs = $OUTPUT->render_from_template('tool_admin_presets/preset_applications_list', $context);
$url = new \moodle_url('/admin/tool/admin_presets/index.php');
$this->moodleform = new continue_form($url);
}
/**
* Executes the application rollback
*
* Each setting value is checked against the config_log->value
*/
public function execute(): void {
global $OUTPUT;
require_sesskey();
list($presetapp, $rollback, $failures) = $this->manager->revert_preset($this->id);
if (!is_null($presetapp)) {
// Change $this->id to point to the preset.
$this->id = $presetapp->adminpresetid;
}
$appliedchanges = new stdClass();
$appliedchanges->show = !empty($rollback);
$appliedchanges->caption = get_string('rollbackresults', 'tool_admin_presets');
$appliedchanges->settings = $rollback;
$skippedchanges = new stdClass();
$skippedchanges->show = !empty($failures);
$skippedchanges->caption = get_string('rollbackfailures', 'tool_admin_presets');
$skippedchanges->settings = $failures;
$data = new stdClass();
$data->appliedchanges = $appliedchanges;
$data->skippedchanges = $skippedchanges;
$data->beforeapplying = true;
$this->outputs = $OUTPUT->render_from_template('tool_admin_presets/settings_rollback', $data);
$url = new \moodle_url('/admin/tool/admin_presets/index.php');
$this->moodleform = new continue_form($url);
}
protected function get_title(): string {
global $DB;
$title = '';
if ($preset = $DB->get_record('adminpresets', ['id' => $this->id])) {
$title = get_string($this->action . $this->mode, 'tool_admin_presets', $preset->name);
}
return $title;
}
protected function get_explanatory_description(): ?string {
$text = null;
if ($this->mode == 'show') {
$text = get_string('rollbackdescription', 'tool_admin_presets');
}
return $text;
}
}
@@ -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/>.
/**
* tool_admin_presets export and import option renderer
*
* @package tool_admin_presets
* @copyright 2021 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_admin_presets\output;
use renderable;
use templatable;
use renderer_base;
use stdClass;
/**
* Class containing data for export and import template
*
* @copyright 2021 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class export_import implements renderable, templatable {
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output): stdClass {
$context = new stdClass();
$exportlink = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'export']);
$exportbutton = new \single_button($exportlink, get_string('actionexport', 'tool_admin_presets'), 'get');
$context->export = $exportbutton->export_for_template($output);
$importlink = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'import']);
$importbutton = new \single_button($importlink, get_string('actionimport', 'tool_admin_presets'), 'get');
$context->import = $importbutton->export_for_template($output);
return $context;
}
}
@@ -0,0 +1,139 @@
<?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/>.
/**
* tool_admin_presets specific renderers
*
* @package tool_admin_presets
* @copyright 2021 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_admin_presets\output;
use core_adminpresets\manager;
use renderable;
use templatable;
use renderer_base;
use stdClass;
/**
* Class containing data for admin_presets tool
*
* @copyright 2021 Amaia Anabitarte <amaia@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class presets_list implements renderable, templatable {
/**
* @var stdClass[] Array of admin presets.
*/
private $presets;
/**
* @var bool Wether the action menu is visible.
*/
private $showactions;
/**
* Construct this renderable.
*
* @param stdClass[] $presets Array of existing admin presets.
* @param bool $showactions Whether actions should be displayed or not.
*/
public function __construct(array $presets, bool $showactions = false) {
$this->presets = $presets;
$this->showactions = $showactions;
}
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output): stdClass {
global $DB;
$context = new stdClass();
$context->presets = [];
foreach ($this->presets as $preset) {
if ($preset->timeimported) {
$timeimportedstring = userdate($preset->timeimported);
} else {
$timeimportedstring = '';
}
$data = [
'name' => format_text($preset->name, FORMAT_PLAIN),
'description' => format_text($preset->comments, FORMAT_HTML),
'release' => format_text($preset->moodlerelease, FORMAT_PLAIN),
'author' => format_text($preset->author, FORMAT_PLAIN),
'site' => format_text(clean_text($preset->site, PARAM_URL), FORMAT_PLAIN),
'timecreated' => userdate($preset->timecreated),
'timeimported' => $timeimportedstring
];
if ($this->showactions) {
// Preset actions.
$actionsmenu = new \action_menu();
$actionsmenu->set_menu_trigger(get_string('actions'));
$actionsmenu->set_owner_selector('preset-actions-' . $preset->id);
$loadlink = new \moodle_url('/admin/tool/admin_presets/index.php', ['action' => 'load', 'id' => $preset->id]);
$actionsmenu->add(new \action_menu_link_secondary(
$loadlink, new \pix_icon('t/play', ''),
get_string('applyaction', 'tool_admin_presets')
));
$downloadlink = new \moodle_url('/admin/tool/admin_presets/index.php',
['action' => 'export', 'mode' => 'download_xml', 'sesskey' => sesskey(), 'id' => $preset->id]
);
$actionsmenu->add(new \action_menu_link_secondary(
$downloadlink,
new \pix_icon('t/download', ''),
get_string('download')
));
// Delete button won't be displayed for the pre-installed core "Starter" and "Full" presets.
if ($preset->iscore == manager::NONCORE_PRESET) {
$deletelink = new \moodle_url('/admin/tool/admin_presets/index.php',
['action' => 'delete', 'id' => $preset->id]
);
$actionsmenu->add(new \action_menu_link_secondary(
$deletelink,
new \pix_icon('i/delete', ''),
get_string('delete')
));
}
// Look for preset applications.
if ($DB->get_records('adminpresets_app', ['adminpresetid' => $preset->id])) {
$params = ['action' => 'rollback', 'id' => $preset->id];
$rollbacklink = new \moodle_url('/admin/tool/admin_presets/index.php', $params);
$actionsmenu->add(new \action_menu_link_secondary(
$rollbacklink,
new \pix_icon('i/reload', ''),
get_string('showhistory', 'tool_admin_presets')
));
}
$data['actions'] = $actionsmenu->export_for_template($output);
}
$context->presets[] = $data;
}
$context->nopresets = empty($context->presets);
$context->showactions = $this->showactions;
return $context;
}
}
@@ -0,0 +1,37 @@
<?php
// This file is part of The Course Module Navigation Block
//
// 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 tool_admin_presets\privacy;
/**
* Admin tool presets this file handle privacy provider.
*
* @package tool_admin_presets
* @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 provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}