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 gradereport_grader\output;
18
 
19
use core\output\comboboxsearch;
20
use core_grades\output\general_action_bar;
21
use moodle_url;
22
 
23
/**
24
 * Renderable class for the action bar elements in the grader report.
25
 *
26
 * @package    gradereport_grader
27
 * @copyright  2022 Mihail Geshoski <mihail@moodle.com>
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class action_bar extends \core_grades\output\action_bar {
31
 
32
    /** @var string $usersearch The content that the current user is looking for. */
33
    protected string $usersearch = '';
34
 
35
    /** @var int $userid The ID of the user that the current user is looking for. */
36
    protected int $userid = 0;
37
 
38
    /**
39
     * The class constructor.
40
     *
41
     * @param \context_course $context The context object.
42
     */
43
    public function __construct(\context_course $context) {
44
        parent::__construct($context);
45
 
46
        $this->userid = optional_param('gpr_userid', 0, PARAM_INT);
47
        $this->usersearch = optional_param('gpr_search', '', PARAM_NOTAGS);
48
 
49
        if ($this->userid) {
50
            $user = \core_user::get_user($this->userid);
51
            $this->usersearch = fullname($user);
52
        }
53
    }
54
 
55
    /**
56
     * Returns the template for the action bar.
57
     *
58
     * @return string
59
     */
60
    public function get_template(): string {
61
        return 'gradereport_grader/action_bar';
62
    }
63
 
64
    /**
65
     * Export the data for the mustache template.
66
     *
67
     * @param \renderer_base $output renderer to be used to render the action bar elements.
68
     * @return array
69
     * @throws \moodle_exception
70
     */
71
    public function export_for_template(\renderer_base $output): array {
72
        global $PAGE, $OUTPUT, $SESSION, $USER;
73
        // If in the course context, we should display the general navigation selector in gradebook.
74
        $courseid = $this->context->instanceid;
75
        // Get the data used to output the general navigation selector.
76
        $generalnavselector = new general_action_bar($this->context,
77
            new moodle_url('/grade/report/grader/index.php', ['id' => $courseid]), 'gradereport', 'grader');
78
 
79
        $data = $generalnavselector->export_for_template($output);
80
 
81
        // If the user has the capability to view all grades, display the group selector (if applicable), the user selector
82
        // and the view mode selector (if applicable).
83
        if (has_capability('moodle/grade:viewall', $this->context)) {
84
            $course = get_course($courseid);
85
            $gradesrenderer = $PAGE->get_renderer('core_grades');
86
 
87
            $initialscontent = $gradesrenderer->initials_selector(
88
                $course,
89
                $this->context,
90
                '/grade/report/grader/index.php'
91
            );
92
 
93
            $firstnameinitial = $SESSION->gradereport["filterfirstname-{$this->context->id}"] ?? '';
94
            $lastnameinitial  = $SESSION->gradereport["filtersurname-{$this->context->id}"] ?? '';
95
 
96
            $initialselector = new comboboxsearch(
97
                false,
98
                $initialscontent->buttoncontent,
99
                $initialscontent->dropdowncontent,
100
                'initials-selector',
101
                'initialswidget',
102
                'initialsdropdown',
103
                $initialscontent->buttonheader,
104
                true,
105
                get_string('filterbyname', 'core_grades'),
106
                'nameinitials',
107
                json_encode([
108
                    'first' => $firstnameinitial,
109
                    'last' => $lastnameinitial,
110
                ])
111
            );
112
            $data['initialselector'] = $initialselector->export_for_template($output);
113
            $data['groupselector'] = $gradesrenderer->group_selector($course);
114
 
115
            $resetlink = new moodle_url('/grade/report/grader/index.php', ['id' => $courseid]);
116
            $searchinput = $OUTPUT->render_from_template('core_user/comboboxsearch/user_selector', [
117
                'currentvalue' => $this->usersearch,
118
                'courseid' => $courseid,
119
                'instance' => rand(),
120
                'resetlink' => $resetlink->out(false),
121
                'group' => 0,
122
                'name' => 'usersearch',
123
                'value' => json_encode([
124
                    'userid' => $this->userid,
125
                    'search' => $this->usersearch,
126
                ]),
127
            ]);
128
            $searchdropdown = new comboboxsearch(
129
                true,
130
                $searchinput,
131
                null,
132
                'user-search d-flex',
133
                null,
134
                'usersearchdropdown overflow-auto',
135
                null,
136
                false,
137
            );
138
            $data['searchdropdown'] = $searchdropdown->export_for_template($output);
139
 
140
            // The collapsed column dialog is aligned to the edge of the screen, we need to place it such that it also aligns.
141
            $collapsemenudirection = right_to_left() ? 'dropdown-menu-left' : 'dropdown-menu-right';
142
 
143
            $collapse = new comboboxsearch(
144
                true,
145
                get_string('collapsedcolumns', 'gradereport_grader', 0),
146
                null,
147
                'collapse-columns',
148
                'collapsecolumn',
149
                'collapsecolumndropdown p-3 flex-column ' . $collapsemenudirection,
150
                null,
151
                true,
152
                get_string('aria:dropdowncolumns', 'gradereport_grader'),
153
                'collapsedcolumns'
154
            );
155
            $data['collapsedcolumns'] = [
156
                'classes' => 'd-none',
157
                'content' => $collapse->export_for_template($output)
158
            ];
159
 
160
            if ($course->groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $this->context)) {
161
                $allowedgroups = groups_get_all_groups($course->id, 0, $course->defaultgroupingid);
162
            } else {
163
                $allowedgroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid);
164
            }
165
 
166
            if (
167
                $firstnameinitial ||
168
                $lastnameinitial ||
169
                groups_get_course_group($course, true, $allowedgroups) ||
170
                $this->usersearch
171
            ) {
172
                $reset = new moodle_url('/grade/report/grader/index.php', [
173
                    'id' => $courseid,
174
                    'group' => 0,
175
                    'sifirst' => '',
176
                    'silast' => ''
177
                ]);
178
                $data['pagereset'] = $reset->out(false);
179
            }
180
        }
181
 
182
        return $data;
183
    }
184
}