Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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;
20
use action_link;
21
use single_select;
22
use url_select;
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 {
56
        global $DB;
57
 
58
        $url = new moodle_url('/mod/feedback/view.php', ['id' => $this->cmid]);
59
        $items['left'][]['actionlink'] = new action_link($url, get_string('back'), null, ['class' => 'btn btn-secondary']);
60
 
61
        if (has_capability('mod/feedback:edititems', $this->context)) {
62
            $editurl = new moodle_url('/mod/feedback/edit.php', $this->urlparams);
63
            $templateurl = new moodle_url('/mod/feedback/manage_templates.php', $this->urlparams);
64
            $importurl = new moodle_url('/mod/feedback/import.php', $this->urlparams);
65
 
66
            $options = [
67
                $editurl->out(false) => get_string('add_item', 'feedback'),
68
                $templateurl->out(false) => get_string('using_templates', '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)) {
75
                $selected = $templateurl;
76
            }
77
 
78
            $items['left'][]['urlselect'] = new url_select($options, $selected->out(false), null);
79
 
80
            $viewquestions = $editurl->compare($this->currenturl);
81
            if ($viewquestions) {
82
                $select = new single_select(new moodle_url('/mod/feedback/edit_item.php',
83
                    ['cmid' => $this->cmid, 'position' => $this->lastposition, 'sesskey' => sesskey()]),
84
                    'typ', feedback_load_feedback_items_options());
85
                $items['left'][]['singleselect'] = $select;
86
 
87
                if ($DB->record_exists('feedback_item', ['feedback' => $this->feedback->id])) {
88
                    $items['export'] = new action_link(
89
                        new moodle_url('/mod/feedback/export.php', $this->urlparams + ['action' => 'exportfile']),
90
                        get_string('export_questions', 'feedback'),
91
                        null,
92
                        ['class' => 'btn btn-secondary'],
93
                    );
94
                }
95
            }
96
        }
97
 
98
        return $items;
99
    }
100
}