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 user report
19
 *
20
 * @package   gradereport_user
21
 * @copyright 2010 Sam Hemelryk
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
use core\output\comboboxsearch;
26
 
27
/**
28
 * Custom renderer for the user grade report
29
 *
30
 * To get an instance of this use the following code:
31
 * $renderer = $PAGE->get_renderer('gradereport_user');
32
 *
33
 * @copyright 2010 Sam Hemelryk
34
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 */
36
class gradereport_user_renderer extends plugin_renderer_base {
37
 
38
    /**
39
     * Small rendering function that helps with outputting the relevant user selector.
40
     *
41
     * @param string $report
42
     * @param stdClass $course
43
     * @param int $userid
44
     * @param null|int $groupid
45
     * @param bool $includeall
46
     * @return string The raw HTML to render.
47
     * @throws coding_exception
48
     */
49
    public function graded_users_selector(string $report, stdClass $course, int $userid, ?int $groupid, bool $includeall): string {
50
 
51
        $select = grade_get_graded_users_select($report, $course, $userid, $groupid, $includeall);
52
        $output = html_writer::tag('div', $this->output->render($select), ['id' => 'graded_users_selector']);
53
        $output .= html_writer::tag('p', '', ['style' => 'page-break-after: always;']);
54
 
55
        return $output;
56
    }
57
 
58
    /**
59
     * Creates and renders the single select box for the user view.
60
     *
61
     * @param int $userid The selected userid
62
     * @param int $userview The current view user setting constant
63
     * @return string
64
     */
65
    public function view_user_selector(int $userid, int $userview): string {
66
        global $USER;
67
        $url = $this->page->url;
68
        if ($userid != $USER->id) {
69
            $url->param('userid', $userid);
70
        }
71
 
72
        $options = [
73
            GRADE_REPORT_USER_VIEW_USER => get_string('otheruser', 'grades'),
74
            GRADE_REPORT_USER_VIEW_SELF => get_string('myself', 'grades')
75
        ];
76
        $select = new single_select($url, 'userview', $options, $userview, null);
77
 
78
        $select->label = get_string('viewas', 'grades');
79
 
80
        $output = html_writer::tag('div', $this->output->render($select), ['class' => 'view_users_selector']);
81
 
82
        return $output;
83
    }
84
 
85
    /**
86
     * Renders the user selector trigger element.
87
     *
88
     * @param object $course The course object.
89
     * @param int|null $userid The user ID.
90
     * @param int|null $groupid The group ID.
1441 ariadna 91
     * @param string $usersearch Search string.
1 efrain 92
     * @return string The raw HTML to render.
93
     * @throws coding_exception
1441 ariadna 94
     * @deprecated since Moodle 4.5. See user_selector use in \gradereport_user\output\action_bar::export_for_template.
1 efrain 95
     */
1441 ariadna 96
    public function users_selector(object $course, ?int $userid = null, ?int $groupid = null, string $usersearch = ''): string {
1 efrain 97
 
1441 ariadna 98
        debugging('users_selector is deprecated.', DEBUG_DEVELOPER);
1 efrain 99
 
1441 ariadna 100
        $courserenderer = $this->page->get_renderer('core', 'course');
101
        $resetlink = new moodle_url('/grade/report/user/index.php', ['id' => $course->id, 'group' => 0]);
102
        $baseurl = new moodle_url('/grade/report/user/index.php', ['id' => $course->id]);
103
        $this->page->requires->js_call_amd('gradereport_user/user', 'init', [$baseurl->out(false)]);
104
        return $courserenderer->render(
105
            new \core_course\output\actionbar\user_selector(
106
                course: $course,
107
                resetlink: $resetlink,
108
                userid: $userid,
109
                groupid: $groupid,
110
                usersearch: $usersearch
111
            )
1 efrain 112
        );
113
    }
114
 
115
    /**
116
     * Creates and renders previous/next user navigation.
117
     *
118
     * @param graded_users_iterator $gui Objects that is used to iterate over a list of gradable users in the course.
119
     * @param int $userid The ID of the current user.
120
     * @param int $courseid The course ID.
121
     * @return string The raw HTML to render.
122
     */
123
    public function user_navigation(graded_users_iterator $gui, int $userid, int $courseid): string {
124
 
125
        $navigationdata = [];
126
 
127
        $users = [];
128
        while ($userdata = $gui->next_user()) {
129
            $users[$userdata->user->id] = $userdata->user;
130
        }
131
 
132
        $arraykeys = array_keys($users);
133
        $keynumber = array_search($userid, $arraykeys);
134
 
135
        // Without a valid user or users list, there's nothing to render.
136
        if ($keynumber === false) {
137
            return '';
138
        }
139
 
140
        // Determine directionality so that icons can be modified to suit language.
141
        $previousarrow = right_to_left() ? 'right' : 'left';
142
        $nextarrow = right_to_left() ? 'left' : 'right';
143
 
144
        // If the current user is not the first one in the list, find and render the previous user.
145
        if ($keynumber !== 0) {
146
            $previoususer = $users[$arraykeys[$keynumber - 1]];
147
            $navigationdata['previoususer'] = [
148
                'name' => fullname($previoususer),
149
                'url' => (new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $previoususer->id]))
150
                    ->out(false),
151
                'previousarrow' => $previousarrow
152
            ];
153
        }
154
        // If the current user is not the last one in the list, find and render the last user.
155
        if ($keynumber < count($users) - 1) {
156
            $nextuser = $users[$arraykeys[$keynumber + 1]];
157
            $navigationdata['nextuser'] = [
158
                'name' => fullname($nextuser),
159
                'url' => (new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $nextuser->id]))
160
                    ->out(false),
161
                'nextarrow' => $nextarrow
162
            ];
163
        }
164
 
165
        return $this->render_from_template('gradereport_user/user_navigation', $navigationdata);
166
    }
167
 
168
    /**
169
     * Creates and renders 'view report as' selector element.
170
     *
171
     * @param int $userid The selected userid
172
     * @param int $userview The current view user setting constant
173
     * @param int $courseid The course ID.
174
     * @return string The raw HTML to render.
1441 ariadna 175
     * @deprecated since Moodle 4.5 See select_menu use in \gradereport_user\output\action_bar::export_for_template.
1 efrain 176
     */
177
    public function view_mode_selector(int $userid, int $userview, int $courseid): string {
178
 
1441 ariadna 179
        debugging('view_mode_selector is deprecated.', DEBUG_DEVELOPER);
180
 
1 efrain 181
        $viewasotheruser = new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $userid,
182
            'userview' => GRADE_REPORT_USER_VIEW_USER]);
183
        $viewasmyself = new moodle_url('/grade/report/user/index.php', ['id' => $courseid, 'userid' => $userid,
184
            'userview' => GRADE_REPORT_USER_VIEW_SELF]);
185
 
186
        $selectoroptions = [
187
            $viewasotheruser->out(false) => get_string('otheruser', 'core_grades'),
188
            $viewasmyself->out(false) => get_string('myself', 'core_grades')
189
        ];
190
 
191
        $selectoractiveurl = $userview === GRADE_REPORT_USER_VIEW_USER ? $viewasotheruser : $viewasmyself;
192
 
193
        $viewasselect = new \core\output\select_menu('viewas', $selectoroptions, $selectoractiveurl->out(false));
194
        $viewasselect->set_label(get_string('viewas', 'core_grades'));
195
 
196
        return $this->render_from_template('gradereport_user/view_mode_selector',
197
            $viewasselect->export_for_template($this));
198
    }
199
}