Differences Between: [Versions 401 and 402] [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 gradereport_singleview\report\singleview; 26 27 /** 28 * Custom renderer for the single view report. 29 * 30 * To get an instance of this use the following code: 31 * $renderer = $PAGE->get_renderer('gradereport_singleview'); 32 * 33 * @copyright 2022 Mihail Geshoski <mihail@moodle.com> 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class gradereport_singleview_renderer extends plugin_renderer_base { 37 38 /** 39 * Renders the user selector trigger element. 40 * 41 * @param object $course The course object. 42 * @param int|null $userid The user ID. 43 * @param int|null $groupid The group ID. 44 * @return string The raw HTML to render. 45 */ 46 public function users_selector(object $course, ?int $userid = null, ?int $groupid = null): string { 47 48 $data = [ 49 'name' => 'userid', 50 'courseid' => $course->id, 51 'groupid' => $groupid ?? 0, 52 ]; 53 54 // If a particular user option is selected (not in zero state). 55 if ($userid) { // A single user selected. 56 $user = core_user::get_user($userid); 57 $data['selectedoption'] = [ 58 'image' => $this->user_picture($user, ['size' => 40, 'link' => false]), 59 'text' => fullname($user), 60 'additionaltext' => $user->email, 61 ]; 62 $data['userid'] = $userid; 63 } 64 65 $this->page->requires->js_call_amd('gradereport_singleview/user', 'init'); 66 return $this->render_from_template('core_grades/user_selector', $data); 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 $this->page->requires->js_call_amd('gradereport_singleview/grade', 'init'); 93 return $this->render_from_template('gradereport_singleview/grade_item_selector', $data); 94 } 95 96 /** 97 * Creates and renders previous/next user/grade item navigation. 98 * 99 * @param object $gpr grade plugin return tracking object 100 * @param int $courseid The course ID. 101 * @param \context_course $context Context of the report. 102 * @param singleview $report The single view report class. 103 * @param int|null $groupid Group ID 104 * @param string $itemtype User or Grade item type 105 * @param int $itemid Either User ID or Grade item ID 106 * @return string The raw HTML to render. 107 * @throws moodle_exception 108 */ 109 public function report_navigation(object $gpr, int $courseid, \context_course $context, singleview $report, 110 ?int $groupid, string $itemtype, int $itemid): string { 111 112 $navigation = ''; 113 $options = $report->screen->options(); 114 115 $optionkeys = array_keys($options); 116 $optionitemid = array_shift($optionkeys); 117 118 $relreport = new gradereport_singleview\report\singleview( 119 $courseid, $gpr, $context, 120 $report->screen->item_type(), $optionitemid 121 ); 122 $reloptions = $relreport->screen->options(); 123 $reloptionssorting = array_keys($relreport->screen->options()); 124 125 $i = array_search($itemid, $reloptionssorting); 126 $navparams = ['item' => $itemtype, 'id' => $courseid, 'group' => $groupid]; 127 128 // Determine directionality so that icons can be modified to suit language. 129 $previousarrow = right_to_left() ? 'right' : 'left'; 130 $nextarrow = right_to_left() ? 'left' : 'right'; 131 132 if ($i > 0) { 133 $navparams['itemid'] = $reloptionssorting[$i - 1]; 134 $link = (new moodle_url('/grade/report/singleview/index.php', $navparams)) 135 ->out(false); 136 $navigationdata['previoususer'] = [ 137 'name' => $reloptions[$navparams['itemid']], 138 'url' => $link, 139 'previousarrow' => $previousarrow 140 ]; 141 } 142 if ($i < count($reloptionssorting) - 1) { 143 $navparams['itemid'] = $reloptionssorting[$i + 1]; 144 $link = (new moodle_url('/grade/report/singleview/index.php', $navparams)) 145 ->out(false); 146 $navigationdata['nextuser'] = [ 147 'name' => $reloptions[$navparams['itemid']], 148 'url' => $link, 149 'nextarrow' => $nextarrow 150 ]; 151 } 152 153 if ($report->screen->supports_paging()) { 154 $navigationdata['perpageselect'] = $report->screen->perpage_select(); 155 $navigationdata['pager'] = $report->screen->pager(); 156 } 157 158 if (isset($navigationdata)) { 159 $navigation = $this->render_from_template('gradereport_singleview/report_navigation', $navigationdata); 160 } 161 return $navigation; 162 } 163 164 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body