Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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 * H5P activity participants report 19 * 20 * @package mod_h5pactivity 21 * @since Moodle 3.9 22 * @copyright 2020 Ferran Recio <ferran@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace mod_h5pactivity\local\report; 27 28 use mod_h5pactivity\local\report; 29 use mod_h5pactivity\local\manager; 30 use mod_h5pactivity\local\attempt; 31 use core\dml\sql_join; 32 use table_sql; 33 use moodle_url; 34 use html_writer; 35 use stdClass; 36 37 defined('MOODLE_INTERNAL') || die(); 38 39 global $CFG; 40 require_once($CFG->libdir.'/tablelib.php'); 41 42 /** 43 * Class H5P activity participants report. 44 * 45 * @package mod_h5pactivity 46 * @since Moodle 3.9 47 * @copyright 2020 Ferran Recio <ferran@moodle.com> 48 */ 49 class participants extends table_sql implements report { 50 51 /** @var manager the H5P activity manager instance. */ 52 private $manager; 53 54 /** @var array the users scored attempts. */ 55 private $scores; 56 57 /** @var array the user attempts count. */ 58 private $count; 59 60 /** 61 * Create a new participants report. 62 * 63 * @param manager $manager h5pactivitymanager object 64 * @param int|bool $currentgroup False if groups not used, 0 for all groups, group id (int) to filter by specific group 65 */ 66 public function __construct(manager $manager, $currentgroup = false) { 67 parent::__construct('mod_h5pactivity-participants'); 68 $this->manager = $manager; 69 $this->scores = $manager->get_users_scaled_score(); 70 $this->count = $manager->count_users_attempts(); 71 72 // Setup table_sql. 73 $columns = ['fullname', 'timemodified', 'score', 'attempts']; 74 $headers = [ 75 get_string('fullname'), get_string('date'), 76 get_string('score', 'mod_h5pactivity'), get_string('attempts', 'mod_h5pactivity'), 77 ]; 78 $this->define_columns($columns); 79 $this->define_headers($headers); 80 $this->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide'); 81 $this->sortable(true); 82 $this->no_sorting('score'); 83 $this->no_sorting('timemodified'); 84 $this->no_sorting('attempts'); 85 $this->pageable(true); 86 87 $capjoin = $this->manager->get_active_users_join(true, $currentgroup); 88 89 // Final SQL. 90 $this->set_sql( 91 'DISTINCT u.id, u.picture, u.firstname, u.lastname, u.firstnamephonetic, u.lastnamephonetic, 92 u.middlename, u.alternatename, u.imagealt, u.email', 93 "{user} u $capjoin->joins", 94 $capjoin->wheres, 95 $capjoin->params); 96 } 97 98 /** 99 * Return the report user record. 100 * 101 * Participants report has no specific user. 102 * 103 * @return stdClass|null a user or null 104 */ 105 public function get_user(): ?stdClass { 106 return null; 107 } 108 109 /** 110 * Return the report attempt object. 111 * 112 * Participants report has no specific attempt. 113 * 114 * @return attempt|null the attempt object or null 115 */ 116 public function get_attempt(): ?attempt { 117 return null; 118 } 119 120 /** 121 * Print the report. 122 */ 123 public function print(): void { 124 global $PAGE, $OUTPUT; 125 126 $this->define_baseurl($PAGE->url); 127 128 echo $OUTPUT->heading(get_string('attempts_report', 'mod_h5pactivity')); 129 130 $this->out($this->get_page_size(), true); 131 } 132 133 /** 134 * Warning in case no user has the selected initials letters. 135 * 136 */ 137 public function print_nothing_to_display() { 138 global $OUTPUT; 139 echo $this->render_reset_button(); 140 $this->print_initials_bar(); 141 echo $OUTPUT->notification(get_string('noparticipants', 'mod_h5pactivity'), 'warning'); 142 } 143 144 /** 145 * Generate the fullname column. 146 * 147 * @param stdClass $user 148 * @return string 149 */ 150 public function col_fullname($user): string { 151 global $OUTPUT; 152 $cm = $this->manager->get_coursemodule(); 153 return $OUTPUT->user_picture($user, ['size' => 35, 'courseid' => $cm->course, 'includefullname' => true]); 154 } 155 156 /** 157 * Generate score column. 158 * 159 * @param stdClass $user the user record 160 * @return string 161 */ 162 public function col_score(stdClass $user): string { 163 $cm = $this->manager->get_coursemodule(); 164 if (isset($this->scores[$user->id])) { 165 $score = $this->scores[$user->id]; 166 $maxgrade = floatval(100); 167 $scaled = round($maxgrade * $score->scaled).'%'; 168 if (empty($score->attemptid)) { 169 return $scaled; 170 } else { 171 $url = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance, 'attemptid' => $score->attemptid]); 172 return html_writer::link($url, $scaled); 173 } 174 } 175 return ''; 176 } 177 178 /** 179 * Generate attempts count column, if any. 180 * 181 * @param stdClass $user the user record 182 * @return string 183 */ 184 public function col_attempts(stdClass $user): string { 185 $cm = $this->manager->get_coursemodule(); 186 if (isset($this->count[$user->id])) { 187 $msg = get_string('review_user_attempts', 'mod_h5pactivity', $this->count[$user->id]); 188 $url = new moodle_url('/mod/h5pactivity/report.php', ['a' => $cm->instance, 'userid' => $user->id]); 189 return html_writer::link($url, $msg); 190 } 191 return ''; 192 193 } 194 195 /** 196 * Generate attempt timemodified column, if any. 197 * 198 * @param stdClass $user the user record 199 * @return string 200 */ 201 public function col_timemodified(stdClass $user): string { 202 if (isset($this->scores[$user->id])) { 203 $score = $this->scores[$user->id]; 204 return userdate($score->timemodified); 205 } 206 return ''; 207 } 208 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body