Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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 {
1441 ariadna 48
        $courserenderer = $this->page->get_renderer('core', 'course');
1 efrain 49
        $resetlink = new moodle_url('/grade/report/singleview/index.php', ['id' => $course->id, 'group' => $groupid ?? 0]);
1441 ariadna 50
        $usersearch = '';
1 efrain 51
 
1441 ariadna 52
        if ($userid) {
53
            $user = core_user::get_user($userid);
54
            $usersearch = fullname($user);
1 efrain 55
        }
56
 
1441 ariadna 57
        return $courserenderer->render(
58
            new \core_course\output\actionbar\user_selector(
59
                course: $course,
60
                resetlink: $resetlink,
61
                userid: $userid,
62
                groupid: $groupid,
63
                usersearch: $usersearch
64
            )
1 efrain 65
        );
66
    }
67
 
68
    /**
69
     * Renders the grade items selector trigger element.
70
     *
71
     * @param object $course The course object.
72
     * @param int|null $gradeitemid The grade item ID.
73
     * @return string The raw HTML to render.
74
     */
75
    public function grade_items_selector(object $course, ?int $gradeitemid = null): string {
76
 
77
        $data = [
78
            'name' => 'itemid',
79
            'courseid' => $course->id,
80
            'instance' => rand(),
81
        ];
82
 
83
        // If a particular grade item option is selected (not in zero state).
84
        if ($gradeitemid) {
85
            $gradeitemname = grade_item::fetch(['id' => $gradeitemid])->get_name(true);
86
            $data['selectedoption'] = [
87
                'text' => $gradeitemname,
88
            ];
89
            $data['itemid'] = $gradeitemid;
90
        }
91
 
92
        $sbody = $this->render_from_template('core/local/comboboxsearch/searchbody', [
93
            'courseid' => $course->id,
94
            'currentvalue' => optional_param('gradesearchvalue', '', PARAM_NOTAGS),
95
            'instance' => $data['instance'],
96
        ]);
97
        $dropdown = new comboboxsearch(
98
            false,
99
            $this->render_from_template('gradereport_singleview/grade_item_selector', $data),
100
            $sbody,
101
            'grade-search h-100',
102
            'gradesearchwidget h-100',
103
            'gradesearchdropdown overflow-auto',
104
            null,
105
            true,
106
            get_string('selectagrade', 'gradereport_singleview'),
107
            'itemid',
108
            $gradeitemid
109
        );
1441 ariadna 110
        return $this->render($dropdown);
1 efrain 111
    }
112
 
113
    /**
114
     * Creates and renders previous/next user/grade item navigation.
115
     *
116
     * @param object $gpr grade plugin return tracking object
117
     * @param int $courseid The course ID.
118
     * @param \context_course $context Context of the report.
119
     * @param singleview $report The single view report class.
120
     * @param int|null $groupid Group ID
121
     * @param string $itemtype User or Grade item type
122
     * @param int $itemid Either User ID or Grade item ID
123
     * @return string The raw HTML to render.
124
     * @throws moodle_exception
125
     */
126
    public function report_navigation(object $gpr, int $courseid, \context_course $context, singleview $report,
127
                                      ?int $groupid, string $itemtype, int $itemid): string {
128
 
129
        $navigation = '';
130
        $options = $report->screen->options();
131
 
132
        $optionkeys = array_keys($options);
133
        $optionitemid = array_shift($optionkeys);
134
 
135
        $relreport = new gradereport_singleview\report\singleview(
136
            $courseid, $gpr, $context,
137
            $report->screen->item_type(), $optionitemid
138
        );
139
        $reloptions = $relreport->screen->options();
140
        $reloptionssorting = array_keys($relreport->screen->options());
141
 
142
        $i = array_search($itemid, $reloptionssorting);
143
        $navparams = ['item' => $itemtype, 'id' => $courseid, 'group' => $groupid];
144
 
145
        // Determine directionality so that icons can be modified to suit language.
146
        $previousarrow = right_to_left() ? 'right' : 'left';
147
        $nextarrow = right_to_left() ? 'left' : 'right';
148
 
149
        if ($i > 0) {
150
            $navparams['itemid'] = $reloptionssorting[$i - 1];
151
            $link = (new moodle_url('/grade/report/singleview/index.php', $navparams))
152
                ->out(false);
153
            $navigationdata['previoususer'] = [
154
                'name' => $reloptions[$navparams['itemid']],
155
                'url' => $link,
156
                'previousarrow' => $previousarrow
157
            ];
158
        }
159
        if ($i < count($reloptionssorting) - 1) {
160
            $navparams['itemid'] = $reloptionssorting[$i + 1];
161
            $link = (new moodle_url('/grade/report/singleview/index.php', $navparams))
162
                ->out(false);
163
            $navigationdata['nextuser'] = [
164
                'name' => $reloptions[$navparams['itemid']],
165
                'url' => $link,
166
                'nextarrow' => $nextarrow
167
            ];
168
        }
169
 
170
        if ($report->screen->supports_paging()) {
171
            $navigationdata['perpageselect'] = $report->screen->perpage_select();
172
        }
173
 
174
        if (isset($navigationdata)) {
175
            $navigation = $this->render_from_template('gradereport_singleview/report_navigation', $navigationdata);
176
        }
177
        return $navigation;
178
    }
179
 
180
}