Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 15... Línea 15...
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace mod_feedback\output;
17
namespace mod_feedback\output;
18
 
18
 
19
use moodle_url;
19
use moodle_url;
20
use action_link;
20
use action_menu;
Línea 21... Línea 21...
21
use single_select;
21
use action_menu_link;
22
use url_select;
22
use pix_icon;
23
 
23
 
24
/**
24
/**
Línea 51... Línea 51...
51
     * Return the items to be used for the tertiary nav
51
     * Return the items to be used for the tertiary nav
52
     *
52
     *
53
     * @return array
53
     * @return array
54
     */
54
     */
55
    public function get_items(): array {
55
    public function get_items(): array {
-
 
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
    }
-
 
64
 
-
 
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,
56
        global $DB;
81
            ));
-
 
82
        }
Línea -... Línea 83...
-
 
83
 
-
 
84
        return $addselect;
-
 
85
    }
-
 
86
 
-
 
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;
-
 
94
 
-
 
95
        $actionsselect = new action_menu();
-
 
96
        $actionsselect->set_menu_trigger(get_string('actions'), 'btn btn-outline-primary');
-
 
97
 
-
 
98
        $hasitems = $DB->record_exists('feedback_item', ['feedback' => $this->feedback->id]);
-
 
99
        // Export.
57
 
100
        if ($hasitems) {
-
 
101
            $exporturl = new moodle_url('/mod/feedback/export.php', $this->urlparams + ['action' => 'exportfile']);
-
 
102
            $actionsselect->add(new action_menu_link(
58
        $url = new moodle_url('/mod/feedback/view.php', ['id' => $this->cmid]);
103
                $exporturl,
-
 
104
                new pix_icon('i/file_export', get_string('export_questions', 'feedback')),
-
 
105
                get_string('export_questions', 'feedback'),
-
 
106
                false,
-
 
107
            ));
Línea 59... Línea 108...
59
        $items['left'][]['actionlink'] = new action_link($url, get_string('back'), null, ['class' => 'btn btn-secondary']);
108
        }
60
 
109
 
61
        if (has_capability('mod/feedback:edititems', $this->context)) {
-
 
62
            $editurl = new moodle_url('/mod/feedback/edit.php', $this->urlparams);
110
        // Import.
63
            $templateurl = new moodle_url('/mod/feedback/manage_templates.php', $this->urlparams);
-
 
64
            $importurl = new moodle_url('/mod/feedback/import.php', $this->urlparams);
111
        $importurl = new moodle_url('/mod/feedback/import.php', $this->urlparams);
65
 
112
        $actionsselect->add(new action_menu_link(
66
            $options = [
-
 
67
                $editurl->out(false) => get_string('add_item', 'feedback'),
113
            $importurl,
68
                $templateurl->out(false) => get_string('using_templates', 'feedback'),
114
            new pix_icon('i/file_import', get_string('import_questions', 'feedback')),
69
                $importurl->out(false) => get_string('import_questions', 'feedback')
-
 
70
            ];
-
 
71
 
-
 
72
            $selected = $this->currenturl;
-
 
73
            // Template pages can have sub pages, so match these.
-
 
74
            if ($this->currenturl->compare(new moodle_url('/mod/feedback/use_templ.php'), URL_MATCH_BASE)) {
115
            get_string('import_questions', 'feedback'),
75
                $selected = $templateurl;
116
            false,
76
            }
117
        ));
77
 
-
 
78
            $items['left'][]['urlselect'] = new url_select($options, $selected->out(false), null);
118
 
79
 
119
        // Save as template.
80
            $viewquestions = $editurl->compare($this->currenturl);
120
        $cancreatetemplates = has_any_capability([
81
            if ($viewquestions) {
121
            'mod/feedback:createprivatetemplate',
82
                $select = new single_select(new moodle_url('/mod/feedback/edit_item.php',
122
            'mod/feedback:createpublictemplate'], \context_module::instance($this->cmid));
83
                    ['cmid' => $this->cmid, 'position' => $this->lastposition, 'sesskey' => sesskey()]),
123
        if ($cancreatetemplates && $hasitems) {
84
                    'typ', feedback_load_feedback_items_options());
-
 
85
                $items['left'][]['singleselect'] = $select;
-
 
86
 
124
            $PAGE->requires->js_call_amd('mod_feedback/createtemplate', 'init');
87
                if ($DB->record_exists('feedback_item', ['feedback' => $this->feedback->id])) {
125
            $actionsselect->add(new action_menu_link(
88
                    $items['export'] = new action_link(
126
                new moodle_url('#'),
89
                        new moodle_url('/mod/feedback/export.php', $this->urlparams + ['action' => 'exportfile']),
127
                new pix_icon('i/file_plus', get_string('save_as_new_template', 'feedback')),
90
                        get_string('export_questions', 'feedback'),
128
                get_string('save_as_new_template', 'feedback'),
91
                        null,
-
 
92
                        ['class' => 'btn btn-secondary'],
-
 
93
                    );
129
                false,
94
                }
130
                ['data-action' => 'createtemplate', 'data-dataid' => $this->cmid],
Línea 95... Línea 131...
95
            }
131
            ));
96
        }
132
        }
97
 
133