| 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 moodle_url;
|
| 1441 |
ariadna |
20 |
use action_menu;
|
|
|
21 |
use action_menu_link;
|
|
|
22 |
use pix_icon;
|
| 1 |
efrain |
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Class actionbar - Display the action bar
|
|
|
26 |
*
|
|
|
27 |
* @package mod_feedback
|
|
|
28 |
* @copyright 2021 Peter Dias
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class edit_action_bar extends base_action_bar {
|
|
|
32 |
/** @var moodle_url $currenturl The current page url */
|
|
|
33 |
private $currenturl;
|
|
|
34 |
/** @var int|null $lastposition The index of the last question type in the feedback module */
|
|
|
35 |
private $lastposition;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* edit_action_bar constructor.
|
|
|
39 |
*
|
|
|
40 |
* @param int $cmid The course module id
|
|
|
41 |
* @param moodle_url $pageurl The current page url
|
|
|
42 |
* @param int|null $lastposition Index of the last question in the feedback
|
|
|
43 |
*/
|
|
|
44 |
public function __construct(int $cmid, moodle_url $pageurl, ?int $lastposition = null) {
|
|
|
45 |
parent::__construct($cmid);
|
|
|
46 |
$this->currenturl = $pageurl;
|
|
|
47 |
$this->lastposition = $lastposition;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Return the items to be used for the tertiary nav
|
|
|
52 |
*
|
|
|
53 |
* @return array
|
|
|
54 |
*/
|
|
|
55 |
public function get_items(): array {
|
| 1441 |
ariadna |
56 |
if (!has_capability('mod/feedback:edititems', $this->context)) {
|
|
|
57 |
return [];
|
|
|
58 |
}
|
|
|
59 |
return [
|
|
|
60 |
'addselect' => $this->get_add_question_menu(),
|
|
|
61 |
'actionsselect' => $this->get_edit_actions_menu(),
|
|
|
62 |
];
|
|
|
63 |
}
|
| 1 |
efrain |
64 |
|
| 1441 |
ariadna |
65 |
/**
|
|
|
66 |
* Return the add question menu
|
|
|
67 |
*
|
|
|
68 |
* @return action_menu
|
|
|
69 |
*/
|
|
|
70 |
private function get_add_question_menu(): action_menu {
|
|
|
71 |
$addselect = new action_menu();
|
|
|
72 |
$addselect->set_menu_trigger(get_string('add_item', 'mod_feedback'), 'btn btn-primary');
|
|
|
73 |
$addselect->set_menu_left();
|
|
|
74 |
$addselectparams = ['cmid' => $this->cmid, 'position' => $this->lastposition, 'sesskey' => sesskey()];
|
|
|
75 |
foreach (feedback_load_feedback_items_options() as $key => $value) {
|
|
|
76 |
$addselect->add(new action_menu_link(
|
|
|
77 |
new moodle_url('/mod/feedback/edit_item.php', $addselectparams + ['typ' => $key]),
|
|
|
78 |
null,
|
|
|
79 |
$value,
|
|
|
80 |
false,
|
|
|
81 |
));
|
|
|
82 |
}
|
| 1 |
efrain |
83 |
|
| 1441 |
ariadna |
84 |
return $addselect;
|
|
|
85 |
}
|
| 1 |
efrain |
86 |
|
| 1441 |
ariadna |
87 |
/**
|
|
|
88 |
* Return the edit actions menu
|
|
|
89 |
*
|
|
|
90 |
* @return action_menu
|
|
|
91 |
*/
|
|
|
92 |
private function get_edit_actions_menu(): action_menu {
|
|
|
93 |
global $DB, $PAGE;
|
| 1 |
efrain |
94 |
|
| 1441 |
ariadna |
95 |
$actionsselect = new action_menu();
|
|
|
96 |
$actionsselect->set_menu_trigger(get_string('actions'), 'btn btn-outline-primary');
|
| 1 |
efrain |
97 |
|
| 1441 |
ariadna |
98 |
$hasitems = $DB->record_exists('feedback_item', ['feedback' => $this->feedback->id]);
|
|
|
99 |
// Export.
|
|
|
100 |
if ($hasitems) {
|
|
|
101 |
$exporturl = new moodle_url('/mod/feedback/export.php', $this->urlparams + ['action' => 'exportfile']);
|
|
|
102 |
$actionsselect->add(new action_menu_link(
|
|
|
103 |
$exporturl,
|
|
|
104 |
new pix_icon('i/file_export', get_string('export_questions', 'feedback')),
|
|
|
105 |
get_string('export_questions', 'feedback'),
|
|
|
106 |
false,
|
|
|
107 |
));
|
|
|
108 |
}
|
| 1 |
efrain |
109 |
|
| 1441 |
ariadna |
110 |
// Import.
|
|
|
111 |
$importurl = new moodle_url('/mod/feedback/import.php', $this->urlparams);
|
|
|
112 |
$actionsselect->add(new action_menu_link(
|
|
|
113 |
$importurl,
|
|
|
114 |
new pix_icon('i/file_import', get_string('import_questions', 'feedback')),
|
|
|
115 |
get_string('import_questions', 'feedback'),
|
|
|
116 |
false,
|
|
|
117 |
));
|
| 1 |
efrain |
118 |
|
| 1441 |
ariadna |
119 |
// Save as template.
|
|
|
120 |
$cancreatetemplates = has_any_capability([
|
|
|
121 |
'mod/feedback:createprivatetemplate',
|
|
|
122 |
'mod/feedback:createpublictemplate'], \context_module::instance($this->cmid));
|
|
|
123 |
if ($cancreatetemplates && $hasitems) {
|
|
|
124 |
$PAGE->requires->js_call_amd('mod_feedback/createtemplate', 'init');
|
|
|
125 |
$actionsselect->add(new action_menu_link(
|
|
|
126 |
new moodle_url('#'),
|
|
|
127 |
new pix_icon('i/file_plus', get_string('save_as_new_template', 'feedback')),
|
|
|
128 |
get_string('save_as_new_template', 'feedback'),
|
|
|
129 |
false,
|
|
|
130 |
['data-action' => 'createtemplate', 'data-dataid' => $this->cmid],
|
|
|
131 |
));
|
| 1 |
efrain |
132 |
}
|
|
|
133 |
|
| 1441 |
ariadna |
134 |
return $actionsselect;
|
| 1 |
efrain |
135 |
}
|
|
|
136 |
}
|