1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace tool_admin_presets\local\action;
|
|
|
18 |
|
|
|
19 |
use core_adminpresets\manager;
|
|
|
20 |
use moodle_exception;
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* This class extends base class and handles delete function.
|
|
|
24 |
*
|
|
|
25 |
* @package tool_admin_presets
|
|
|
26 |
* @copyright 2021 Pimenko <support@pimenko.com><pimenko.com>
|
|
|
27 |
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
*/
|
|
|
30 |
class delete extends base {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Shows a confirm box
|
|
|
34 |
*/
|
|
|
35 |
public function show(): void {
|
|
|
36 |
global $DB, $OUTPUT;
|
|
|
37 |
|
|
|
38 |
// Check the preset exists (cannot delete the pre-installed core "Starter" and "Full" presets).
|
|
|
39 |
$presetdata = $DB->get_record('adminpresets', ['id' => $this->id, 'iscore' => manager::NONCORE_PRESET], 'name');
|
|
|
40 |
|
|
|
41 |
if ($presetdata) {
|
|
|
42 |
$deletetext = get_string('deletepreset', 'tool_admin_presets', $presetdata->name);
|
|
|
43 |
|
|
|
44 |
$params = ['action' => $this->action, 'mode' => 'execute', 'id' => $this->id, 'sesskey' => sesskey()];
|
|
|
45 |
$confirmurl = new \moodle_url('/admin/tool/admin_presets/index.php', $params);
|
|
|
46 |
|
|
|
47 |
$cancelurl = new \moodle_url('/admin/tool/admin_presets/index.php');
|
|
|
48 |
|
|
|
49 |
// If the preset was applied add a warning text.
|
|
|
50 |
if ($DB->get_records('adminpresets_app', ['adminpresetid' => $this->id])) {
|
|
|
51 |
$deletetext .= '<p><strong>' .
|
|
|
52 |
get_string("deletepreviouslyapplied", "tool_admin_presets") . '</strong></p>';
|
|
|
53 |
}
|
|
|
54 |
$displayoptions = [
|
|
|
55 |
'confirmtitle' => get_string('deletepresettitle', 'tool_admin_presets', $presetdata->name),
|
|
|
56 |
'continuestr' => get_string('delete')
|
|
|
57 |
];
|
|
|
58 |
$this->outputs = $OUTPUT->confirm($deletetext, $confirmurl, $cancelurl, $displayoptions);
|
|
|
59 |
} else {
|
|
|
60 |
throw new moodle_exception('errordeleting', 'core_adminpresets');
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Delete the DB preset
|
|
|
66 |
*/
|
|
|
67 |
public function execute(): void {
|
|
|
68 |
require_sesskey();
|
|
|
69 |
|
|
|
70 |
$this->manager->delete_preset($this->id);
|
|
|
71 |
|
|
|
72 |
// Trigger the as it is usually triggered after execute finishes.
|
|
|
73 |
$this->log();
|
|
|
74 |
|
|
|
75 |
$url = new \moodle_url('/admin/tool/admin_presets/index.php');
|
|
|
76 |
redirect($url);
|
|
|
77 |
}
|
|
|
78 |
}
|