Differences Between: [Versions 401 and 403] [Versions 402 and 403]
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 $data = [ 50 'currentvalue' => optional_param('searchvalue', '', PARAM_NOTAGS), 51 'courseid' => $course->id, 52 'group' => $groupid ?? 0, 53 'resetlink' => $resetlink->out(false), 54 'userid' => $userid ?? 0 55 ]; 56 $dropdown = new comboboxsearch( 57 true, 58 $this->render_from_template('core_user/comboboxsearch/user_selector', $data), 59 null, 60 'user-search dropdown d-flex', 61 null, 62 'usersearchdropdown overflow-auto', 63 null, 64 false, 65 ); 66 return $this->render_from_template($dropdown->get_template(), $dropdown->export_for_template($this)); 67 } 68 69 /** 70 * Renders the grade items selector trigger element. 71 * 72 * @param object $course The course object. 73 * @param int|null $gradeitemid The grade item ID. 74 * @return string The raw HTML to render. 75 */ 76 public function grade_items_selector(object $course, ?int $gradeitemid = null): string { 77 78 $data = [ 79 'name' => 'itemid', 80 'courseid' => $course->id, 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 ]); 96 $dropdown = new comboboxsearch( 97 false, 98 $this->render_from_template('gradereport_singleview/grade_item_selector', $data), 99 $sbody, 100 'grade-search h-100', 101 'gradesearchwidget h-100', 102 'gradesearchdropdown overflow-auto w-100', 103 ); 104 return $this->render_from_template($dropdown->get_template(), $dropdown->export_for_template($this)); 105 } 106 107 /** 108 * Creates and renders previous/next user/grade item navigation. 109 * 110 * @param object $gpr grade plugin return tracking object 111 * @param int $courseid The course ID. 112 * @param \context_course $context Context of the report. 113 * @param singleview $report The single view report class. 114 * @param int|null $groupid Group ID 115 * @param string $itemtype User or Grade item type 116 * @param int $itemid Either User ID or Grade item ID 117 * @return string The raw HTML to render. 118 * @throws moodle_exception 119 */ 120 public function report_navigation(object $gpr, int $courseid, \context_course $context, singleview $report, 121 ?int $groupid, string $itemtype, int $itemid): string { 122 123 $navigation = ''; 124 $options = $report->screen->options(); 125 126 $optionkeys = array_keys($options); 127 $optionitemid = array_shift($optionkeys); 128 129 $relreport = new gradereport_singleview\report\singleview( 130 $courseid, $gpr, $context, 131 $report->screen->item_type(), $optionitemid 132 ); 133 $reloptions = $relreport->screen->options(); 134 $reloptionssorting = array_keys($relreport->screen->options()); 135 136 $i = array_search($itemid, $reloptionssorting); 137 $navparams = ['item' => $itemtype, 'id' => $courseid, 'group' => $groupid]; 138 139 // Determine directionality so that icons can be modified to suit language. 140 $previousarrow = right_to_left() ? 'right' : 'left'; 141 $nextarrow = right_to_left() ? 'left' : 'right'; 142 143 if ($i > 0) { 144 $navparams['itemid'] = $reloptionssorting[$i - 1]; 145 $link = (new moodle_url('/grade/report/singleview/index.php', $navparams)) 146 ->out(false); 147 $navigationdata['previoususer'] = [ 148 'name' => $reloptions[$navparams['itemid']], 149 'url' => $link, 150 'previousarrow' => $previousarrow 151 ]; 152 } 153 if ($i < count($reloptionssorting) - 1) { 154 $navparams['itemid'] = $reloptionssorting[$i + 1]; 155 $link = (new moodle_url('/grade/report/singleview/index.php', $navparams)) 156 ->out(false); 157 $navigationdata['nextuser'] = [ 158 'name' => $reloptions[$navparams['itemid']], 159 'url' => $link, 160 'nextarrow' => $nextarrow 161 ]; 162 } 163 164 if ($report->screen->supports_paging()) { 165 $navigationdata['perpageselect'] = $report->screen->perpage_select(); 166 } 167 168 if (isset($navigationdata)) { 169 $navigation = $this->render_from_template('gradereport_singleview/report_navigation', $navigationdata); 170 } 171 return $navigation; 172 } 173 174 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body