[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 * The user screen. 19 * 20 * @package gradereport_singleview 21 * @copyright 2014 Moodle Pty Ltd (http://moodle.com) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace gradereport_singleview\local\screen; 26 27 use grade_seq; 28 use gradereport_singleview; 29 use moodle_url; 30 use pix_icon; 31 use html_writer; 32 use gradereport_singleview\local\ui\range; 33 use gradereport_singleview\local\ui\bulk_insert; 34 use grade_item; 35 use grade_grade; 36 use stdClass; 37 38 defined('MOODLE_INTERNAL') || die; 39 40 /** 41 * The user screen. 42 * 43 * @package gradereport_singleview 44 * @copyright 2014 Moodle Pty Ltd (http://moodle.com) 45 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 46 */ 47 class user extends tablelike implements selectable_items { 48 49 /** @var array $categories A cache for grade_item categories */ 50 private $categories = array(); 51 52 /** @var int $requirespaging Do we have more items than the paging limit? */ 53 private $requirespaging = true; 54 55 /** 56 * Get the description for the screen. 57 * 58 * @return string 59 */ 60 public function description() { 61 return get_string('gradeitems', 'grades'); 62 } 63 64 /** 65 * Convert the list of items to a list of options. 66 * 67 * @return array 68 */ 69 public function options() { 70 $result = array(); 71 foreach ($this->items as $itemid => $item) { 72 $result[$itemid] = $item->get_name(); 73 } 74 return $result; 75 } 76 77 /** 78 * Get the type of items on this screen. 79 * 80 * @return string 81 */ 82 public function item_type() { 83 return 'grade'; 84 } 85 86 /** 87 * Should we show the group selector on this screen? 88 * 89 * @return bool 90 */ 91 public function display_group_selector() { 92 return false; 93 } 94 95 /** 96 * Init the screen 97 * 98 * @param bool $selfitemisempty Have we selected an item yet? 99 */ 100 public function init($selfitemisempty = false) { 101 global $DB; 102 103 if (!$selfitemisempty) { 104 $this->item = $DB->get_record('user', array('id' => $this->itemid)); 105 } 106 107 $params = array('courseid' => $this->courseid); 108 109 $seq = new grade_seq($this->courseid, true); 110 foreach ($seq->items as $key => $item) { 111 if (isset($item->itemmodule)) { 112 list($courseid, $cmid) = get_course_and_cm_from_instance($item->iteminstance, $item->itemmodule); 113 $seq->items[$key]->cmid = $cmid->id; 114 } 115 } 116 117 $this->items = array(); 118 foreach ($seq->items as $itemid => $item) { 119 if (grade::filter($item)) { 120 $this->items[$itemid] = $item; 121 } 122 } 123 124 $this->requirespaging = count($this->items) > $this->perpage; 125 126 $this->setup_structure(); 127 128 $this->definition = array( 129 'finalgrade', 'feedback', 'override', 'exclude' 130 ); 131 $this->set_headers($this->original_headers()); 132 } 133 134 /** 135 * Get the list of headers for the table. 136 * 137 * @return array List of headers 138 */ 139 public function original_headers() { 140 return array( 141 '', // For filter icon. 142 get_string('assessmentname', 'gradereport_singleview'), 143 get_string('gradecategory', 'grades'), 144 get_string('range', 'grades'), 145 get_string('grade', 'grades'), 146 get_string('feedback', 'grades'), 147 $this->make_toggle_links('override'), 148 $this->make_toggle_links('exclude') 149 ); 150 } 151 152 /** 153 * Format each row of the table. 154 * 155 * @param grade_item $item 156 * @return string 157 */ 158 public function format_line($item) { 159 global $OUTPUT; 160 161 $grade = $this->fetch_grade_or_default($item, $this->item->id); 162 $lockicon = ''; 163 164 $lockeditem = $lockeditemgrade = 0; 165 if (!empty($grade->locked)) { 166 $lockeditem = 1; 167 } 168 if (!empty($grade->grade_item->locked)) { 169 $lockeditemgrade = 1; 170 } 171 // Check both grade and grade item. 172 if ($lockeditem || $lockeditemgrade) { 173 $lockicon = $OUTPUT->pix_icon('t/locked', 'grade is locked'); 174 } 175 176 $realmodid = ''; 177 if (isset($item->cmid)) { 178 $realmodid = $item->cmid; 179 } 180 181 $iconstring = get_string('filtergrades', 'gradereport_singleview', $item->get_name()); 182 183 // Create a fake gradetreeitem so we can call get_element_header(). 184 // The type logic below is from grade_category->_get_children_recursion(). 185 $gradetreeitem = array(); 186 if (in_array($item->itemtype, array('course', 'category'))) { 187 $gradetreeitem['type'] = $item->itemtype.'item'; 188 } else { 189 $gradetreeitem['type'] = 'item'; 190 } 191 $gradetreeitem['object'] = $item; 192 $gradetreeitem['userid'] = $this->item->id; 193 194 $itemlabel = $this->structure->get_element_header($gradetreeitem, true, false, false, false, true); 195 $grade->label = $item->get_name(); 196 197 $itemlabel = $item->get_name(); 198 if (!empty($realmodid)) { 199 $url = new moodle_url('/mod/' . $item->itemmodule . '/view.php', array('id' => $realmodid)); 200 $itemlabel = html_writer::link($url, $item->get_name()); 201 } 202 203 $line = array( 204 $OUTPUT->action_icon($this->format_link('grade', $item->id), new pix_icon('t/editstring', $iconstring)), 205 $this->format_icon($item) . $lockicon . $itemlabel, 206 $this->category($item), 207 new range($item) 208 ); 209 $lineclasses = array( 210 "action", 211 "gradeitem", 212 "category", 213 "range" 214 ); 215 216 $outputline = array(); 217 $i = 0; 218 foreach ($line as $key => $value) { 219 $cell = new \html_table_cell($value); 220 if ($isheader = $i == 1) { 221 $cell->header = $isheader; 222 $cell->scope = "row"; 223 } 224 if (array_key_exists($key, $lineclasses)) { 225 $cell->attributes['class'] = $lineclasses[$key]; 226 } 227 $outputline[] = $cell; 228 $i++; 229 } 230 231 return $this->format_definition($outputline, $grade); 232 } 233 234 /** 235 * Helper to get the icon for an item. 236 * 237 * @param grade_item $item 238 * @return string 239 */ 240 private function format_icon($item) { 241 $element = array('type' => 'item', 'object' => $item); 242 return $this->structure->get_element_icon($element); 243 } 244 245 /** 246 * Helper to get the category for an item. 247 * 248 * @param grade_item $item 249 * @return grade_category 250 */ 251 private function category($item) { 252 global $DB; 253 254 if (empty($item->categoryid)) { 255 256 if ($item->itemtype == 'course') { 257 return $this->course->fullname; 258 } 259 260 $params = array('id' => $item->iteminstance); 261 $elem = $DB->get_record('grade_categories', $params); 262 263 return $elem->fullname; 264 } 265 266 if (!isset($this->categories[$item->categoryid])) { 267 $category = $item->get_parent_category(); 268 269 $this->categories[$category->id] = $category; 270 } 271 272 return $this->categories[$item->categoryid]->get_name(); 273 } 274 275 /** 276 * Get the heading for the page. 277 * 278 * @return string 279 */ 280 public function heading() { 281 return fullname($this->item); 282 } 283 284 /** 285 * Get the summary for this table. 286 * 287 * @return string 288 */ 289 public function summary() { 290 return get_string('summaryuser', 'gradereport_singleview'); 291 } 292 293 /** 294 * Default pager 295 * 296 * @return string 297 */ 298 public function pager() { 299 global $OUTPUT; 300 301 if (!$this->supports_paging()) { 302 return ''; 303 } 304 305 return $OUTPUT->paging_bar( 306 count($this->items), $this->page, $this->perpage, 307 new moodle_url('/grade/report/singleview/index.php', array( 308 'perpage' => $this->perpage, 309 'id' => $this->courseid, 310 'groupid' => $this->groupid, 311 'itemid' => $this->itemid, 312 'item' => 'user' 313 )) 314 ); 315 } 316 317 /** 318 * Does this page require paging? 319 * 320 * @return bool 321 */ 322 public function supports_paging() { 323 return $this->requirespaging; 324 } 325 326 327 /** 328 * Process the data from the form. 329 * 330 * @param array $data 331 * @return array of warnings 332 */ 333 public function process($data) { 334 $bulk = new bulk_insert($this->item); 335 // Bulk insert messages the data to be passed in 336 // ie: for all grades of empty grades apply the specified value. 337 if ($bulk->is_applied($data)) { 338 $filter = $bulk->get_type($data); 339 $insertvalue = $bulk->get_insert_value($data); 340 341 $userid = $this->item->id; 342 foreach ($this->items as $gradeitemid => $gradeitem) { 343 $null = $gradeitem->gradetype == GRADE_TYPE_SCALE ? -1 : ''; 344 $field = "finalgrade_{$gradeitem->id}_{$this->itemid}"; 345 if (isset($data->$field)) { 346 continue; 347 } 348 349 $grade = grade_grade::fetch(array( 350 'itemid' => $this->itemid, 351 'userid' => $userid 352 )); 353 354 $data->$field = empty($grade) ? $null : $grade->finalgrade; 355 $data->{"old$field"} = $data->$field; 356 357 preg_match('/_(\d+)_(\d+)/', $field, $oldoverride); 358 $oldoverride = 'oldoverride' . $oldoverride[0]; 359 if (empty($data->$oldoverride)) { 360 $data->$field = (!isset($grade->rawgrade)) ? $null : $grade->rawgrade; 361 } 362 363 } 364 365 foreach ($data as $varname => $value) { 366 if (preg_match('/override_(\d+)_(\d+)/', $varname, $matches)) { 367 $data->$matches[0] = '1'; 368 } 369 if (!preg_match('/^finalgrade_(\d+)_(\d+)/', $varname, $matches)) { 370 continue; 371 } 372 373 $gradeitem = grade_item::fetch(array( 374 'courseid' => $this->courseid, 375 'id' => $matches[1] 376 )); 377 378 $isscale = ($gradeitem->gradetype == GRADE_TYPE_SCALE); 379 380 $empties = (trim($value) === '' or ($isscale and $value == -1)); 381 382 if ($filter == 'all' or $empties) { 383 $data->$varname = ($isscale and empty($insertvalue)) ? 384 -1 : $insertvalue; 385 } 386 } 387 } 388 return parent::process($data); 389 } 390 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |