gradebook MDL-23033 made use of user_picture::fields()
[moodle.git] / grade / report / grader / lib.php
CommitLineData
e060e33d 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
8ad36f4c 17
4ba9941c 18/**
19 * File in which the grader_report class is defined.
20 * @package gradebook
21 */
22
eea6690a 23require_once($CFG->dirroot . '/grade/report/lib.php');
4ba9941c 24require_once($CFG->libdir.'/tablelib.php');
4ba9941c 25
26/**
27 * Class providing an API for the grader report building and displaying.
eea6690a 28 * @uses grade_report
4ba9941c 29 * @package gradebook
30 */
eea6690a 31class grade_report_grader extends grade_report {
4ba9941c 32 /**
33 * The final grades.
b89a70ce 34 * @var array $grades
4ba9941c 35 */
d24832f9 36 public $grades;
4ba9941c 37
38 /**
39 * Array of errors for bulk grades updating.
40 * @var array $gradeserror
41 */
d24832f9 42 public $gradeserror = array();
4ba9941c 43
4ba9941c 44//// SQL-RELATED
45
4ba9941c 46 /**
47 * The id of the grade_item by which this report will be sorted.
48 * @var int $sortitemid
49 */
d24832f9 50 public $sortitemid;
4ba9941c 51
52 /**
53 * Sortorder used in the SQL selections.
54 * @var int $sortorder
55 */
d24832f9 56 public $sortorder;
4ba9941c 57
58 /**
59 * An SQL fragment affecting the search for users.
60 * @var string $userselect
61 */
d24832f9 62 public $userselect;
63
64 /**
65 * The bound params for $userselect
319770d7 66 * @var array $userselectparams
d24832f9 67 */
319770d7 68 public $userselectparams = array();
4ba9941c 69
4faf5f99 70 /**
384960dd 71 * List of collapsed categories from user preference
4faf5f99 72 * @var array $collapsed
73 */
d24832f9 74 public $collapsed;
4faf5f99 75
66ef0471 76 /**
77 * A count of the rows, used for css classes.
78 * @var int $rowcount
79 */
d24832f9 80 public $rowcount = 0;
66ef0471 81
6cc3e350 82 /**
57068674 83 * Capability check caching
84 * */
d24832f9 85 public $canviewhidden;
57068674 86
319770d7 87 var $preferencespage=false;
653a8648 88
92ff6236
AD
89 /**
90 * Length at which feedback will be truncated (to the nearest word) and an ellipsis be added.
91 * TODO replace this by a report preference
92 * @var int $feedback_trunc_length
93 */
94 protected $feedback_trunc_length = 50;
95
4ba9941c 96 /**
97 * Constructor. Sets local copies of user preferences and initialises grade_tree.
98 * @param int $courseid
d30c4481 99 * @param object $gpr grade plugin return tracking object
eea6690a 100 * @param string $context
101 * @param int $page The current page being viewed (when report is paged)
102 * @param int $sortitemid The id of the grade_item by which to sort the table
4ba9941c 103 */
d24832f9 104 public function __construct($courseid, $gpr, $context, $page=null, $sortitemid=null) {
4ba9941c 105 global $CFG;
d24832f9 106 parent::__construct($courseid, $gpr, $context, $page);
4ba9941c 107
57068674 108 $this->canviewhidden = has_capability('moodle/grade:viewhidden', get_context_instance(CONTEXT_COURSE, $this->course->id));
109
4faf5f99 110 // load collapsed settings for this report
111 if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories')) {
112 $this->collapsed = unserialize($collapsed);
4faf5f99 113 } else {
384960dd 114 $this->collapsed = array('aggregatesonly' => array(), 'gradesonly' => array());
4faf5f99 115 }
384960dd 116
aea4df41 117 if (empty($CFG->enableoutcomes)) {
118 $nooutcomes = false;
119 } else {
120 $nooutcomes = get_user_preferences('grade_report_shownooutcomes');
121 }
122
e0724506 123 // if user report preference set or site report setting set use it, otherwise use course or site setting
124 $switch = $this->get_pref('aggregationposition');
05766b50 125 if ($switch == '') {
e0724506 126 $switch = grade_get_setting($this->courseid, 'aggregationposition', $CFG->grade_aggregationposition);
127 }
128
4faf5f99 129 // Grab the grade_tree for this course
e0724506 130 $this->gtree = new grade_tree($this->courseid, true, $switch, $this->collapsed, $nooutcomes);
4faf5f99 131
4ba9941c 132 $this->sortitemid = $sortitemid;
133
4ba9941c 134 // base url for sorting by first/last name
09cef06a 135
319770d7 136 $this->baseurl = new moodle_url('index.php', array('id' => $this->courseid));
137
138 $studentsperpage = $this->get_pref('studentsperpage');
09cef06a 139 if (!empty($studentsperpage)) {
319770d7 140 $this->baseurl->params(array('perpage' => $studentsperpage, 'page' => $this->page));
09cef06a 141 }
09cef06a 142
a6855934 143 $this->pbarurl = new moodle_url('/grade/report/grader/index.php', array('id' => $this->courseid, 'perpage' => $studentsperpage));
4ba9941c 144
35079f53 145 $this->setup_groups();
4ba9941c 146
147 $this->setup_sortitemid();
148 }
149
4ba9941c 150 /**
151 * Processes the data sent by the form (grades and feedbacks).
75674470 152 * Caller is reposible for all access control checks
153 * @param array $data form submission (with magic quotes)
154 * @return array empty array if success, array of warnings if something fails.
4ba9941c 155 */
d24832f9 156 public function process_data($data) {
5c75a0a3 157 global $DB;
75674470 158 $warnings = array();
2cc773f5 159
30ebb74f 160 $separategroups = false;
161 $mygroups = array();
162 if ($this->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $this->context)) {
163 $separategroups = true;
164 $mygroups = groups_get_user_groups($this->course->id);
165 $mygroups = $mygroups[0]; // ignore groupings
166 // reorder the groups fro better perf bellow
167 $current = array_search($this->currentgroup, $mygroups);
168 if ($current !== false) {
169 unset($mygroups[$current]);
170 array_unshift($mygroups, $this->currentgroup);
171 }
172 }
173
4ba9941c 174 // always initialize all arrays
175 $queue = array();
4ba9941c 176 foreach ($data as $varname => $postedvalue) {
4ba9941c 177
178 $needsupdate = false;
4ba9941c 179
180 // skip, not a grade nor feedback
79eabc2a 181 if (strpos($varname, 'grade') === 0) {
319770d7 182 $datatype = 'grade';
79eabc2a 183 } else if (strpos($varname, 'feedback') === 0) {
319770d7 184 $datatype = 'feedback';
4ba9941c 185 } else {
186 continue;
187 }
188
189 $gradeinfo = explode("_", $varname);
4ba9941c 190 $userid = clean_param($gradeinfo[1], PARAM_INT);
191 $itemid = clean_param($gradeinfo[2], PARAM_INT);
192
29a5680e 193 $oldvalue = $data->{'old'.$varname};
194
195 // was change requested?
99ccfda8 196 if ($oldvalue == $postedvalue) { // string comparison
29a5680e 197 continue;
198 }
199
319770d7 200 if (!$gradeitem = grade_item::fetch(array('id'=>$itemid, 'courseid'=>$this->courseid))) { // we must verify course id here!
14398fd6 201 print_error('invalidgradeitmeid');
4ba9941c 202 }
203
204 // Pre-process grade
319770d7 205 if ($datatype == 'grade') {
4256a134 206 $feedback = false;
207 $feedbackformat = false;
319770d7 208 if ($gradeitem->gradetype == GRADE_TYPE_SCALE) {
4ba9941c 209 if ($postedvalue == -1) { // -1 means no grade
210 $finalgrade = null;
211 } else {
29a5680e 212 $finalgrade = $postedvalue;
4ba9941c 213 }
214 } else {
76317c73 215 $finalgrade = unformat_float($postedvalue);
4ba9941c 216 }
79eabc2a 217
0a2c8485 218 $errorstr = '';
379ea949 219 // Warn if the grade is out of bounds.
220 if (is_null($finalgrade)) {
221 // ok
653a8648 222 } else {
319770d7 223 $bounded = $gradeitem->bounded_grade($finalgrade);
653a8648 224 if ($bounded > $finalgrade) {
0a2c8485 225 $errorstr = 'lessthanmin';
653a8648 226 } else if ($bounded < $finalgrade) {
78946b9b
PS
227 $errorstr = 'morethanmax';
228 }
0a2c8485 229 }
230 if ($errorstr) {
5c75a0a3 231 $user = $DB->get_record('user', array('id' => $userid), 'id, firstname, lastname');
379ea949 232 $gradestr = new object();
0a2c8485 233 $gradestr->username = fullname($user);
319770d7 234 $gradestr->itemname = $gradeitem->get_name();
9d35e66e 235 $warnings[] = get_string($errorstr, 'grades', $gradestr);
0a2c8485 236 }
237
319770d7 238 } else if ($datatype == 'feedback') {
4256a134 239 $finalgrade = false;
79eabc2a 240 $trimmed = trim($postedvalue);
241 if (empty($trimmed)) {
29a5680e 242 $feedback = NULL;
e1d2692a 243 } else {
653a8648 244 $feedback = stripslashes($postedvalue);
e1d2692a 245 }
4ba9941c 246 }
4ba9941c 247
30ebb74f 248 // group access control
249 if ($separategroups) {
250 // note: we can not use $this->currentgroup because it would fail badly
251 // when having two browser windows each with different group
252 $sharinggroup = false;
253 foreach($mygroups as $groupid) {
254 if (groups_is_member($groupid, $userid)) {
255 $sharinggroup = true;
256 break;
257 }
258 }
259 if (!$sharinggroup) {
260 // either group membership changed or somebedy is hacking grades of other group
261 $warnings[] = get_string('errorsavegrade', 'grades');
262 continue;
263 }
264 }
265
319770d7 266 $gradeitem->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE);
4ba9941c 267 }
268
75674470 269 return $warnings;
4ba9941c 270 }
271
4ba9941c 272
273 /**
274 * Setting the sort order, this depends on last state
275 * all this should be in the new table class that we might need to use
276 * for displaying grades.
277 */
d24832f9 278 private function setup_sortitemid() {
63d6efa2 279
280 global $SESSION;
281
4ba9941c 282 if ($this->sortitemid) {
283 if (!isset($SESSION->gradeuserreport->sort)) {
a80112f0 284 if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
285 $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
286 } else {
287 $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
288 }
4ba9941c 289 } else {
290 // this is the first sort, i.e. by last name
291 if (!isset($SESSION->gradeuserreport->sortitemid)) {
a80112f0 292 if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
d24832f9 293 $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
a80112f0 294 } else {
295 $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
296 }
4ba9941c 297 } else if ($SESSION->gradeuserreport->sortitemid == $this->sortitemid) {
298 // same as last sort
299 if ($SESSION->gradeuserreport->sort == 'ASC') {
300 $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
301 } else {
302 $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
303 }
304 } else {
a80112f0 305 if ($this->sortitemid == 'firstname' || $this->sortitemid == 'lastname') {
306 $this->sortorder = $SESSION->gradeuserreport->sort = 'ASC';
307 } else {
308 $this->sortorder = $SESSION->gradeuserreport->sort = 'DESC';
309 }
4ba9941c 310 }
311 }
312 $SESSION->gradeuserreport->sortitemid = $this->sortitemid;
313 } else {
314 // not requesting sort, use last setting (for paging)
315
316 if (isset($SESSION->gradeuserreport->sortitemid)) {
317 $this->sortitemid = $SESSION->gradeuserreport->sortitemid;
d20737e8 318 }else{
319 $this->sortitemid = 'lastname';
4ba9941c 320 }
d20737e8 321
4ba9941c 322 if (isset($SESSION->gradeuserreport->sort)) {
323 $this->sortorder = $SESSION->gradeuserreport->sort;
324 } else {
325 $this->sortorder = 'ASC';
326 }
327 }
328 }
329
4ba9941c 330 /**
b50371da 331 * pulls out the userids of the users to be display, and sorts them
4ba9941c 332 */
d24832f9 333 public function load_users() {
334 global $CFG, $DB;
b50371da 335
319770d7 336 list($usql, $gbrparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0');
4ba9941c 337
338 if (is_numeric($this->sortitemid)) {
319770d7 339 $params = array_merge(array('gitemid'=>$this->sortitemid), $gbrparams, $this->groupwheresql_params);
b50371da 340 // the MAX() magic is required in order to please PG
341 $sort = "MAX(g.finalgrade) $this->sortorder";
09d0ef21 342
9d35e66e 343 $sql = "SELECT u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber
b50371da 344 FROM {user} u
345 JOIN {role_assignments} ra ON ra.userid = u.id
09d0ef21 346 $this->groupsql
b50371da 347 LEFT JOIN {grade_grades} g ON (g.userid = u.id AND g.itemid = :gitemid)
348 WHERE ra.roleid $usql AND u.deleted = 0
09d0ef21 349 $this->groupwheresql
350 AND ra.contextid ".get_related_contexts_string($this->context)."
b50371da 351 GROUP BY u.id, u.firstname, u.lastname, u.imagealt, u.picture, u.idnumber
09d0ef21 352 ORDER BY $sort";
353
4ba9941c 354 } else {
09d0ef21 355 switch($this->sortitemid) {
356 case 'lastname':
357 $sort = "u.lastname $this->sortorder, u.firstname $this->sortorder"; break;
358 case 'firstname':
359 $sort = "u.firstname $this->sortorder, u.lastname $this->sortorder"; break;
360 case 'idnumber':
361 default:
362 $sort = "u.idnumber $this->sortorder"; break;
c421ad4b 363 }
4ba9941c 364
319770d7 365 $params = array_merge($gbrparams, $this->groupwheresql_params);
d5afd6c9
AD
366
367 $userfields = user_picture::fields('u');
368 $sql = "SELECT DISTINCT $userfields, u.idnumber
d24832f9 369 FROM {user} u
370 JOIN {role_assignments} ra ON u.id = ra.userid
09d0ef21 371 $this->groupsql
b50371da 372 WHERE ra.roleid $usql AND u.deleted = 0
09d0ef21 373 $this->groupwheresql
374 AND ra.contextid ".get_related_contexts_string($this->context)."
375 ORDER BY $sort";
4ba9941c 376 }
377
09d0ef21 378
d24832f9 379 $this->users = $DB->get_records_sql($sql, $params, $this->get_pref('studentsperpage') * $this->page, $this->get_pref('studentsperpage'));
09d0ef21 380
4ba9941c 381 if (empty($this->users)) {
382 $this->userselect = '';
383 $this->users = array();
0a695c36 384 $this->userselect_params = array();
4ba9941c 385 } else {
b50371da 386 list($usql, $params) = $DB->get_in_or_equal(array_keys($this->users), SQL_PARAMS_NAMED, 'usid0');
d24832f9 387 $this->userselect = "AND g.userid $usql";
388 $this->userselect_params = $params;
4ba9941c 389 }
390
391 return $this->users;
392 }
393
4ba9941c 394 /**
395 * we supply the userids in this query, and get all the grades
396 * pulls out all the grades, this does not need to worry about paging
397 */
d24832f9 398 public function load_final_grades() {
399 global $CFG, $DB;
4ba9941c 400
23207a1a 401 // please note that we must fetch all grade_grades fields if we want to contruct grade_grade object from it!
b50371da 402 $params = array_merge(array('courseid'=>$this->courseid), $this->userselect_params);
b89a70ce 403 $sql = "SELECT g.*
d24832f9 404 FROM {grade_items} gi,
405 {grade_grades} g
b50371da 406 WHERE g.itemid = gi.id AND gi.courseid = :courseid {$this->userselect}";
b89a70ce 407
408 $userids = array_keys($this->users);
4ba9941c 409
d297269d 410
d24832f9 411 if ($grades = $DB->get_records_sql($sql, $params)) {
b89a70ce 412 foreach ($grades as $graderec) {
d24832f9 413 if (in_array($graderec->userid, $userids) and array_key_exists($graderec->itemid, $this->gtree->get_items())) { // some items may not be present!!
b89a70ce 414 $this->grades[$graderec->userid][$graderec->itemid] = new grade_grade($graderec, false);
d24832f9 415 $this->grades[$graderec->userid][$graderec->itemid]->grade_item =& $this->gtree->get_item($graderec->itemid); // db caching
b89a70ce 416 }
417 }
418 }
419
420 // prefil grades that do not exist yet
421 foreach ($userids as $userid) {
d24832f9 422 foreach ($this->gtree->get_items() as $itemid=>$unused) {
b89a70ce 423 if (!isset($this->grades[$userid][$itemid])) {
424 $this->grades[$userid][$itemid] = new grade_grade();
478f4322 425 $this->grades[$userid][$itemid]->itemid = $itemid;
3b34f698 426 $this->grades[$userid][$itemid]->userid = $userid;
d24832f9 427 $this->grades[$userid][$itemid]->grade_item =& $this->gtree->get_item($itemid); // db caching
b89a70ce 428 }
4ba9941c 429 }
430 }
431 }
432
433 /**
434 * Builds and returns a div with on/off toggles.
435 * @return string HTML code
436 */
d24832f9 437 public function get_toggles_html() {
319770d7 438 global $CFG, $USER, $COURSE, $OUTPUT;
aea4df41 439
319770d7 440 $html = '';
2cc773f5 441 if ($USER->gradeediting[$this->courseid]) {
442 if (has_capability('moodle/grade:manage', $this->context) or has_capability('moodle/grade:hide', $this->context)) {
319770d7 443 $html .= $this->print_toggle('eyecons');
2cc773f5 444 }
445 if (has_capability('moodle/grade:manage', $this->context)
446 or has_capability('moodle/grade:lock', $this->context)
447 or has_capability('moodle/grade:unlock', $this->context)) {
319770d7 448 $html .= $this->print_toggle('locks');
2cc773f5 449 }
2ca093fa 450 if (has_capability('moodle/grade:manage', $this->context)) {
319770d7 451 $html .= $this->print_toggle('quickfeedback');
2ca093fa 452 }
453
2cc773f5 454 if (has_capability('moodle/grade:manage', $this->context)) {
319770d7 455 $html .= $this->print_toggle('calculations');
2cc773f5 456 }
4ba9941c 457 }
458
57068674 459 if ($this->canviewhidden) {
319770d7 460 $html .= $this->print_toggle('averages');
57068674 461 }
aae94377 462
319770d7 463 $html .= $this->print_toggle('ranges');
aea4df41 464 if (!empty($CFG->enableoutcomes)) {
319770d7 465 $html .= $this->print_toggle('nooutcomes');
aea4df41 466 }
319770d7 467
468 return $OUTPUT->container($html, 'grade-report-toggles');
4ba9941c 469 }
470
471 /**
472 * Shortcut function for printing the grader report toggles.
473 * @param string $type The type of toggle
474 * @param bool $return Whether to return the HTML string rather than printing it
475 * @return void
476 */
319770d7 477 public function print_toggle($type) {
e63f88c9 478 global $CFG, $OUTPUT;
4ba9941c 479
319770d7 480 $icons = array('eyecons' => 't/hide',
481 'calculations' => 't/calc',
482 'locks' => 't/lock',
483 'averages' => 't/mean',
484 'quickfeedback' => 't/feedback',
485 'nooutcomes' => 't/outcomes');
4ba9941c 486
319770d7 487 $prefname = 'grade_report_show' . $type;
aea4df41 488
319770d7 489 if (array_key_exists($prefname, $CFG)) {
490 $showpref = get_user_preferences($prefname, $CFG->$prefname);
aea4df41 491 } else {
319770d7 492 $showpref = get_user_preferences($prefname);
aea4df41 493 }
4ba9941c 494
388234f4 495 $strshow = $this->get_lang_string('show' . $type, 'grades');
496 $strhide = $this->get_lang_string('hide' . $type, 'grades');
4ba9941c 497
319770d7 498 $showhide = 'show';
499 $toggleaction = 1;
4ba9941c 500
319770d7 501 if ($showpref) {
502 $showhide = 'hide';
503 $toggleaction = 0;
4ba9941c 504 }
505
506 if (array_key_exists($type, $icons)) {
319770d7 507 $imagename = $icons[$type];
4ba9941c 508 } else {
319770d7 509 $imagename = "t/$type.gif";
4ba9941c 510 }
511
319770d7 512 $string = ${'str' . $showhide};
4ba9941c 513
8ae8bf8a
PS
514 $aurl = clone($this->baseurl);
515 $url->params(array('toggle' => $toggleaction, 'toggle_type' => $type));
4ba9941c 516
c63923bd 517 $retval = $OUTPUT->container($OUTPUT->action_icon($url, new pix_icon($imagename, $string))); // TODO: this container looks wrong here
4ba9941c 518
319770d7 519 return $retval;
4ba9941c 520 }
521
522 /**
6c096a49
NC
523 * Builds and returns the rows that will make up the left part of the grader report
524 * This consists of student names and icons, links to user reports and id numbers, as well
525 * as header cells for these columns. It also includes the fillers required for the
526 * categories displayed on the right side of the report.
527 * @return array Array of html_table_row objects
4ba9941c 528 */
6c096a49 529 public function get_left_rows() {
319770d7 530 global $CFG, $USER, $OUTPUT;
4ba9941c 531
6c096a49
NC
532 $rows = array();
533
534 $showuserimage = $this->get_pref('showuserimage');
535 $showuseridnumber = $this->get_pref('showuseridnumber');
795b745a 536 $fixedstudents = $this->is_fixed_students();
203b7e2e 537
6c096a49
NC
538 $strfeedback = $this->get_lang_string("feedback");
539 $strgrade = $this->get_lang_string('grade');
203b7e2e 540
6c096a49
NC
541 $arrows = $this->get_sort_arrows();
542
543 $colspan = 1;
544
3e7ca6b3 545 if (has_capability('gradereport/'.$CFG->grade_profilereport.':view', $this->context)) {
6c096a49
NC
546 $colspan++;
547 }
548
549 if ($showuseridnumber) {
550 $colspan++;
551 }
552
553 $levels = count($this->gtree->levels) - 1;
554
555 for ($i = 0; $i < $levels; $i++) {
556 $fillercell = new html_table_cell();
16be8974 557 $fillercell->attributes['class'] = 'fixedcolumn cell topleft';
6c096a49
NC
558 $fillercell->text = ' ';
559 $fillercell->colspan = $colspan;
8cea545e 560 $row = new html_table_row(array($fillercell));
6c096a49
NC
561 $rows[] = $row;
562 }
563
564 $headerrow = new html_table_row();
16be8974 565 $headerrow->attributes['class'] = 'heading';
6c096a49
NC
566
567 $studentheader = new html_table_cell();
16be8974 568 $studentheader->attributes['class'] = 'header';
6c096a49
NC
569 $studentheader->scope = 'col';
570 $studentheader->header = true;
571 $studentheader->id = 'studentheader';
3e7ca6b3 572 if (has_capability('gradereport/'.$CFG->grade_profilereport.':view', $this->context)) {
6c096a49
NC
573 $studentheader->colspan = 2;
574 }
575 $studentheader->text = $arrows['studentname'];
576
577 $headerrow->cells[] = $studentheader;
578
579 if ($showuseridnumber) {
0f4c64b7
PS
580 // TODO: weird, this is not used anywhere
581 $sortidnumberlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>'idnumber')), get_string('idnumber'));
6c096a49
NC
582
583 $idnumberheader = new html_table_cell();
16be8974 584 $idnumberheader->attributes['class'] = 'header useridnumber';
6c096a49
NC
585 $idnumberheader->scope = 'col';
586 $idnumberheader->header = true;
587 $idnumberheader->text = $arrows['idnumber'];
588
589 $headerrow->cells[] = $idnumberheader;
590 }
591
592 $rows[] = $headerrow;
593
594 $rows = $this->get_left_icons_row($rows, $colspan);
595
596 $rowclasses = array('even', 'odd');
597
598 foreach ($this->users as $userid => $user) {
599 $userrow = new html_table_row();
fe213365 600 $userrow->id = 'fixed_user_'.$userid;
abfe77ea 601 $userrow->attributes['class'] = 'r'.$this->rowcount++.' '.$rowclasses[$this->rowcount % 2];
6c096a49
NC
602
603 $usercell = new html_table_cell();
16be8974 604 $usercell->attributes['class'] = 'user';
6c096a49
NC
605 $usercell->header = true;
606 $usercell->scope = 'row';
6c096a49
NC
607
608 if ($showuserimage) {
812dbaf7 609 $usercell->text = $OUTPUT->container($OUTPUT->user_picture($user), 'userpic');
203b7e2e 610 }
611
a6855934 612 $usercell->text .= html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $this->course->id)), fullname($user));
6c096a49
NC
613
614 $userrow->cells[] = $usercell;
615
3e7ca6b3 616 if (has_capability('gradereport/'.$CFG->grade_profilereport.':view', $this->context)) {
6c096a49 617 $userreportcell = new html_table_cell();
16be8974 618 $userreportcell->attributes['class'] = 'userreport';
6c096a49
NC
619 $userreportcell->header = true;
620 $a->user = fullname($user);
621 $strgradesforuser = get_string('gradesforuser', 'grades', $a);
a6855934 622 $url = new moodle_url('/grade/report/'.$CFG->grade_profilereport.'/index.php', array('userid' => $user->id, 'id' => $this->course->id));
c63923bd 623 $userreportcell->text = $OUTPUT->action_icon($url, new pix_icon('t/grades', $strgradesforuser));
6c096a49 624 $userrow->cells[] = $userreportcell;
203b7e2e 625 }
626
6c096a49
NC
627 if ($showuseridnumber) {
628 $idnumbercell = new html_table_cell();
16be8974 629 $idnumbercell->attributes['class'] = 'header useridnumber';
6c096a49
NC
630 $idnumbercell->header = true;
631 $idnumbercell->scope = 'row';
6c096a49
NC
632 $userrow->cells[] = $idnumbercell;
633 }
634
635 $rows[] = $userrow;
203b7e2e 636 }
4ba9941c 637
6c096a49
NC
638 $rows = $this->get_left_range_row($rows, $colspan);
639 $rows = $this->get_left_avg_row($rows, $colspan, true);
640 $rows = $this->get_left_avg_row($rows, $colspan);
4ba9941c 641
6c096a49
NC
642 return $rows;
643 }
644
645 /**
646 * Builds and returns the rows that will make up the right part of the grader report
647 * @return array Array of html_table_row objects
648 */
649 public function get_right_rows() {
fe213365 650 global $CFG, $USER, $OUTPUT, $DB, $PAGE;
4ba9941c 651
6c096a49
NC
652 $rows = array();
653 $this->rowcount = 0;
654 $numrows = count($this->gtree->get_levels());
655 $numusers = count($this->users);
656 $gradetabindex = 1;
319770d7 657 $columnstounset = array();
6c096a49 658 $strgrade = $this->get_lang_string('grade');
fe213365 659 $strfeedback = $this->get_lang_string("feedback");
6c096a49 660 $arrows = $this->get_sort_arrows();
cb7fe7b4 661
fe213365
SH
662 $jsarguments = array(
663 'id' => '#fixed_column',
664 'cfg' => array('ajaxenabled'=>false),
665 'items' => array(),
666 'users' => array(),
667 'feedback' => array()
668 );
669 $jsscales = array();
670
d24832f9 671 foreach ($this->gtree->get_levels() as $key=>$row) {
4ba9941c 672 if ($key == 0) {
cb7fe7b4 673 // do not display course grade category
4ba9941c 674 // continue;
675 }
676
6c096a49 677 $headingrow = new html_table_row();
16be8974 678 $headingrow->attributes['class'] = 'heading_name_row';
4ba9941c 679
cb7fe7b4 680 foreach ($row as $columnkey => $element) {
319770d7 681 $sortlink = clone($this->baseurl);
2e3987a9 682 if (isset($element['object']->id)) {
319770d7 683 $sortlink->param('sortitemid', $element['object']->id);
2e3987a9 684 }
685
cb7fe7b4 686 $eid = $element['eid'];
687 $object = $element['object'];
688 $type = $element['type'];
438a5aa9 689 $categorystate = @$element['categorystate'];
2e3987a9 690 $itemmodule = null;
691 $iteminstance = null;
8c5a416e 692
4ba9941c 693 if (!empty($element['colspan'])) {
6c096a49 694 $colspan = $element['colspan'];
4ba9941c 695 } else {
6c096a49 696 $colspan = 1;
4ba9941c 697 }
698
699 if (!empty($element['depth'])) {
6c096a49 700 $catlevel = 'catlevel'.$element['depth'];
4ba9941c 701 } else {
702 $catlevel = '';
703 }
704
cb7fe7b4 705// Element is a filler
4ba9941c 706 if ($type == 'filler' or $type == 'fillerfirst' or $type == 'fillerlast') {
6c096a49 707 $fillercell = new html_table_cell();
16be8974 708 $fillercell->attributes['class'] = $type . ' ' . $catlevel;
6c096a49
NC
709 $fillercell->colspan = $colspan;
710 $fillercell->text = '&nbsp;';
711 $fillercell->header = true;
712 $fillercell->scope = 'col';
713 $headingrow->cells[] = $fillercell;
cb7fe7b4 714 }
715// Element is a category
4faf5f99 716 else if ($type == 'category') {
6c096a49 717 $categorycell = new html_table_cell();
16be8974 718 $categorycell->attributes['class'] = 'category ' . $catlevel;
6c096a49
NC
719 $categorycell->colspan = $colspan;
720 $categorycell->text = shorten_text($element['object']->get_name());
721 $categorycell->text .= $this->get_collapsing_icon($element);
722 $categorycell->header = true;
723 $categorycell->scope = 'col';
4ba9941c 724
725 // Print icons
2cc773f5 726 if ($USER->gradeediting[$this->courseid]) {
6c096a49 727 $categorycell->text .= $this->get_icons($element);
4ba9941c 728 }
729
6c096a49 730 $headingrow->cells[] = $categorycell;
cb7fe7b4 731 }
732// Element is a grade_item
4faf5f99 733 else {
2e3987a9 734 $itemmodule = $element['object']->itemmodule;
735 $iteminstance = $element['object']->iteminstance;
736
4ba9941c 737 if ($element['object']->id == $this->sortitemid) {
738 if ($this->sortorder == 'ASC') {
319770d7 739 $arrow = $this->get_sort_arrow('up', $sortlink);
4ba9941c 740 } else {
319770d7 741 $arrow = $this->get_sort_arrow('down', $sortlink);
4ba9941c 742 }
743 } else {
319770d7 744 $arrow = $this->get_sort_arrow('move', $sortlink);
4ba9941c 745 }
746
6c096a49
NC
747 $headerlink = $this->gtree->get_element_header($element, true, $this->get_pref('showactivityicons'), false);
748
749 $itemcell = new html_table_cell();
16be8974 750 $itemcell->attributes['class'] = $type . ' ' . $catlevel . 'highlightable';
6c096a49 751
4ba9941c 752 if ($element['object']->is_hidden()) {
16be8974 753 $itemcell->attributes['class'] .= ' hidden';
4ba9941c 754 }
755
6c096a49
NC
756 $itemcell->colspan = $colspan;
757 $itemcell->text = shorten_text($headerlink) . $arrow;
758 $itemcell->header = true;
759 $itemcell->scope = 'col';
6c096a49
NC
760
761 $headingrow->cells[] = $itemcell;
4ba9941c 762 }
4ba9941c 763 }
6c096a49 764 $rows[] = $headingrow;
4ba9941c 765 }
4ba9941c 766
6c096a49 767 $rows = $this->get_right_icons_row($rows);
4ba9941c 768
388234f4 769 // Preload scale objects for items with a scaleid
319770d7 770 $scaleslist = array();
c0c1e7c2 771 $tabindices = array();
d297269d 772
fe213365
SH
773 foreach ($this->gtree->get_items() as $itemid=>$item) {
774 $scale = null;
388234f4 775 if (!empty($item->scaleid)) {
319770d7 776 $scaleslist[] = $item->scaleid;
fe213365
SH
777 $jsarguments['items'][$itemid] = array('id'=>$itemid, 'name'=>$item->get_name(true), 'type'=>'scale', 'scale'=>$item->scaleid, 'decimals'=>$item->get_decimals());
778 } else {
779 $jsarguments['items'][$itemid] = array('id'=>$itemid, 'name'=>$item->get_name(true), 'type'=>'value', 'scale'=>false, 'decimals'=>$item->get_decimals());
388234f4 780 }
c0c1e7c2 781 $tabindices[$item->id]['grade'] = $gradetabindex;
782 $tabindices[$item->id]['feedback'] = $gradetabindex + $numusers;
783 $gradetabindex += $numusers * 2;
388234f4 784 }
319770d7 785 $scalesarray = array();
388234f4 786
319770d7 787 if (!empty($scaleslist)) {
788 $scalesarray = $DB->get_records_list('scale', 'id', $scaleslist);
388234f4 789 }
fe213365 790 $jsscales = $scalesarray;
d24832f9 791
6c096a49 792 $rowclasses = array('even', 'odd');
a47d38f2 793
4ba9941c 794 foreach ($this->users as $userid => $user) {
b89a70ce 795
57068674 796 if ($this->canviewhidden) {
d297269d 797 $altered = array();
798 $unknown = array();
b89a70ce 799 } else {
319770d7 800 $hidingaffected = grade_grade::get_hiding_affected($this->grades[$userid], $this->gtree->get_items());
801 $altered = $hidingaffected['altered'];
802 $unknown = $hidingaffected['unknown'];
803 unset($hidingaffected);
b89a70ce 804 }
805
bb9b58a6 806
6c096a49 807 $itemrow = new html_table_row();
fe213365 808 $itemrow->id = 'user_'.$userid;
16be8974 809 $itemrow->attributes['class'] = $rowclasses[$this->rowcount % 2];
9d35e66e 810
fe213365
SH
811 $jsarguments['users'][$userid] = fullname($user);
812
dc482cfa 813 foreach ($this->gtree->items as $itemid=>$unused) {
814 $item =& $this->gtree->items[$itemid];
d297269d 815 $grade = $this->grades[$userid][$item->id];
b89a70ce 816
6c096a49
NC
817 $itemcell = new html_table_cell();
818
fe213365
SH
819 $itemcell->id = 'u'.$userid.'i'.$itemid;
820
e50ce569 821 // Get the decimal points preference for this item
31a6c06c 822 $decimalpoints = $item->get_decimals();
4ba9941c 823
d297269d 824 if (in_array($itemid, $unknown)) {
825 $gradeval = null;
826 } else if (array_key_exists($itemid, $altered)) {
827 $gradeval = $altered[$itemid];
828 } else {
829 $gradeval = $grade->finalgrade;
830 }
4ba9941c 831
00374cc5 832 // MDL-11274
833 // Hide grades in the grader report if the current grader doesn't have 'moodle/grade:viewhidden'
57068674 834 if (!$this->canviewhidden and $grade->is_hidden()) {
6cc3e350 835 if (!empty($CFG->grade_hiddenasdate) and $grade->get_datesubmitted() and !$item->is_category_item() and !$item->is_course_item()) {
d297269d 836 // the problem here is that we do not have the time when grade value was modified, 'timemodified' is general modification date for grade_grades records
26acc814 837 $itemcell->text = html_writer::tag('span', userdate($grade->get_datesubmitted(),get_string('strftimedatetimeshort')), array('class'=>'datesubmitted'));
bb49f77b 838 } else {
6c096a49 839 $itemcell->text = '-';
00374cc5 840 }
6c096a49 841 $itemrow->cells[] = $itemcell;
a5b8be62 842 continue;
00374cc5 843 }
844
2cc773f5 845 // emulate grade element
d3c3da1b 846 $eid = $this->gtree->get_grade_eid($grade);
847 $element = array('eid'=>$eid, 'object'=>$grade, 'type'=>'grade');
2cc773f5 848
16be8974 849 $itemcell->attributes['class'] .= ' grade';
dff9d94d 850 if ($item->is_category_item()) {
16be8974 851 $itemcell->attributes['class'] .= ' cat';
b89a70ce 852 }
dff9d94d 853 if ($item->is_course_item()) {
16be8974 854 $itemcell->attributes['class'] .= ' course';
b89a70ce 855 }
4ba9941c 856 if ($grade->is_overridden()) {
16be8974 857 $itemcell->attributes['class'] .= ' overridden';
4ba9941c 858 }
85db09fb 859
5ebce7bb 860 if ($grade->is_excluded()) {
16be8974 861 // $itemcell->attributes['class'] .= ' excluded';
5ebce7bb 862 }
4ba9941c 863
fe213365 864 if (!empty($grade->feedback)) {
92ff6236 865 //should we be truncating feedback? ie $short_feedback = shorten_text($feedback, $this->feedback_trunc_length);
fe213365 866 $jsarguments['feedback'][] = array('user'=>$userid, 'item'=>$itemid, 'content'=>wordwrap(trim(format_string($grade->feedback, $grade->feedbackformat)), 34, '<br/ >'));
653a8648 867 }
868
23207a1a 869 if ($grade->is_excluded()) {
26acc814 870 $itemcell->text .= html_writer::tag('span', get_string('excluded', 'grades'), array('class'=>'excludedfloater'));
23207a1a 871 }
872
4ba9941c 873 // Do not show any icons if no grade (no record in DB to match)
d3c3da1b 874 if (!$item->needsupdate and $USER->gradeediting[$this->courseid]) {
6c096a49 875 $itemcell->text .= $this->get_icons($element);
4ba9941c 876 }
877
80fb1cf9 878 $hidden = '';
879 if ($grade->is_hidden()) {
880 $hidden = ' hidden ';
881 }
6cc3e350 882
d24832f9 883 $gradepass = ' gradefail ';
46e6df89 884 if ($grade->is_passed($item)) {
885 $gradepass = ' gradepass ';
e6477988 886 } elseif (is_null($grade->is_passed($item))) {
887 $gradepass = '';
46e6df89 888 }
889
4ba9941c 890 // if in editting mode, we need to print either a text box
891 // or a drop down (for scales)
4ba9941c 892 // grades in item of type grade category or course are not directly editable
d14ae855 893 if ($item->needsupdate) {
26acc814 894 $itemcell->text .= html_writer::tag('span', get_string('error'), array('class'=>"gradingerror$hidden"));
d14ae855 895
2cc773f5 896 } else if ($USER->gradeediting[$this->courseid]) {
4ba9941c 897
319770d7 898 if ($item->scaleid && !empty($scalesarray[$item->scaleid])) {
899 $scale = $scalesarray[$item->scaleid];
99ccfda8 900 $gradeval = (int)$gradeval; // scales use only integers
388234f4 901 $scales = explode(",", $scale->scale);
902 // reindex because scale is off 1
9d35e66e 903
914ea002 904 // MDL-12104 some previous scales might have taken up part of the array
905 // so this needs to be reset
d48ebf97 906 $scaleopt = array();
388234f4 907 $i = 0;
908 foreach ($scales as $scaleoption) {
909 $i++;
910 $scaleopt[$i] = $scaleoption;
911 }
912
913 if ($this->get_pref('quickgrading') and $grade->is_editable()) {
0658afc9 914 $oldval = empty($gradeval) ? -1 : $gradeval;
915 if (empty($item->outcomeid)) {
d4795a07 916 $nogradestr = $this->get_lang_string('nograde');
0658afc9 917 } else {
d4795a07 918 $nogradestr = $this->get_lang_string('nooutcome', 'grades');
0658afc9 919 }
fe213365
SH
920 $itemcell->text .= '<input type="hidden" id="oldgrade_'.$userid.'_'.$item->id.'" name="oldgrade_'.$userid.'_'.$item->id.'" value="'.$oldval.'"/>';
921 $attributes = array('tabindex' => $tabindices[$item->id]['grade'], 'id'=>'grade_'.$userid.'_'.$item->id);
064527d6 922 $itemcell->text .= html_writer::select($scaleopt, 'grade_'.$userid.'_'.$item->id, $gradeval, array(-1=>$nogradestr), $attributes);;
388234f4 923 } elseif(!empty($scale)) {
4ba9941c 924 $scales = explode(",", $scale->scale);
4ba9941c 925
388234f4 926 // invalid grade if gradeval < 1
99ccfda8 927 if ($gradeval < 1) {
26acc814 928 $itemcell->text .= html_writer::tag('span', '-', array('class'=>"gradevalue$hidden$gradepass"));
4ba9941c 929 } else {
653a8648 930 $gradeval = $grade->grade_item->bounded_grade($gradeval); //just in case somebody changes scale
26acc814 931 $itemcell->text .= html_writer::tag('span', $scales[$gradeval-1], array('class'=>"gradevalue$hidden$gradepass"));
4ba9941c 932 }
388234f4 933 } else {
934 // no such scale, throw error?
4ba9941c 935 }
79eabc2a 936
bb384a8e 937 } else if ($item->gradetype != GRADE_TYPE_TEXT) { // Value type
936f1350 938 if ($this->get_pref('quickgrading') and $grade->is_editable()) {
76317c73 939 $value = format_float($gradeval, $decimalpoints);
fe213365 940 $itemcell->text .= '<input type="hidden" id="oldgrade_'.$userid.'_'.$item->id.'" name="oldgrade_'.$userid.'_'.$item->id.'" value="'.$value.'" />';
6c096a49 941 $itemcell->text .= '<input size="6" tabindex="' . $tabindices[$item->id]['grade']
319770d7 942 . '" type="text" class="text" title="'. $strgrade .'" name="grade_'
fe213365 943 .$userid.'_' .$item->id.'" id="grade_'.$userid.'_'.$item->id.'" value="'.$value.'" />';
4ba9941c 944 } else {
26acc814 945 $itemcell->text .= html_writer::tag('span', format_float($gradeval, $decimalpoints), array('class'=>"gradevalue$hidden$gradepass"));
4ba9941c 946 }
947 }
948
949
950 // If quickfeedback is on, print an input element
2ca093fa 951 if ($this->get_pref('showquickfeedback') and $grade->is_editable()) {
dc482cfa 952
fe213365
SH
953 $itemcell->text .= '<input type="hidden" id="oldfeedback_'.$userid.'_'.$item->id.'" name="oldfeedback_'.$userid.'_'.$item->id.'" value="' . s($grade->feedback) . '" />';
954 $itemcell->text .= '<input class="quickfeedback" tabindex="' . $tabindices[$item->id]['feedback'].'" id="feedback_'.$userid.'_'.$item->id
955 . '" size="6" title="' . $strfeedback . '" type="text" name="feedback_'.$userid.'_'.$item->id.'" value="' . s($grade->feedback) . '" />';
4ba9941c 956 }
957
78a2d9f0 958 } else { // Not editing
41f22daa 959 $gradedisplaytype = $item->get_displaytype();
e50ce569 960
fe213365 961 if ($item->scaleid && !empty($scalesarray[$item->scaleid])) {
16be8974 962 $itemcell->attributes['class'] .= ' grade_type_scale';
fe213365 963 } else if ($item->gradetype != GRADE_TYPE_TEXT) {
16be8974 964 $itemcell->attributes['class'] .= ' grade_type_text';
fe213365 965 }
4ba9941c 966
6712973f
AD
967 if ($this->get_pref('enableajax')) {
968 $itemcell->attributes['class'] .= ' clickable';
969 }
970
d14ae855 971 if ($item->needsupdate) {
26acc814 972 $itemcell->text .= html_writer::tag('span', get_string('error'), array('class'=>"gradingerror$hidden$gradepass"));
4ba9941c 973 } else {
26acc814 974 $itemcell->text .= html_writer::tag('span', grade_format_gradevalue($gradeval, $item, true, $gradedisplaytype, null), array('class'=>"gradevalue$hidden$gradepass"));
4ba9941c 975 }
4ba9941c 976 }
977
978 if (!empty($this->gradeserror[$item->id][$userid])) {
6c096a49 979 $itemcell->text .= $this->gradeserror[$item->id][$userid];
4ba9941c 980 }
981
6c096a49 982 $itemrow->cells[] = $itemcell;
4ba9941c 983 }
6c096a49 984 $rows[] = $itemrow;
4ba9941c 985 }
4ba9941c 986
fe213365
SH
987 if ($this->get_pref('enableajax')) {
988 $jsarguments['cfg']['ajaxenabled'] = true;
989 $jsarguments['cfg']['scales'] = array();
990 foreach ($jsscales as $scale) {
991 $jsarguments['cfg']['scales'][$scale->id] = explode(',',$scale->scale);
992 }
993 $jsarguments['cfg']['feedbacktrunclength'] = $this->feedback_trunc_length;
92ff6236
AD
994
995 //feedbacks are now being stored in $jsarguments['feedback'] in get_right_rows()
996 //$jsarguments['cfg']['feedback'] = $this->feedbacks;
fe213365
SH
997 }
998 $jsarguments['cfg']['isediting'] = (bool)$USER->gradeediting[$this->courseid];
999 $jsarguments['cfg']['courseid'] = $this->courseid;
1000 $jsarguments['cfg']['studentsperpage'] = $this->get_pref('studentsperpage');
1001 $jsarguments['cfg']['showquickfeedback'] = (bool)$this->get_pref('showquickfeedback');
1002
1003 $module = array(
1004 'name' => 'gradereport_grader',
1005 'fullpath' => '/grade/report/grader/module.js',
1006 'requires' => array('base', 'dom', 'event', 'event-mouseenter', 'event-key', 'io', 'json-parse', 'overlay')
1007 );
1008 $PAGE->requires->js_init_call('M.gradereport_grader.init_report', $jsarguments, false, $module);
1009 $PAGE->requires->strings_for_js(array('addfeedback','feedback', 'grade'), 'grades');
1010 $PAGE->requires->strings_for_js(array('ajaxchoosescale','ajaxclicktoclose','ajaxerror','ajaxfailedupdate', 'ajaxfieldchanged'), 'gradereport_grader');
1011
6c096a49
NC
1012 $rows = $this->get_right_range_row($rows);
1013 $rows = $this->get_right_avg_row($rows, true);
1014 $rows = $this->get_right_avg_row($rows);
dc482cfa 1015
6c096a49
NC
1016 return $rows;
1017 }
dc482cfa 1018
6c096a49
NC
1019 /**
1020 * Depending on the style of report (fixedstudents vs traditional one-table),
1021 * arranges the rows of data in one or two tables, and returns the output of
1022 * these tables in HTML
1023 * @return string HTML
1024 */
1025 public function get_grade_table() {
1026 global $OUTPUT;
1027 $fixedstudents = $this->is_fixed_students();
dc482cfa 1028
6c096a49
NC
1029 $leftrows = $this->get_left_rows();
1030 $rightrows = $this->get_right_rows();
dc482cfa 1031
6c096a49 1032 $html = '';
dc482cfa 1033
fe213365 1034
203b7e2e 1035 if ($fixedstudents) {
319770d7 1036 $fixedcolumntable = new html_table();
1037 $fixedcolumntable->id = 'fixed_column';
6c096a49 1038 $fixedcolumntable->data = $leftrows;
16be8974 1039 $html .= $OUTPUT->container(html_writer::table($fixedcolumntable), 'left_scroller');
dc482cfa 1040
6c096a49
NC
1041 $righttable = new html_table();
1042 $righttable->id = 'user-grades';
6c096a49 1043 $righttable->data = $rightrows;
319770d7 1044
16be8974 1045 $html .= $OUTPUT->container(html_writer::table($righttable), 'right_scroller');
6c096a49
NC
1046 } else {
1047 $fulltable = new html_table();
16be8974 1048 $fulltable->attributes['class'] = 'gradestable flexible boxaligncenter generaltable';
6c096a49
NC
1049 $fulltable->id = 'user-grades';
1050
1051 // Extract rows from each side (left and right) and collate them into one row each
1052 foreach ($leftrows as $key => $row) {
1053 $row->cells = array_merge($row->cells, $rightrows[$key]->cells);
1054 $fulltable->data[] = $row;
203b7e2e 1055 }
16be8974 1056 $html .= html_writer::table($fulltable);
6c096a49
NC
1057 }
1058 return $OUTPUT->container($html, 'gradeparent');
1059 }
dc482cfa 1060
6c096a49
NC
1061 /**
1062 * Builds and return the row of icons for the left side of the report.
1063 * It only has one cell that says "Controls"
1064 * @param array $rows The Array of rows for the left part of the report
1065 * @param int $colspan The number of columns this cell has to span
1066 * @return array Array of rows for the left part of the report
1067 */
1068 public function get_left_icons_row($rows=array(), $colspan=1) {
1069 global $USER;
dc482cfa 1070
6c096a49
NC
1071 if ($USER->gradeediting[$this->courseid]) {
1072 $controlsrow = new html_table_row();
16be8974 1073 $controlsrow->attributes['class'] = 'controls';
6c096a49 1074 $controlscell = new html_table_cell();
16be8974 1075 $controlscell->attributes['class'] = 'header controls';
6c096a49
NC
1076 $controlscell->colspan = $colspan;
1077 $controlscell->text = $this->get_lang_string('controls','grades');
1078
1079 $controlsrow->cells[] = $controlscell;
1080 $rows[] = $controlsrow;
1081 }
1082 return $rows;
1083 }
dc482cfa 1084
6c096a49
NC
1085 /**
1086 * Builds and return the header for the row of ranges, for the left part of the grader report.
1087 * @param array $rows The Array of rows for the left part of the report
1088 * @param int $colspan The number of columns this cell has to span
1089 * @return array Array of rows for the left part of the report
1090 */
1091 public function get_left_range_row($rows=array(), $colspan=1) {
1092 global $CFG, $USER;
bb9b58a6 1093
6c096a49
NC
1094 if ($this->get_pref('showranges')) {
1095 $rangerow = new html_table_row();
16be8974 1096 $rangerow->attributes['class'] = 'range r'.$this->rowcount++;
6c096a49 1097 $rangecell = new html_table_cell();
16be8974 1098 $rangecell->attributes['class'] = 'header range';
6c096a49
NC
1099 $rangecell->colspan = $colspan;
1100 $rangecell->header = true;
1101 $rangecell->scope = 'row';
1102 $rangecell->text = $this->get_lang_string('range','grades');
1103 $rangerow->cells[] = $rangecell;
1104 $rows[] = $rangerow;
1105 }
dc482cfa 1106
6c096a49
NC
1107 return $rows;
1108 }
dc482cfa 1109
6c096a49
NC
1110 /**
1111 * Builds and return the headers for the rows of averages, for the left part of the grader report.
1112 * @param array $rows The Array of rows for the left part of the report
1113 * @param int $colspan The number of columns this cell has to span
1114 * @param bool $groupavg If true, returns the row for group averages, otherwise for overall averages
1115 * @return array Array of rows for the left part of the report
1116 */
1117 public function get_left_avg_row($rows=array(), $colspan=1, $groupavg=false) {
1118 if (!$this->canviewhidden) {
1119 // totals might be affected by hiding, if user can not see hidden grades the aggregations might be altered
1120 // better not show them at all if user can not see all hideen grades
1121 return $rows;
1122 }
dc482cfa 1123
6c096a49
NC
1124 $showaverages = $this->get_pref('showaverages');
1125 $showaveragesgroup = $this->currentgroup && $showaverages;
1126 $straveragegroup = get_string('groupavg', 'grades');
319770d7 1127
6c096a49 1128 if ($groupavg) {
319770d7 1129 if ($showaveragesgroup) {
1130 $groupavgrow = new html_table_row();
16be8974 1131 $groupavgrow->attributes['class'] = 'groupavg r'.$this->rowcount++;
319770d7 1132 $groupavgcell = new html_table_cell();
16be8974 1133 $groupavgcell->attributes['class'] = 'header range';
319770d7 1134 $groupavgcell->colspan = $colspan;
1135 $groupavgcell->header = true;
1136 $groupavgcell->scope = 'row';
1137 $groupavgcell->text = $straveragegroup;
1138 $groupavgrow->cells[] = $groupavgcell;
6c096a49 1139 $rows[] = $groupavgrow;
203b7e2e 1140 }
6c096a49
NC
1141 } else {
1142 $straverage = get_string('overallaverage', 'grades');
dc482cfa 1143
203b7e2e 1144 if ($showaverages) {
319770d7 1145 $avgrow = new html_table_row();
16be8974 1146 $avgrow->attributes['class'] = 'avg r'.$this->rowcount++;
319770d7 1147 $avgcell = new html_table_cell();
16be8974 1148 $avgcell->attributes['class'] = 'header range';
319770d7 1149 $avgcell->colspan = $colspan;
1150 $avgcell->header = true;
1151 $avgcell->scope = 'row';
1152 $avgcell->text = $straverage;
1153 $avgrow->cells[] = $avgcell;
6c096a49 1154 $rows[] = $avgrow;
203b7e2e 1155 }
6c096a49 1156 }
203b7e2e 1157
6c096a49
NC
1158 return $rows;
1159 }
dc482cfa 1160
6c096a49
NC
1161 /**
1162 * Builds and return the row of icons when editing is on, for the right part of the grader report.
1163 * @param array $rows The Array of rows for the right part of the report
1164 * @return array Array of rows for the right part of the report
1165 */
1166 public function get_right_icons_row($rows=array()) {
1167 global $USER;
1168 if ($USER->gradeediting[$this->courseid]) {
1169 $iconsrow = new html_table_row();
16be8974 1170 $iconsrow->attributes['class'] = 'controls';
6c096a49
NC
1171
1172 $showuseridnumber = $this->get_pref('showuseridnumber');
dc482cfa 1173
6c096a49
NC
1174 foreach ($this->gtree->items as $itemid=>$unused) {
1175 // emulate grade element
1176 $item =& $this->gtree->get_item($itemid);
1177
1178 $eid = $this->gtree->get_item_eid($item);
1179 $element = $this->gtree->locate_element($eid);
1180 $itemcell = new html_table_cell();
16be8974 1181 $itemcell->attributes['class'] = 'controls icons';
6c096a49
NC
1182 $itemcell->text = $this->get_icons($element);
1183 $iconsrow->cells[] = $itemcell;
1184 }
1185 $rows[] = $iconsrow;
1186 }
1187 return $rows;
dc482cfa 1188 }
1189
18a00359 1190 /**
6c096a49
NC
1191 * Builds and return the row of ranges for the right part of the grader report.
1192 * @param array $rows The Array of rows for the right part of the report
1193 * @return array Array of rows for the right part of the report
18a00359 1194 */
6c096a49
NC
1195 public function get_right_range_row($rows=array()) {
1196 global $OUTPUT;
18a00359 1197
6c096a49
NC
1198 if ($this->get_pref('showranges')) {
1199 $rangesdisplaytype = $this->get_pref('rangesdisplaytype');
1200 $rangesdecimalpoints = $this->get_pref('rangesdecimalpoints');
1201 $rangerow = new html_table_row();
16be8974 1202 $rangerow->attributes['class'] = 'heading range';
18a00359 1203
6c096a49
NC
1204 foreach ($this->gtree->items as $itemid=>$unused) {
1205 $item =& $this->gtree->items[$itemid];
1206 $itemcell = new html_table_cell();
1207 $itemcell->header = true;
16be8974 1208 $itemcell->attributes['class'] .= ' header range';
6c096a49
NC
1209
1210 $hidden = '';
1211 if ($item->is_hidden()) {
1212 $hidden = ' hidden ';
1213 }
1214
1215 $formattedrange = $item->get_formatted_range($rangesdisplaytype, $rangesdecimalpoints);
1216
1217 $itemcell->text = $OUTPUT->container($formattedrange, 'rangevalues'.$hidden);
1218 $rangerow->cells[] = $itemcell;
1219 }
1220 $rows[] = $rangerow;
18a00359 1221 }
6c096a49 1222 return $rows;
18a00359 1223 }
1224
4ba9941c 1225 /**
6c096a49
NC
1226 * Builds and return the row of averages for the right part of the grader report.
1227 * @param array $rows Whether to return only group averages or all averages.
1228 * @param bool $grouponly Whether to return only group averages or all averages.
1229 * @return array Array of rows for the right part of the report
4ba9941c 1230 */
6c096a49
NC
1231 public function get_right_avg_row($rows=array(), $grouponly=false) {
1232 global $CFG, $USER, $DB, $OUTPUT;
4ba9941c 1233
57068674 1234 if (!$this->canviewhidden) {
1235 // totals might be affected by hiding, if user can not see hidden grades the aggregations might be altered
1236 // better not show them at all if user can not see all hideen grades
6c096a49 1237 return $rows;
57068674 1238 }
1239
6c096a49
NC
1240 $showaverages = $this->get_pref('showaverages');
1241 $showaveragesgroup = $this->currentgroup && $showaverages;
1242
5b508a08 1243 $averagesdisplaytype = $this->get_pref('averagesdisplaytype');
1244 $averagesdecimalpoints = $this->get_pref('averagesdecimalpoints');
098042ba 1245 $meanselection = $this->get_pref('meanselection');
1246 $shownumberofgrades = $this->get_pref('shownumberofgrades');
1247
5b508a08 1248 $avghtml = '';
aae94377 1249 $avgcssclass = 'avg';
3446013d 1250
5b508a08 1251 if ($grouponly) {
1252 $straverage = get_string('groupavg', 'grades');
35079f53 1253 $showaverages = $this->currentgroup && $this->get_pref('showaverages');
5b508a08 1254 $groupsql = $this->groupsql;
1255 $groupwheresql = $this->groupwheresql;
319770d7 1256 $groupwheresqlparams = $this->groupwheresql_params;
aae94377 1257 $avgcssclass = 'groupavg';
3446013d 1258 } else {
6308b91c 1259 $straverage = get_string('overallaverage', 'grades');
5b508a08 1260 $showaverages = $this->get_pref('showaverages');
0dba6cb2 1261 $groupsql = "";
1262 $groupwheresql = "";
319770d7 1263 $groupwheresqlparams = array();
3446013d 1264 }
1265
a5b8be62 1266 if ($shownumberofgrades) {
1267 $straverage .= ' (' . get_string('submissions', 'grades') . ') ';
1268 }
1269
f8ae1f86 1270 $totalcount = $this->get_numusers($grouponly);
04259694 1271
319770d7 1272 list($usql, $rolesparams) = $DB->get_in_or_equal(explode(',', $this->gradebookroles), SQL_PARAMS_NAMED, 'grbr0');
d24832f9 1273
5b508a08 1274 if ($showaverages) {
319770d7 1275 $params = array_merge(array('courseid'=>$this->courseid), $rolesparams, $groupwheresqlparams);
04259694 1276
828af11c 1277 // find sums of all grade items in course
1278 $SQL = "SELECT g.itemid, SUM(g.finalgrade) AS sum
d24832f9 1279 FROM {grade_items} gi
1280 JOIN {grade_grades} g ON g.itemid = gi.id
1281 JOIN {user} u ON u.id = g.userid
1282 JOIN {role_assignments} ra ON ra.userid = u.id
828af11c 1283 $groupsql
b50371da 1284 WHERE gi.courseid = :courseid
d24832f9 1285 AND ra.roleid $usql
828af11c 1286 AND ra.contextid ".get_related_contexts_string($this->context)."
1287 AND g.finalgrade IS NOT NULL
883187d0 1288 $groupwheresql
883187d0 1289 GROUP BY g.itemid";
319770d7 1290 $sumarray = array();
d24832f9 1291 if ($sums = $DB->get_records_sql($SQL, $params)) {
ab3444d7 1292 foreach ($sums as $itemid => $csum) {
319770d7 1293 $sumarray[$itemid] = $csum->sum;
7b61efbe 1294 }
4ba9941c 1295 }
66ef0471 1296
883187d0 1297 // MDL-10875 Empty grades must be evaluated as grademin, NOT always 0
1298 // This query returns a count of ungraded grades (NULL finalgrade OR no matching record in grade_grades table)
319770d7 1299 $params = array_merge(array('courseid'=>$this->courseid), $rolesparams, $groupwheresqlparams);
883187d0 1300 $SQL = "SELECT gi.id, COUNT(u.id) AS count
d24832f9 1301 FROM {grade_items} gi
1302 CROSS JOIN {user} u
1303 JOIN {role_assignments} ra ON ra.userid = u.id
1304 LEFT OUTER JOIN {grade_grades} g ON (g.itemid = gi.id AND g.userid = u.id AND g.finalgrade IS NOT NULL)
828af11c 1305 $groupsql
b50371da 1306 WHERE gi.courseid = :courseid
d24832f9 1307 AND ra.roleid $usql
828af11c 1308 AND ra.contextid ".get_related_contexts_string($this->context)."
1309 AND g.id IS NULL
1310 $groupwheresql
883187d0 1311 GROUP BY gi.id";
828af11c 1312
319770d7 1313 $ungradedcounts = $DB->get_records_sql($SQL, $params);
883187d0 1314
6c096a49 1315 $avgrow = new html_table_row();
16be8974 1316 $avgrow->attributes['class'] = 'avg';
653a8648 1317
b89a70ce 1318 foreach ($this->gtree->items as $itemid=>$unused) {
1319 $item =& $this->gtree->items[$itemid];
1320
67881aa8 1321 if ($item->needsupdate) {
6c096a49
NC
1322 $avgcell = new html_table_cell();
1323 $avgcell->text = $OUTPUT->container(get_string('error'), 'gradingerror');
1324 $avgrow->cells[] = $avgcell;
67881aa8 1325 continue;
1326 }
1327
319770d7 1328 if (!isset($sumarray[$item->id])) {
1329 $sumarray[$item->id] = 0;
33a34cd4 1330 }
883187d0 1331
319770d7 1332 if (empty($ungradedcounts[$itemid])) {
1333 $ungradedcount = 0;
828af11c 1334 } else {
319770d7 1335 $ungradedcount = $ungradedcounts[$itemid]->count;
d1556c09 1336 }
33a34cd4 1337
c2efb501 1338 if ($meanselection == GRADE_REPORT_MEAN_GRADED) {
319770d7 1339 $meancount = $totalcount - $ungradedcount;
33a34cd4 1340 } else { // Bump up the sum by the number of ungraded items * grademin
319770d7 1341 $sumarray[$item->id] += $ungradedcount * $item->grademin;
1342 $meancount = $totalcount;
33a34cd4 1343 }
1344
31a6c06c 1345 $decimalpoints = $item->get_decimals();
41f22daa 1346
bb384a8e 1347 // Determine which display type to use for this average
2cc773f5 1348 if ($USER->gradeediting[$this->courseid]) {
1796708d 1349 $displaytype = GRADE_DISPLAY_TYPE_REAL;
d622930b 1350
e0724506 1351 } else if ($averagesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) { // no ==0 here, please resave the report and user preferences
d622930b 1352 $displaytype = $item->get_displaytype();
1353
1354 } else {
bb384a8e 1355 $displaytype = $averagesdisplaytype;
1356 }
1357
31a6c06c 1358 // Override grade_item setting if a display preference (not inherit) was set for the averages
e0724506 1359 if ($averagesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) {
d622930b 1360 $decimalpoints = $item->get_decimals();
1361
1362 } else {
5b508a08 1363 $decimalpoints = $averagesdecimalpoints;
1364 }
1365
319770d7 1366 if (!isset($sumarray[$item->id]) || $meancount == 0) {
6c096a49
NC
1367 $avgcell = new html_table_cell();
1368 $avgcell->text = '-';
1369 $avgrow->cells[] = $avgcell;
1370
4ba9941c 1371 } else {
319770d7 1372 $sum = $sumarray[$item->id];
1373 $avgradeval = $sum/$meancount;
d622930b 1374 $gradehtml = grade_format_gradevalue($avgradeval, $item, true, $displaytype, $decimalpoints);
bb384a8e 1375
098042ba 1376 $numberofgrades = '';
098042ba 1377 if ($shownumberofgrades) {
319770d7 1378 $numberofgrades = " ($meancount)";
098042ba 1379 }
1380
6c096a49
NC
1381 $avgcell = new html_table_cell();
1382 $avgcell->text = $gradehtml.$numberofgrades;
1383 $avgrow->cells[] = $avgcell;
80fb1cf9 1384 }
9ecd4386 1385 }
6c096a49 1386 $rows[] = $avgrow;
9ecd4386 1387 }
6c096a49 1388 return $rows;
9ecd4386 1389 }
4ba9941c 1390
1391 /**
1392 * Given a grade_category, grade_item or grade_grade, this function
1393 * figures out the state of the object and builds then returns a div
1394 * with the icons needed for the grader report.
1395 *
1396 * @param object $object
4ba9941c 1397 * @return string HTML
1398 */
d24832f9 1399 protected function get_icons($element) {
319770d7 1400 global $CFG, $USER, $OUTPUT;
4ba9941c 1401
2cc773f5 1402 if (!$USER->gradeediting[$this->courseid]) {
1403 return '<div class="grade_icons" />';
79eabc2a 1404 }
4ba9941c 1405
2cc773f5 1406 // Init all icons
319770d7 1407 $editicon = '';
dc482cfa 1408
1409 if ($element['type'] != 'categoryitem' && $element['type'] != 'courseitem') {
319770d7 1410 $editicon = $this->gtree->get_edit_icon($element, $this->gpr);
dc482cfa 1411 }
1412
319770d7 1413 $editcalculationicon = '';
1414 $showhideicon = '';
1415 $lockunlockicon = '';
4ba9941c 1416
a5b8be62 1417 if (has_capability('moodle/grade:manage', $this->context)) {
4ba9941c 1418
a5b8be62 1419 if ($this->get_pref('showcalculations')) {
319770d7 1420 $editcalculationicon = $this->gtree->get_calculation_icon($element, $this->gpr);
a5b8be62 1421 }
1422
1423 if ($this->get_pref('showeyecons')) {
319770d7 1424 $showhideicon = $this->gtree->get_hiding_icon($element, $this->gpr);
a5b8be62 1425 }
4ba9941c 1426
a5b8be62 1427 if ($this->get_pref('showlocks')) {
319770d7 1428 $lockunlockicon = $this->gtree->get_locking_icon($element, $this->gpr);
a5b8be62 1429 }
4ba9941c 1430 }
1431
319770d7 1432 return $OUTPUT->container($editicon.$editcalculationicon.$showhideicon.$lockunlockicon, 'grade_icons');
4faf5f99 1433 }
1434
1435 /**
1436 * Given a category element returns collapsing +/- icon if available
1437 * @param object $object
1438 * @return string HTML
1439 */
d24832f9 1440 protected function get_collapsing_icon($element) {
5d3b9994 1441 global $OUTPUT;
4faf5f99 1442
319770d7 1443 $icon = '';
2cc773f5 1444 // If object is a category, display expand/contract icon
384960dd 1445 if ($element['type'] == 'category') {
2cc773f5 1446 // Load language strings
319770d7 1447 $strswitchminus = $this->get_lang_string('aggregatesonly', 'grades');
1448 $strswitchplus = $this->get_lang_string('gradesonly', 'grades');
1449 $strswitchwhole = $this->get_lang_string('fullmode', 'grades');
384960dd 1450
8ae8bf8a 1451 $url = new moodle_url($this->gpr->get_return_url(null, array('target'=>$element['eid'], 'sesskey'=>sesskey())));
48b5d8f3 1452
384960dd 1453 if (in_array($element['object']->id, $this->collapsed['aggregatesonly'])) {
8ae8bf8a 1454 $url->param('action', 'switch_plus');
c63923bd 1455 $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_plus', $strswitchplus));
8ae8bf8a
PS
1456
1457 } else if (in_array($element['object']->id, $this->collapsed['gradesonly'])) {
1458 $url->param('action', 'switch_whole');
c63923bd 1459 $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_whole', $strswitchwhole));
b5d0cafc 1460 $contractexpandicon->image->src = $OUTPUT->pix_url('t/switch_whole');
8ae8bf8a
PS
1461
1462 } else {
1463 $url->param('action', 'switch_minus');
c63923bd 1464 $icon = $OUTPUT->action_icon($url, new pix_icon('t/switch_minus', $strswitchminus));
2cc773f5 1465 }
4ba9941c 1466 }
319770d7 1467 return $icon;
4ba9941c 1468 }
48b5d8f3 1469
1470 /**
1471 * Processes a single action against a category, grade_item or grade.
1472 * @param string $target eid ({type}{id}, e.g. c4 for category4)
1473 * @param string $action Which action to take (edit, delete etc...)
1474 * @return
1475 */
d24832f9 1476 public function process_action($target, $action) {
4faf5f99 1477 // TODO: this code should be in some grade_tree static method
48b5d8f3 1478 $targettype = substr($target, 0, 1);
1479 $targetid = substr($target, 1);
4faf5f99 1480 // TODO: end
1481
1482 if ($collapsed = get_user_preferences('grade_report_grader_collapsed_categories')) {
1483 $collapsed = unserialize($collapsed);
1484 } else {
384960dd 1485 $collapsed = array('aggregatesonly' => array(), 'gradesonly' => array());
4faf5f99 1486 }
1487
48b5d8f3 1488 switch ($action) {
384960dd 1489 case 'switch_minus': // Add category to array of aggregatesonly
1490 if (!in_array($targetid, $collapsed['aggregatesonly'])) {
1491 $collapsed['aggregatesonly'][] = $targetid;
4faf5f99 1492 set_user_preference('grade_report_grader_collapsed_categories', serialize($collapsed));
1493 }
48b5d8f3 1494 break;
4faf5f99 1495
384960dd 1496 case 'switch_plus': // Remove category from array of aggregatesonly, and add it to array of gradesonly
1497 $key = array_search($targetid, $collapsed['aggregatesonly']);
4faf5f99 1498 if ($key !== false) {
384960dd 1499 unset($collapsed['aggregatesonly'][$key]);
4faf5f99 1500 }
384960dd 1501 if (!in_array($targetid, $collapsed['gradesonly'])) {
1502 $collapsed['gradesonly'][] = $targetid;
1503 }
1504 set_user_preference('grade_report_grader_collapsed_categories', serialize($collapsed));
48b5d8f3 1505 break;
384960dd 1506 case 'switch_whole': // Remove the category from the array of collapsed cats
1507 $key = array_search($targetid, $collapsed['gradesonly']);
1508 if ($key !== false) {
1509 unset($collapsed['gradesonly'][$key]);
1510 set_user_preference('grade_report_grader_collapsed_categories', serialize($collapsed));
1511 }
4faf5f99 1512
384960dd 1513 break;
48b5d8f3 1514 default:
1515 break;
1516 }
1517
1518 return true;
1519 }
03fcc729 1520
795b745a 1521 /**
1522 * Returns whether or not to display fixed students column.
1523 * Includes a browser check, because IE6 doesn't support the scrollbar.
1524 *
1525 * @return bool
1526 */
1527 public function is_fixed_students() {
1528 global $USER, $CFG;
03fcc729 1529 return empty($USER->screenreader) && $CFG->grade_report_fixedstudents &&
1530 (check_browser_version('MSIE', '7.0') ||
795b745a 1531 check_browser_version('Firefox', '2.0') ||
1532 check_browser_version('Gecko', '2006010100') ||
1533 check_browser_version('Camino', '1.0') ||
1534 check_browser_version('Opera', '6.0') ||
03fcc729 1535 check_browser_version('Safari', '2.0'));
795b745a 1536 }
6c096a49
NC
1537
1538 /**
1539 * Refactored function for generating HTML of sorting links with matching arrows.
1540 * Returns an array with 'studentname' and 'idnumber' as keys, with HTML ready
1541 * to inject into a table header cell.
1542 * @return array An associative array of HTML sorting links+arrows
1543 */
1544 public function get_sort_arrows() {
1545 global $OUTPUT;
1546 $arrows = array();
1547
1548 $strsortasc = $this->get_lang_string('sortasc', 'grades');
1549 $strsortdesc = $this->get_lang_string('sortdesc', 'grades');
1550 $strfirstname = $this->get_lang_string('firstname');
1551 $strlastname = $this->get_lang_string('lastname');
1552
0f4c64b7
PS
1553 $firstlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>'firstname')), $strfirstname);
1554 $lastlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>'lastname')), $strlastname);
1555 $idnumberlink = html_writer::link(new moodle_url($this->baseurl, array('sortitemid'=>'idnumber')), get_string('idnumber'));
6c096a49 1556
0f4c64b7 1557 $arrows['studentname'] = $lastlink;
6c096a49
NC
1558
1559 if ($this->sortitemid === 'lastname') {
1560 if ($this->sortorder == 'ASC') {
1561 $arrows['studentname'] .= print_arrow('up', $strsortasc, true);
1562 } else {
1563 $arrows['studentname'] .= print_arrow('down', $strsortdesc, true);
1564 }
1565 }
1566
0f4c64b7 1567 $arrows['studentname'] .= ' ' . $firstlink;
6c096a49
NC
1568
1569 if ($this->sortitemid === 'firstname') {
1570 if ($this->sortorder == 'ASC') {
1571 $arrows['studentname'] .= print_arrow('up', $strsortasc, true);
1572 } else {
1573 $arrows['studentname'] .= print_arrow('down', $strsortdesc, true);
1574 }
1575 }
1576
0f4c64b7 1577 $arrows['idnumber'] = $idnumberlink;
6c096a49
NC
1578
1579 if ('idnumber' == $this->sortitemid) {
1580 if ($this->sortorder == 'ASC') {
1581 $arrows['idnumber'] .= print_arrow('up', $strsortasc, true);
1582 } else {
1583 $arrows['idnumber'] .= print_arrow('down', $strsortdesc, true);
1584 }
1585 }
1586
1587 return $arrows;
1588 }
4ba9941c 1589}
6c3ef410 1590