1441 |
ariadna |
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 core_courseformat\output\local;
|
|
|
18 |
|
|
|
19 |
use core_courseformat\base as course_format;
|
|
|
20 |
use core\output\renderer_base;
|
|
|
21 |
use core\output\single_button;
|
|
|
22 |
use core\url;
|
|
|
23 |
use stdClass;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Support UIs for non-ajax course updates alternatives.
|
|
|
27 |
*
|
|
|
28 |
* This class is used from course/format/update.php to provide confirmation
|
|
|
29 |
* dialogs for specific actions that require user confirmation.
|
|
|
30 |
*
|
|
|
31 |
* All protected methods has the same parameters as the core_courseformat\stateactions
|
|
|
32 |
* even if they are not used for a specific action.
|
|
|
33 |
*
|
|
|
34 |
* @package core_courseformat
|
|
|
35 |
* @copyright 2024 Ferran Recio <ferran@moodle.com>
|
|
|
36 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
37 |
*/
|
|
|
38 |
class courseupdate {
|
|
|
39 |
use courseformat_named_templatable;
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Constructor.
|
|
|
43 |
*
|
|
|
44 |
* @param course_format $format the course format class.
|
|
|
45 |
* @param url $actionurl the current action url.
|
|
|
46 |
* @param url $returnurl the return url if the user cancel the action.
|
|
|
47 |
*/
|
|
|
48 |
public function __construct(
|
|
|
49 |
/** @var course_format the course format class */
|
|
|
50 |
protected course_format $format,
|
|
|
51 |
/** @var url the current action url */
|
|
|
52 |
protected url $actionurl,
|
|
|
53 |
/** @var url the return url if the user cancel the action */
|
|
|
54 |
protected url $returnurl,
|
|
|
55 |
) {
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* Check if a specific action requires confirmation.
|
|
|
60 |
*
|
|
|
61 |
* Format plugins can override this method to provide confirmation
|
|
|
62 |
* dialogs for specific actions.
|
|
|
63 |
*
|
|
|
64 |
* @param string $action the action name
|
|
|
65 |
* @return bool
|
|
|
66 |
*/
|
|
|
67 |
public function is_confirmation_required(
|
|
|
68 |
string $action,
|
|
|
69 |
): bool {
|
|
|
70 |
$methodname = $action . '_confirmation_dialog';
|
|
|
71 |
return method_exists($this, $methodname);
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
/**
|
|
|
75 |
* Get the confirmation dialog for a specific action.
|
|
|
76 |
*
|
|
|
77 |
* Format plugins can override this method to provide confirmation
|
|
|
78 |
* dialogs for specific actions.
|
|
|
79 |
*
|
|
|
80 |
* @param renderer_base $output the course renderer
|
|
|
81 |
* @param stdClass $course
|
|
|
82 |
* @param string $action the state action name to execute
|
|
|
83 |
* @param array $ids the section or cm ids.
|
|
|
84 |
* @param int|null $targetsectionid the optional target section id
|
|
|
85 |
* @param int|null $targetcmid the optional target cm id
|
|
|
86 |
* @return string the HTML output
|
|
|
87 |
*/
|
|
|
88 |
public function get_confirmation_dialog(
|
|
|
89 |
renderer_base $output,
|
|
|
90 |
stdClass $course,
|
|
|
91 |
string $action,
|
|
|
92 |
array $ids = [],
|
|
|
93 |
?int $targetsectionid = null,
|
|
|
94 |
?int $targetcmid = null,
|
|
|
95 |
): string {
|
|
|
96 |
$methodname = $action . '_confirmation_dialog';
|
|
|
97 |
if (method_exists($this, $methodname)) {
|
|
|
98 |
return $this->$methodname(
|
|
|
99 |
output: $output,
|
|
|
100 |
course: $course,
|
|
|
101 |
ids: $ids,
|
|
|
102 |
targetsectionid: $targetsectionid,
|
|
|
103 |
targetcmid: $targetcmid,
|
|
|
104 |
);
|
|
|
105 |
}
|
|
|
106 |
return '';
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Render the section delete confirmation dialog.
|
|
|
111 |
*
|
|
|
112 |
* @param renderer_base $output the course renderer
|
|
|
113 |
* @param stdClass $course
|
|
|
114 |
* @param array $ids the action ids.
|
|
|
115 |
* @param int|null $targetsectionid the target section id (not used)
|
|
|
116 |
* @param int|null $targetcmid the target cm id (not used)
|
|
|
117 |
* @return string the HTML output
|
|
|
118 |
*/
|
|
|
119 |
protected function section_delete_confirmation_dialog(
|
|
|
120 |
renderer_base $output,
|
|
|
121 |
stdClass $course,
|
|
|
122 |
array $ids = [],
|
|
|
123 |
?int $targetsectionid = null,
|
|
|
124 |
?int $targetcmid = null,
|
|
|
125 |
): string {
|
|
|
126 |
if (count($ids) == 1) {
|
|
|
127 |
$modinfo = $this->format->get_modinfo();
|
|
|
128 |
$section = $modinfo->get_section_info_by_id($ids[0]);
|
|
|
129 |
$title = get_string('sectiondelete_title', 'core_courseformat');
|
|
|
130 |
$message = get_string(
|
|
|
131 |
'sectiondelete_info',
|
|
|
132 |
'core_courseformat',
|
|
|
133 |
['name' => $this->format->get_section_name($section)]
|
|
|
134 |
);
|
|
|
135 |
} else {
|
|
|
136 |
$title = get_string('sectionsdelete_title', 'core_courseformat');
|
|
|
137 |
$message = get_string('sectionsdelete_info', 'core_courseformat', ['count' => count($ids)]);
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
return $output->confirm(
|
|
|
141 |
message: $message,
|
|
|
142 |
cancel: $this->returnurl,
|
|
|
143 |
continue: new url($this->actionurl, ['confirm' => 1]),
|
|
|
144 |
displayoptions: [
|
|
|
145 |
'confirmtitle' => $title,
|
|
|
146 |
'type' => single_button::BUTTON_DANGER,
|
|
|
147 |
'continuestr' => get_string('delete'),
|
|
|
148 |
]
|
|
|
149 |
);
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
/**
|
|
|
153 |
* Render the cm delete confirmation dialog.
|
|
|
154 |
*
|
|
|
155 |
* @param renderer_base $output the course renderer
|
|
|
156 |
* @param stdClass $course
|
|
|
157 |
* @param array $ids the action ids.
|
|
|
158 |
* @param int|null $targetsectionid the target section id (not used)
|
|
|
159 |
* @param int|null $targetcmid the target cm id (not used)
|
|
|
160 |
* @return string the HTML output
|
|
|
161 |
*/
|
|
|
162 |
protected function cm_delete_confirmation_dialog(
|
|
|
163 |
renderer_base $output,
|
|
|
164 |
stdClass $course,
|
|
|
165 |
array $ids = [],
|
|
|
166 |
?int $targetsectionid = null,
|
|
|
167 |
?int $targetcmid = null,
|
|
|
168 |
): string {
|
|
|
169 |
|
|
|
170 |
if (count($ids) == 1) {
|
|
|
171 |
$modinfo = $this->format->get_modinfo();
|
|
|
172 |
$cm = $modinfo->get_cm($ids[0]);
|
|
|
173 |
|
|
|
174 |
if ($cm->get_delegated_section_info()) {
|
|
|
175 |
$title = get_string('cmdelete_subsectiontitle', 'core_courseformat');
|
|
|
176 |
$meesagestr = 'sectiondelete_info';
|
|
|
177 |
} else {
|
|
|
178 |
$title = get_string('cmdelete_title', 'core_courseformat');
|
|
|
179 |
$meesagestr = 'cmdelete_info';
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
$message = get_string(
|
|
|
183 |
$meesagestr,
|
|
|
184 |
'core_courseformat',
|
|
|
185 |
(object) [
|
|
|
186 |
'type' => get_string('pluginname', 'mod_' . $cm->modname),
|
|
|
187 |
'name' => $cm->name,
|
|
|
188 |
],
|
|
|
189 |
);
|
|
|
190 |
} else {
|
|
|
191 |
$title = get_string('cmsdelete_title', 'core_courseformat');
|
|
|
192 |
$message = get_string('cmsdelete_info', 'core_courseformat', ['count' => count($ids)]);
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
return $output->confirm(
|
|
|
196 |
message: $message,
|
|
|
197 |
cancel: $this->returnurl,
|
|
|
198 |
continue: new url($this->actionurl, ['confirm' => 1]),
|
|
|
199 |
displayoptions: [
|
|
|
200 |
'confirmtitle' => $title,
|
|
|
201 |
'type' => single_button::BUTTON_DANGER,
|
|
|
202 |
'continuestr' => get_string('delete'),
|
|
|
203 |
]
|
|
|
204 |
);
|
|
|
205 |
}
|
|
|
206 |
}
|