From b1842963167f50ba4750aaa6ada7d378b533ee55 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Mon, 24 Oct 2022 02:38:07 +1100 Subject: [PATCH] MDL-75423 gradereport_singleview: Trigger element for the user selector Creates a renderer method and a template for the element that would trigger the user selector. --- grade/report/singleview/renderer.php | 64 +++++++++++++++++ grade/report/singleview/styles.css | 5 ++ .../templates/user_selector.mustache | 71 +++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 grade/report/singleview/renderer.php create mode 100644 grade/report/singleview/templates/user_selector.mustache diff --git a/grade/report/singleview/renderer.php b/grade/report/singleview/renderer.php new file mode 100644 index 00000000000..e525234c997 --- /dev/null +++ b/grade/report/singleview/renderer.php @@ -0,0 +1,64 @@ +. + +/** + * Renderer for the grade single view report. + * + * @package gradereport_singleview + * @copyright 2022 Mihail Geshoski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Custom renderer for the single view report. + * + * To get an instance of this use the following code: + * $renderer = $PAGE->get_renderer('gradereport_singleview'); + * + * @copyright 2022 Mihail Geshoski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class gradereport_singleview_renderer extends plugin_renderer_base { + + /** + * Renders the user selector trigger element. + * + * @param object $course The course object. + * @param int|null $userid The user ID. + * @param int|null $groupid The group ID. + * @return string The raw HTML to render. + */ + public function users_selector(object $course, ?int $userid = null, ?int $groupid = null): string { + + $data = [ + 'courseid' => $course->id, + 'groupid' => $groupid ?? 0, + ]; + + // If a particular user option is selected (not in zero state). + if ($userid) { // A single user selected. + $user = core_user::get_user($userid); + $data['selectedoption'] = [ + 'image' => $this->user_picture($user, ['size' => 40, 'link' => false]), + 'text' => fullname($user), + 'additionaltext' => $user->email, + ]; + } + + $this->page->requires->js_call_amd('gradereport_singleview/user', 'init'); + return $this->render_from_template('gradereport_singleview/user_selector', $data); + } +} diff --git a/grade/report/singleview/styles.css b/grade/report/singleview/styles.css index 5427356fc77..1d2a91cd8ad 100644 --- a/grade/report/singleview/styles.css +++ b/grade/report/singleview/styles.css @@ -102,3 +102,8 @@ height: 150px; overflow: auto; } + +.path-grade-report-singleview .user-selector .userinitials { + width: 40px; + height: 40px; +} diff --git a/grade/report/singleview/templates/user_selector.mustache b/grade/report/singleview/templates/user_selector.mustache new file mode 100644 index 00000000000..a9269571fac --- /dev/null +++ b/grade/report/singleview/templates/user_selector.mustache @@ -0,0 +1,71 @@ +{{! + This file is part of Moodle - http://moodle.org/ + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template gradereport_singleview/user_selector + + The user selector trigger element. + + Context variables required for this template: + * courseid - The course ID. + * groupid - The group ID. + * selectedoption - (optional) Object containing information about the selected option. + * image - The image corresponding to the selected option. + * text - The text of the selected option. + * additionaltext - (optional) Additional text displayed below the selected option (e.g. the user email) + + Example context (json): + { + "courseid": "2", + "groupid": "2", + "selectedoption": { + "image": "\"\"", + "text": "John Doe", + "additionaltext": "johndoe@example.com" + } + } +}} +
+ +