| 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 mod_feedback\output;
|
|
|
18 |
|
|
|
19 |
use confirm_action;
|
|
|
20 |
use context_system;
|
|
|
21 |
use moodle_url;
|
| 1441 |
ariadna |
22 |
use pix_icon;
|
|
|
23 |
use core\output\action_menu;
|
|
|
24 |
use core\output\action_link;
|
|
|
25 |
use core\output\action_menu\link as action_menu_link;
|
|
|
26 |
use mod_feedback\manager;
|
| 1 |
efrain |
27 |
|
|
|
28 |
/**
|
|
|
29 |
* Class actionbar - Display the action bar
|
|
|
30 |
*
|
|
|
31 |
* @package mod_feedback
|
|
|
32 |
* @copyright 2021 Peter Dias
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class edit_template_action_bar extends base_action_bar {
|
|
|
36 |
/** @var int $templateid The template that is being edited/used */
|
|
|
37 |
private $templateid;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* edit_template_action_bar constructor.
|
|
|
41 |
* @param int $cmid
|
|
|
42 |
* @param int $templateid
|
| 1441 |
ariadna |
43 |
* @param string|null $mode This parameter has been deprecated since 4.5 and should not be used anymore.
|
| 1 |
efrain |
44 |
*/
|
| 1441 |
ariadna |
45 |
public function __construct(int $cmid, int $templateid, ?string $mode = null) {
|
|
|
46 |
if ($mode !== null) {
|
|
|
47 |
debugging(
|
|
|
48 |
'The age argument has been deprecated. Please remove it from your method calls.',
|
|
|
49 |
DEBUG_DEVELOPER,
|
|
|
50 |
);
|
|
|
51 |
}
|
| 1 |
efrain |
52 |
parent::__construct($cmid);
|
|
|
53 |
$this->templateid = $templateid;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Return the items to be used in the tertiary nav
|
|
|
58 |
*
|
|
|
59 |
* @return array
|
|
|
60 |
*/
|
|
|
61 |
public function get_items(): array {
|
| 1441 |
ariadna |
62 |
global $PAGE;
|
|
|
63 |
|
|
|
64 |
$templateurl = new moodle_url('/mod/feedback/manage_templates.php', $this->urlparams);
|
|
|
65 |
$template = manager::get_template_record($this->templateid);
|
|
|
66 |
|
|
|
67 |
// Back button.
|
| 1 |
efrain |
68 |
$items['left'][]['actionlink'] = new action_link($templateurl, get_string('back'), null, ['class' => 'btn btn-secondary']);
|
|
|
69 |
|
| 1441 |
ariadna |
70 |
// Actions.
|
| 1 |
efrain |
71 |
if (has_capability('mod/feedback:edititems', $this->context)) {
|
| 1441 |
ariadna |
72 |
$actionsselect = new action_menu();
|
|
|
73 |
$actionsselect->set_menu_trigger(get_string('actions'), 'btn btn-outline-primary');
|
|
|
74 |
$PAGE->requires->js_call_amd('mod_feedback/usetemplate', 'init');
|
|
|
75 |
|
|
|
76 |
// Use template.
|
|
|
77 |
$actionsselect->add(new action_menu_link(
|
|
|
78 |
new moodle_url('#'),
|
|
|
79 |
new pix_icon('i/files', get_string('preview')),
|
|
|
80 |
get_string('use_this_template', 'mod_feedback'),
|
|
|
81 |
false,
|
|
|
82 |
['data-action' => 'usetemplate', 'data-dataid' => $this->cmid, 'data-templateid' => $this->templateid],
|
|
|
83 |
));
|
| 1 |
efrain |
84 |
}
|
|
|
85 |
|
| 1441 |
ariadna |
86 |
// Delete.
|
| 1 |
efrain |
87 |
$showdelete = has_capability('mod/feedback:deletetemplate', $this->context);
|
|
|
88 |
if ($template->ispublic) {
|
| 1441 |
ariadna |
89 |
$showdelete = has_all_capabilities(
|
|
|
90 |
['mod/feedback:createpublictemplate', 'mod/feedback:deletetemplate'],
|
|
|
91 |
context_system::instance()
|
|
|
92 |
);
|
| 1 |
efrain |
93 |
}
|
|
|
94 |
if ($showdelete) {
|
| 1441 |
ariadna |
95 |
$params = $this->urlparams + [
|
| 1 |
efrain |
96 |
'deletetemplate' => $this->templateid,
|
|
|
97 |
'sesskey' => sesskey()
|
|
|
98 |
];
|
|
|
99 |
$deleteurl = new moodle_url('/mod/feedback/manage_templates.php', $params);
|
| 1441 |
ariadna |
100 |
$deleteaction = new action_link(
|
|
|
101 |
$deleteurl,
|
|
|
102 |
get_string('delete'),
|
|
|
103 |
new confirm_action(get_string('confirmdeletetemplate', 'feedback')),
|
|
|
104 |
['class' => 'text-danger'],
|
|
|
105 |
new pix_icon('t/delete', get_string('delete_template', 'feedback')),
|
|
|
106 |
);
|
|
|
107 |
$actionsselect->add_secondary_action($deleteaction);
|
| 1 |
efrain |
108 |
}
|
|
|
109 |
|
| 1441 |
ariadna |
110 |
$items['actionsselect'] = count($actionsselect->get_primary_actions()) > 0 ? $actionsselect : null;
|
|
|
111 |
|
| 1 |
efrain |
112 |
return $items;
|
|
|
113 |
}
|
|
|
114 |
}
|