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 action_link;
20
use moodle_url;
21
 
22
/**
23
 * Class standard_action_bar
24
 *
25
 * The default tertiary nav on the module landing page
26
 *
27
 * @copyright 2021 Peter Dias
28
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
29
 * @package mod_feedback
30
 */
31
class standard_action_bar extends base_action_bar {
32
    /** @var int $startpage The page to resume with. */
33
    private $startpage;
34
    /** @var int $viewcompletion Whether or not the user can finish the feedback */
35
    private $viewcompletion;
36
 
37
    /**
38
     * standard_action_bar constructor.
39
     *
40
     * @param int $cmid
41
     * @param bool $viewcompletion Whether or not the user can finish the feedback
42
     * @param int|null $startpage The page to resume with.
43
     * @param int|null $courseid The course that the feedback is being accessed from. If null, courseid will be
44
     *                              set via the $cmid relationship
45
     */
46
    public function __construct(int $cmid, bool $viewcompletion, ?int $startpage = null, ?int $courseid = null) {
47
        parent::__construct($cmid);
48
        $this->startpage = $startpage;
49
        $this->viewcompletion = $viewcompletion;
50
        if ($courseid && $courseid != $this->course->id) {
51
            $this->course = get_course($courseid);
52
        }
53
        $this->urlparams['courseid'] = $this->course->id;
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 {
62
        $items = [];
63
 
64
        if (has_capability('mod/feedback:edititems', $this->context)) {
65
            $editurl = new moodle_url('/mod/feedback/edit.php', $this->urlparams);
66
            $items['left'][]['actionlink'] = new action_link($editurl, get_string('edit_items', 'feedback'),
67
                null, ['class' => 'btn btn-secondary']);
68
        }
69
 
70
        // The preview icon should be displayed only to users with capability to edit or view reports (to include
71
        // non-editing teachers too).
72
        $capabilities = [
73
            'mod/feedback:edititems',
74
            'mod/feedback:viewreports',
75
        ];
76
        if (has_any_capability($capabilities, $this->context)) {
77
            $previewlnk = new moodle_url('/mod/feedback/print.php', array('id' => $this->cmid));
78
            if ($this->course->id) {
79
                $previewlnk->param('courseid', $this->course->id);
80
            }
81
            $items['left'][]['actionlink'] = new action_link($previewlnk, get_string('previewquestions', 'feedback'),
82
            null, ['class' => 'btn btn-secondary']);
83
        }
84
 
85
        if ($this->viewcompletion) {
86
            // Display a link to complete feedback or resume.
87
            $completeurl = new moodle_url('/mod/feedback/complete.php',
88
                ['id' => $this->cmid, 'courseid' => $this->course->id]);
89
            if ($this->startpage) {
90
                $completeurl->param('gopage', $this->startpage);
91
                $label = get_string('continue_the_form', 'feedback');
92
            } else {
93
                $label = get_string('complete_the_form', 'feedback');
94
            }
95
            $items['left'][]['actionlink'] = new action_link($completeurl, $label, null, ['class' => 'btn btn-primary']);
96
        }
97
 
98
        return $items;
99
    }
100
}