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
/**
18
 * Renderer for the grade single view report.
19
 *
20
 * @package   gradereport_singleview
21
 * @copyright 2022 Mihail Geshoski <mihail@moodle.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
use core\output\comboboxsearch;
26
use gradereport_singleview\report\singleview;
27
 
28
/**
29
 * Custom renderer for the single view report.
30
 *
31
 * To get an instance of this use the following code:
32
 * $renderer = $PAGE->get_renderer('gradereport_singleview');
33
 *
34
 * @copyright 2022 Mihail Geshoski <mihail@moodle.com>
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class gradereport_singleview_renderer extends plugin_renderer_base {
38
 
39
    /**
40
     * Renders the user selector trigger element.
41
     *
42
     * @param object $course The course object.
43
     * @param int|null $userid The user ID.
44
     * @param int|null $groupid The group ID.
45
     * @return string The raw HTML to render.
46
     */
47
    public function users_selector(object $course, ?int $userid = null, ?int $groupid = null): string {
48
        $resetlink = new moodle_url('/grade/report/singleview/index.php', ['id' => $course->id, 'group' => $groupid ?? 0]);
49
        $submitteduserid = optional_param('userid', '', PARAM_INT);
50
 
51
        if ($submitteduserid) {
52
            $user = core_user::get_user($submitteduserid);
53
            $currentvalue = fullname($user);
54
        } else {
55
            $currentvalue = '';
56
        }
57
 
58
        $data = [
59
            'currentvalue' => $currentvalue,
60
            'courseid' => $course->id,
61
            'instance' => rand(),
62
            'group' => $groupid ?? 0,
63
            'resetlink' => $resetlink->out(false),
64
            'name' => 'userid',
65
            'value' => $submitteduserid ?? '',
66
        ];
67
        $dropdown = new comboboxsearch(
68
            true,
69
            $this->render_from_template('core_user/comboboxsearch/user_selector', $data),
70
            null,
71
            'user-search d-flex',
72
            null,
73
            'usersearchdropdown overflow-auto',
74
            null,
75
            false,
76
        );
77
        return $this->render_from_template($dropdown->get_template(), $dropdown->export_for_template($this));
78
    }
79
 
80
    /**
81
     * Renders the grade items selector trigger element.
82
     *
83
     * @param object $course The course object.
84
     * @param int|null $gradeitemid The grade item ID.
85
     * @return string The raw HTML to render.
86
     */
87
    public function grade_items_selector(object $course, ?int $gradeitemid = null): string {
88
 
89
        $data = [
90
            'name' => 'itemid',
91
            'courseid' => $course->id,
92
            'instance' => rand(),
93
        ];
94
 
95
        // If a particular grade item option is selected (not in zero state).
96
        if ($gradeitemid) {
97
            $gradeitemname = grade_item::fetch(['id' => $gradeitemid])->get_name(true);
98
            $data['selectedoption'] = [
99
                'text' => $gradeitemname,
100
            ];
101
            $data['itemid'] = $gradeitemid;
102
        }
103
 
104
        $sbody = $this->render_from_template('core/local/comboboxsearch/searchbody', [
105
            'courseid' => $course->id,
106
            'currentvalue' => optional_param('gradesearchvalue', '', PARAM_NOTAGS),
107
            'instance' => $data['instance'],
108
        ]);
109
        $dropdown = new comboboxsearch(
110
            false,
111
            $this->render_from_template('gradereport_singleview/grade_item_selector', $data),
112
            $sbody,
113
            'grade-search h-100',
114
            'gradesearchwidget h-100',
115
            'gradesearchdropdown overflow-auto',
116
            null,
117
            true,
118
            get_string('selectagrade', 'gradereport_singleview'),
119
            'itemid',
120
            $gradeitemid
121
        );
122
        return $this->render_from_template($dropdown->get_template(), $dropdown->export_for_template($this));
123
    }
124
 
125
    /**
126
     * Creates and renders previous/next user/grade item navigation.
127
     *
128
     * @param object $gpr grade plugin return tracking object
129
     * @param int $courseid The course ID.
130
     * @param \context_course $context Context of the report.
131
     * @param singleview $report The single view report class.
132
     * @param int|null $groupid Group ID
133
     * @param string $itemtype User or Grade item type
134
     * @param int $itemid Either User ID or Grade item ID
135
     * @return string The raw HTML to render.
136
     * @throws moodle_exception
137
     */
138
    public function report_navigation(object $gpr, int $courseid, \context_course $context, singleview $report,
139
                                      ?int $groupid, string $itemtype, int $itemid): string {
140
 
141
        $navigation = '';
142
        $options = $report->screen->options();
143
 
144
        $optionkeys = array_keys($options);
145
        $optionitemid = array_shift($optionkeys);
146
 
147
        $relreport = new gradereport_singleview\report\singleview(
148
            $courseid, $gpr, $context,
149
            $report->screen->item_type(), $optionitemid
150
        );
151
        $reloptions = $relreport->screen->options();
152
        $reloptionssorting = array_keys($relreport->screen->options());
153
 
154
        $i = array_search($itemid, $reloptionssorting);
155
        $navparams = ['item' => $itemtype, 'id' => $courseid, 'group' => $groupid];
156
 
157
        // Determine directionality so that icons can be modified to suit language.
158
        $previousarrow = right_to_left() ? 'right' : 'left';
159
        $nextarrow = right_to_left() ? 'left' : 'right';
160
 
161
        if ($i > 0) {
162
            $navparams['itemid'] = $reloptionssorting[$i - 1];
163
            $link = (new moodle_url('/grade/report/singleview/index.php', $navparams))
164
                ->out(false);
165
            $navigationdata['previoususer'] = [
166
                'name' => $reloptions[$navparams['itemid']],
167
                'url' => $link,
168
                'previousarrow' => $previousarrow
169
            ];
170
        }
171
        if ($i < count($reloptionssorting) - 1) {
172
            $navparams['itemid'] = $reloptionssorting[$i + 1];
173
            $link = (new moodle_url('/grade/report/singleview/index.php', $navparams))
174
                ->out(false);
175
            $navigationdata['nextuser'] = [
176
                'name' => $reloptions[$navparams['itemid']],
177
                'url' => $link,
178
                'nextarrow' => $nextarrow
179
            ];
180
        }
181
 
182
        if ($report->screen->supports_paging()) {
183
            $navigationdata['perpageselect'] = $report->screen->perpage_select();
184
        }
185
 
186
        if (isset($navigationdata)) {
187
            $navigation = $this->render_from_template('gradereport_singleview/report_navigation', $navigationdata);
188
        }
189
        return $navigation;
190
    }
191
 
192
}