07459730797532e46df862cfaef4b11fb06c7eb6
[moodle.git] / mod / assign / gradingtable.php
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/>.
17 /**
18  * This file contains the definition for the grading table which subclassses easy_table
19  *
20  * @package   mod_assign
21  * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->libdir.'/tablelib.php');
28 require_once($CFG->libdir.'/gradelib.php');
29 require_once($CFG->dirroot.'/mod/assign/locallib.php');
31 /**
32  * Extends table_sql to provide a table of assignment submissions
33  *
34  * @package   mod_assign
35  * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
36  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37  */
38 class assign_grading_table extends table_sql implements renderable {
39     /** @var assign $assignment */
40     private $assignment = null;
41     /** @var int $perpage */
42     private $perpage = 10;
43     /** @var int $rownum (global index of current row in table) */
44     private $rownum = -1;
45     /** @var renderer_base for getting output */
46     private $output = null;
47     /** @var stdClass gradinginfo */
48     private $gradinginfo = null;
49     /** @var int $tablemaxrows */
50     private $tablemaxrows = 10000;
51     /** @var boolean $quickgrading */
52     private $quickgrading = false;
53     /** @var boolean $hasgrantextension - Only do the capability check once for the entire table */
54     private $hasgrantextension = false;
55     /** @var boolean $hasgrade - Only do the capability check once for the entire table */
56     private $hasgrade = false;
57     /** @var array $groupsubmissions - A static cache of group submissions */
58     private $groupsubmissions = array();
59     /** @var array $submissiongroups - A static cache of submission groups */
60     private $submissiongroups = array();
61     /** @var string $plugingradingbatchoperations - List of plugin supported batch operations */
62     public $plugingradingbatchoperations = array();
63     /** @var array $plugincache - A cache of plugin lookups to match a column name to a plugin efficiently */
64     private $plugincache = array();
65     /** @var array $scale - A list of the keys and descriptions for the custom scale */
66     private $scale = null;
68     /**
69      * overridden constructor keeps a reference to the assignment class that is displaying this table
70      *
71      * @param assign $assignment The assignment class
72      * @param int $perpage how many per page
73      * @param string $filter The current filter
74      * @param int $rowoffset For showing a subsequent page of results
75      * @param bool $quickgrading Is this table wrapped in a quickgrading form?
76      * @param string $downloadfilename
77      */
78     public function __construct(assign $assignment,
79                                 $perpage,
80                                 $filter,
81                                 $rowoffset,
82                                 $quickgrading,
83                                 $downloadfilename = null) {
84         global $CFG, $PAGE, $DB, $USER;
85         parent::__construct('mod_assign_grading');
86         $this->assignment = $assignment;
88         // Check permissions up front.
89         $this->hasgrantextension = has_capability('mod/assign:grantextension',
90                                                   $this->assignment->get_context());
91         $this->hasgrade = $this->assignment->can_grade();
93         // Check if we have the elevated view capablities to see the blind details.
94         $this->hasviewblind = has_capability('mod/assign:viewblinddetails',
95                 $this->assignment->get_context());
97         foreach ($assignment->get_feedback_plugins() as $plugin) {
98             if ($plugin->is_visible() && $plugin->is_enabled()) {
99                 foreach ($plugin->get_grading_batch_operations() as $action => $description) {
100                     if (empty($this->plugingradingbatchoperations)) {
101                         $this->plugingradingbatchoperations[$plugin->get_type()] = array();
102                     }
103                     $this->plugingradingbatchoperations[$plugin->get_type()][$action] = $description;
104                 }
105             }
106         }
107         $this->perpage = $perpage;
108         $this->quickgrading = $quickgrading && $this->hasgrade;
109         $this->output = $PAGE->get_renderer('mod_assign');
111         $urlparams = array('action'=>'grading', 'id'=>$assignment->get_course_module()->id);
112         $url = new moodle_url($CFG->wwwroot . '/mod/assign/view.php', $urlparams);
113         $this->define_baseurl($url);
115         // Do some business - then set the sql.
116         $currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
118         if ($rowoffset) {
119             $this->rownum = $rowoffset - 1;
120         }
122         $users = array_keys( $assignment->list_participants($currentgroup, true));
123         if (count($users) == 0) {
124             // Insert a record that will never match to the sql is still valid.
125             $users[] = -1;
126         }
128         $params = array();
129         $params['assignmentid1'] = (int)$this->assignment->get_instance()->id;
130         $params['assignmentid2'] = (int)$this->assignment->get_instance()->id;
131         $params['assignmentid3'] = (int)$this->assignment->get_instance()->id;
133         $extrauserfields = get_extra_user_fields($this->assignment->get_context());
135         $fields = user_picture::fields('u', $extrauserfields) . ', ';
136         $fields .= 'u.id as userid, ';
137         $fields .= 's.status as status, ';
138         $fields .= 's.id as submissionid, ';
139         $fields .= 's.timecreated as firstsubmission, ';
140         $fields .= 's.timemodified as timesubmitted, ';
141         $fields .= 's.attemptnumber as attemptnumber, ';
142         $fields .= 'g.id as gradeid, ';
143         $fields .= 'g.grade as grade, ';
144         $fields .= 'g.timemodified as timemarked, ';
145         $fields .= 'g.timecreated as firstmarked, ';
146         $fields .= 'uf.mailed as mailed, ';
147         $fields .= 'uf.locked as locked, ';
148         $fields .= 'uf.extensionduedate as extensionduedate, ';
149         $fields .= 'uf.workflowstate as workflowstate, ';
150         $fields .= 'uf.allocatedmarker as allocatedmarker ';
152         $from = '{user} u
153                          LEFT JOIN {assign_submission} s ON
154                             u.id = s.userid AND
155                             s.assignment = :assignmentid1 AND
156                             s.latest = 1
157                          LEFT JOIN {assign_grades} g ON
158                             u.id = g.userid AND
159                             g.assignment = :assignmentid2 AND
160                             g.attemptnumber = s.attemptnumber
161                          LEFT JOIN {assign_user_flags} uf ON u.id = uf.userid AND uf.assignment = :assignmentid3';
163         $userparams = array();
164         $userindex = 0;
166         list($userwhere, $userparams) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED, 'user');
167         $where = 'u.id ' . $userwhere;
168         $params = array_merge($params, $userparams);
170         // The filters do not make sense when there are no submissions, so do not apply them.
171         if ($this->assignment->is_any_submission_plugin_enabled()) {
172             if ($filter == ASSIGN_FILTER_SUBMITTED) {
173                 $where .= ' AND (s.timemodified IS NOT NULL AND
174                                  s.status = :submitted) ';
175                 $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
177             } else if ($filter == ASSIGN_FILTER_NOT_SUBMITTED) {
178                 $where .= ' AND (s.timemodified IS NULL OR s.status != :submitted) ';
179                 $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
180             } else if ($filter == ASSIGN_FILTER_REQUIRE_GRADING) {
181                 $where .= ' AND (s.timemodified IS NOT NULL AND
182                                  s.status = :submitted AND
183                                  (s.timemodified > g.timemodified OR g.timemodified IS NULL))';
184                 $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
186             } else if (strpos($filter, ASSIGN_FILTER_SINGLE_USER) === 0) {
187                 $userfilter = (int) array_pop(explode('=', $filter));
188                 $where .= ' AND (u.id = :userid)';
189                 $params['userid'] = $userfilter;
190             }
191         }
193         if ($this->assignment->get_instance()->markingworkflow &&
194             $this->assignment->get_instance()->markingallocation) {
195             if (has_capability('mod/assign:manageallocations', $this->assignment->get_context())) {
196                 // Check to see if marker filter is set.
197                 $markerfilter = (int)get_user_preferences('assign_markerfilter', '');
198                 if (!empty($markerfilter)) {
199                     if ($markerfilter == ASSIGN_MARKER_FILTER_NO_MARKER) {
200                         $where .= ' AND (uf.allocatedmarker IS NULL OR uf.allocatedmarker = 0)';
201                     } else {
202                         $where .= ' AND uf.allocatedmarker = :markerid';
203                         $params['markerid'] = $markerfilter;
204                     }
205                 }
206             } else { // Only show users allocated to this marker.
207                 $where .= ' AND uf.allocatedmarker = :markerid';
208                 $params['markerid'] = $USER->id;
209             }
210         }
212         if ($this->assignment->get_instance()->markingworkflow) {
213             $workflowstates = $this->assignment->get_marking_workflow_states_for_current_user();
214             if (!empty($workflowstates)) {
215                 $workflowfilter = get_user_preferences('assign_workflowfilter', '');
216                 if ($workflowfilter == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED) {
217                     $where .= ' AND (uf.workflowstate = :workflowstate OR uf.workflowstate IS NULL OR '.
218                         $DB->sql_isempty('assign_user_flags', 'workflowstate', true, true).')';
219                     $params['workflowstate'] = $workflowfilter;
220                 } else if (array_key_exists($workflowfilter, $workflowstates)) {
221                     $where .= ' AND uf.workflowstate = :workflowstate';
222                     $params['workflowstate'] = $workflowfilter;
223                 }
224             }
225         }
227         $this->set_sql($fields, $from, $where, $params);
229         if ($downloadfilename) {
230             $this->is_downloading('csv', $downloadfilename);
231         }
233         $columns = array();
234         $headers = array();
236         // Select.
237         if (!$this->is_downloading() && $this->hasgrade) {
238             $columns[] = 'select';
239             $headers[] = get_string('select') .
240                     '<div class="selectall"><label class="accesshide" for="selectall">' . get_string('selectall') . '</label>
241                     <input type="checkbox" id="selectall" name="selectall" title="' . get_string('selectall') . '"/></div>';
242         }
244         // User picture.
245         if ($this->hasviewblind || !$this->assignment->is_blind_marking()) {
246             if (!$this->is_downloading()) {
247                 $columns[] = 'picture';
248                 $headers[] = get_string('pictureofuser');
249             } else {
250                 $columns[] = 'recordid';
251                 $headers[] = get_string('recordid', 'assign');
252             }
254             // Fullname.
255             $columns[] = 'fullname';
256             $headers[] = get_string('fullname');
258             foreach ($extrauserfields as $extrafield) {
259                 $columns[] = $extrafield;
260                 $headers[] = get_user_field_name($extrafield);
261             }
262         } else {
263             // Record ID.
264             $columns[] = 'recordid';
265             $headers[] = get_string('recordid', 'assign');
266         }
268         if ($this->hasviewblind) {
269                 $columns[] = 'recordid';
270                 $headers[] = get_string('recordid', 'assign');
271         }
273         // Submission status.
274         if ($assignment->is_any_submission_plugin_enabled()) {
275             $columns[] = 'status';
276             $headers[] = get_string('status', 'assign');
277         } else if ($this->assignment->get_instance()->markingworkflow) {
278             $columns[] = 'workflowstatus';
279             $headers[] = get_string('status', 'assign');
280         }
282         // Team submission columns.
283         if ($assignment->get_instance()->teamsubmission) {
284             $columns[] = 'team';
285             $headers[] = get_string('submissionteam', 'assign');
286         }
287         // Allocated marker.
288         if ($this->assignment->get_instance()->markingworkflow &&
289             $this->assignment->get_instance()->markingallocation &&
290             has_capability('mod/assign:manageallocations', $this->assignment->get_context())) {
291             // Add a column for the allocated marker.
292             $columns[] = 'allocatedmarker';
293             $headers[] = get_string('marker', 'assign');
294         }
295         // Grade.
296         $columns[] = 'grade';
297         $headers[] = get_string('grade');
298         if ($this->is_downloading()) {
299             if ($this->assignment->get_instance()->grade >= 0) {
300                 $columns[] = 'grademax';
301                 $headers[] = get_string('maxgrade', 'assign');
302             } else {
303                 // This is a custom scale.
304                 $columns[] = 'scale';
305                 $headers[] = get_string('scale', 'assign');
306             }
308             if ($this->assignment->get_instance()->markingworkflow) {
309                 // Add a column for the marking workflow state.
310                 $columns[] = 'workflowstate';
311                 $headers[] = get_string('markingworkflowstate', 'assign');
312             }
313             // Add a column for the list of valid marking workflow states.
314             $columns[] = 'gradecanbechanged';
315             $headers[] = get_string('gradecanbechanged', 'assign');
316         }
317         if (!$this->is_downloading() && $this->hasgrade) {
318             // We have to call this column userid so we can use userid as a default sortable column.
319             $columns[] = 'userid';
320             $headers[] = get_string('edit');
321         }
323         // Submission plugins.
324         if ($assignment->is_any_submission_plugin_enabled()) {
325             $columns[] = 'timesubmitted';
326             $headers[] = get_string('lastmodifiedsubmission', 'assign');
328             foreach ($this->assignment->get_submission_plugins() as $plugin) {
329                 if ($this->is_downloading()) {
330                     if ($plugin->is_visible() && $plugin->is_enabled()) {
331                         foreach ($plugin->get_editor_fields() as $field => $description) {
332                             $index = 'plugin' . count($this->plugincache);
333                             $this->plugincache[$index] = array($plugin, $field);
334                             $columns[] = $index;
335                             $headers[] = $plugin->get_name();
336                         }
337                     }
338                 } else {
339                     if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
340                         $index = 'plugin' . count($this->plugincache);
341                         $this->plugincache[$index] = array($plugin);
342                         $columns[] = $index;
343                         $headers[] = $plugin->get_name();
344                     }
345                 }
346             }
347         }
349         // Time marked.
350         $columns[] = 'timemarked';
351         $headers[] = get_string('lastmodifiedgrade', 'assign');
353         // Feedback plugins.
354         foreach ($this->assignment->get_feedback_plugins() as $plugin) {
355             if ($this->is_downloading()) {
356                 if ($plugin->is_visible() && $plugin->is_enabled()) {
357                     foreach ($plugin->get_editor_fields() as $field => $description) {
358                         $index = 'plugin' . count($this->plugincache);
359                         $this->plugincache[$index] = array($plugin, $field);
360                         $columns[] = $index;
361                         $headers[] = $description;
362                     }
363                 }
364             } else if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
365                 $index = 'plugin' . count($this->plugincache);
366                 $this->plugincache[$index] = array($plugin);
367                 $columns[] = $index;
368                 $headers[] = $plugin->get_name();
369             }
370         }
372         // Exclude 'Final grade' column in downloaded grading worksheets.
373         if (!$this->is_downloading()) {
374             // Final grade.
375             $columns[] = 'finalgrade';
376             $headers[] = get_string('finalgrade', 'grades');
377         }
379         // Load the grading info for all users.
380         $this->gradinginfo = grade_get_grades($this->assignment->get_course()->id,
381                                               'mod',
382                                               'assign',
383                                               $this->assignment->get_instance()->id,
384                                               $users);
386         if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) {
387             $columns[] = 'outcomes';
388             $headers[] = get_string('outcomes', 'grades');
389         }
391         // Set the columns.
392         $this->define_columns($columns);
393         $this->define_headers($headers);
394         foreach ($extrauserfields as $extrafield) {
395              $this->column_class($extrafield, $extrafield);
396         }
397         // We require at least one unique column for the sort.
398         $this->sortable(true, 'userid');
399         $this->no_sorting('recordid');
400         $this->no_sorting('finalgrade');
401         $this->no_sorting('userid');
402         $this->no_sorting('select');
403         $this->no_sorting('outcomes');
405         if ($assignment->get_instance()->teamsubmission) {
406             $this->no_sorting('team');
407         }
409         $plugincolumnindex = 0;
410         foreach ($this->assignment->get_submission_plugins() as $plugin) {
411             if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
412                 $submissionpluginindex = 'plugin' . $plugincolumnindex++;
413                 $this->no_sorting($submissionpluginindex);
414             }
415         }
416         foreach ($this->assignment->get_feedback_plugins() as $plugin) {
417             if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
418                 $feedbackpluginindex = 'plugin' . $plugincolumnindex++;
419                 $this->no_sorting($feedbackpluginindex);
420             }
421         }
423         // When there is no data we still want the column headers printed in the csv file.
424         if ($this->is_downloading()) {
425             $this->start_output();
426         }
427     }
429     /**
430      * Before adding each row to the table make sure rownum is incremented.
431      *
432      * @param array $row row of data from db used to make one row of the table.
433      * @return array one row for the table
434      */
435     public function format_row($row) {
436         if ($this->rownum < 0) {
437             $this->rownum = $this->currpage * $this->pagesize;
438         } else {
439             $this->rownum += 1;
440         }
442         return parent::format_row($row);
443     }
445     /**
446      * Add a column with an ID that uniquely identifies this user in this assignment.
447      *
448      * @param stdClass $row
449      * @return string
450      */
451     public function col_recordid(stdClass $row) {
452         return get_string('hiddenuser', 'assign') .
453                $this->assignment->get_uniqueid_for_user($row->userid);
454     }
457     /**
458      * Add the userid to the row class so it can be updated via ajax.
459      *
460      * @param stdClass $row The row of data
461      * @return string The row class
462      */
463     public function get_row_class($row) {
464         return 'user' . $row->userid;
465     }
467     /**
468      * Return the number of rows to display on a single page.
469      *
470      * @return int The number of rows per page
471      */
472     public function get_rows_per_page() {
473         return $this->perpage;
474     }
476     /**
477      * list current marking workflow state
478      *
479      * @param stdClass $row
480      * @return string
481      */
482     public function col_workflowstatus(stdClass $row) {
483         $o = '';
485         $gradingdisabled = $this->assignment->grading_disabled($row->id);
486         // The function in the assignment keeps a static cache of this list of states.
487         $workflowstates = $this->assignment->get_marking_workflow_states_for_current_user();
488         $workflowstate = $row->workflowstate;
489         if (empty($workflowstate)) {
490             $workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED;
491         }
492         if ($this->quickgrading && !$gradingdisabled) {
493             $notmarked = get_string('markingworkflowstatenotmarked', 'assign');
494             $name = 'quickgrade_' . $row->id . '_workflowstate';
495             $o .= html_writer::select($workflowstates, $name, $workflowstate, array('' => $notmarked));
496             // Check if this user is a marker that can't manage allocations and doesn't have the marker column added.
497             if ($this->assignment->get_instance()->markingworkflow &&
498                 $this->assignment->get_instance()->markingallocation &&
499                 !has_capability('mod/assign:manageallocations', $this->assignment->get_context())) {
501                 $name = 'quickgrade_' . $row->id . '_allocatedmarker';
502                 $o .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name,
503                         'value' => $row->allocatedmarker));
504             }
505         } else {
506             $o .= $this->output->container(get_string('markingworkflowstate' . $workflowstate, 'assign'), $workflowstate);
507         }
508         return $o;
509     }
511     /**
512      * For download only - list current marking workflow state
513      *
514      * @param stdClass $row - The row of data
515      * @return string The current marking workflow state
516      */
517     public function col_workflowstate($row) {
518         $state = $row->workflowstate;
519         if (empty($state)) {
520             $state = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED;
521         }
523         return get_string('markingworkflowstate' . $state, 'assign');
524     }
526     /**
527      * list current marker
528      *
529      * @param stdClass $row - The row of data
530      * @return id the user->id of the marker.
531      */
532     public function col_allocatedmarker(stdClass $row) {
533         static $markers = null;
534         static $markerlist = array();
535         if ($markers === null) {
536             $markers = get_users_by_capability($this->assignment->get_context(), 'mod/assign:grade');
537             $markerlist[0] = get_string('choosemarker', 'assign');
538             foreach ($markers as $marker) {
539                 $markerlist[$marker->id] = fullname($marker);
540             }
541         }
542         if (empty($markerlist)) {
543             // TODO: add some form of notification here that no markers are available.
544             return '';
545         }
546         if ($this->is_downloading()) {
547             if (isset($markers[$row->allocatedmarker])) {
548                 return fullname($markers[$row->allocatedmarker]);
549             } else {
550                 return '';
551             }
552         }
554         if ($this->quickgrading && has_capability('mod/assign:manageallocations', $this->assignment->get_context()) &&
555             (empty($row->workflowstate) ||
556              $row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INMARKING ||
557              $row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED)) {
559             $name = 'quickgrade_' . $row->id . '_allocatedmarker';
560             return  html_writer::select($markerlist, $name, $row->allocatedmarker, false);
561         } else if (!empty($row->allocatedmarker)) {
562             $output = '';
563             if ($this->quickgrading) { // Add hidden field for quickgrading page.
564                 $name = 'quickgrade_' . $row->id . '_allocatedmarker';
565                 $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$name, 'value'=>$row->allocatedmarker));
566             }
567             $output .= $markerlist[$row->allocatedmarker];
568             return $output;
569         }
570     }
571     /**
572      * For download only - list all the valid options for this custom scale.
573      *
574      * @param stdClass $row - The row of data
575      * @return string A list of valid options for the current scale
576      */
577     public function col_scale($row) {
578         global $DB;
580         if (empty($this->scale)) {
581             $dbparams = array('id'=>-($this->assignment->get_instance()->grade));
582             $this->scale = $DB->get_record('scale', $dbparams);
583         }
585         if (!empty($this->scale->scale)) {
586             return implode("\n", explode(',', $this->scale->scale));
587         }
588         return '';
589     }
591     /**
592      * Display a grade with scales etc.
593      *
594      * @param string $grade
595      * @param boolean $editable
596      * @param int $userid The user id of the user this grade belongs to
597      * @param int $modified Timestamp showing when the grade was last modified
598      * @return string The formatted grade
599      */
600     public function display_grade($grade, $editable, $userid, $modified) {
601         if ($this->is_downloading()) {
602             if ($this->assignment->get_instance()->grade >= 0) {
603                 if ($grade == -1 || $grade === null) {
604                     return '';
605                 }
606                 return format_float($grade, 2);
607             } else {
608                 // This is a custom scale.
609                 $scale = $this->assignment->display_grade($grade, false);
610                 if ($scale == '-') {
611                     $scale = '';
612                 }
613                 return $scale;
614             }
615         }
616         return $this->assignment->display_grade($grade, $editable, $userid, $modified);
617     }
619     /**
620      * Get the team info for this user.
621      *
622      * @param stdClass $row
623      * @return string The team name
624      */
625     public function col_team(stdClass $row) {
626         $submission = false;
627         $group = false;
628         $this->get_group_and_submission($row->id, $group, $submission, -1);
629         if ($group) {
630             return $group->name;
631         }
632         return get_string('defaultteam', 'assign');
633     }
635     /**
636      * Use a static cache to try and reduce DB calls.
637      *
638      * @param int $userid The user id for this submission
639      * @param int $group The groupid (returned)
640      * @param stdClass|false $submission The stdClass submission or false (returned)
641      * @param int $attemptnumber Return a specific attempt number (-1 for latest)
642      */
643     protected function get_group_and_submission($userid, &$group, &$submission, $attemptnumber) {
644         $group = false;
645         if (isset($this->submissiongroups[$userid])) {
646             $group = $this->submissiongroups[$userid];
647         } else {
648             $group = $this->assignment->get_submission_group($userid, false);
649             $this->submissiongroups[$userid] = $group;
650         }
652         $groupid = 0;
653         if ($group) {
654             $groupid = $group->id;
655         }
657         // Static cache is keyed by groupid and attemptnumber.
658         // We may need both the latest and previous attempt in the same page.
659         if (isset($this->groupsubmissions[$groupid . ':' . $attemptnumber])) {
660             $submission = $this->groupsubmissions[$groupid . ':' . $attemptnumber];
661         } else {
662             $submission = $this->assignment->get_group_submission($userid, $groupid, false, $attemptnumber);
663             $this->groupsubmissions[$groupid . ':' . $attemptnumber] = $submission;
664         }
665     }
667     /**
668      * Format a list of outcomes.
669      *
670      * @param stdClass $row
671      * @return string
672      */
673     public function col_outcomes(stdClass $row) {
674         $outcomes = '';
675         foreach ($this->gradinginfo->outcomes as $index => $outcome) {
676             $options = make_grades_menu(-$outcome->scaleid);
678             $options[0] = get_string('nooutcome', 'grades');
679             if ($this->quickgrading && !($outcome->grades[$row->userid]->locked)) {
680                 $select = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
681                 foreach ($options as $optionindex => $optionvalue) {
682                     $selected = '';
683                     if ($outcome->grades[$row->userid]->grade == $optionindex) {
684                         $selected = 'selected="selected"';
685                     }
686                     $select .= '<option value="' . $optionindex . '"' . $selected . '>' . $optionvalue . '</option>';
687                 }
688                 $select .= '</select>';
689                 $outcomes .= $this->output->container($outcome->name . ': ' . $select, 'outcome');
690             } else {
691                 $name = $outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade];
692                 if ($this->is_downloading()) {
693                     $outcomes .= $name;
694                 } else {
695                     $outcomes .= $this->output->container($name, 'outcome');
696                 }
697             }
698         }
700         return $outcomes;
701     }
704     /**
705      * Format a user picture for display.
706      *
707      * @param stdClass $row
708      * @return string
709      */
710     public function col_picture(stdClass $row) {
711         if ($row->picture) {
712             return $this->output->user_picture($row);
713         }
714         return '';
715     }
717     /**
718      * Format a user record for display (link to profile).
719      *
720      * @param stdClass $row
721      * @return string
722      */
723     public function col_fullname($row) {
724         if (!$this->is_downloading()) {
725             $courseid = $this->assignment->get_course()->id;
726             $link= new moodle_url('/user/view.php', array('id' =>$row->id, 'course'=>$courseid));
727             $fullname = $this->output->action_link($link, $this->assignment->fullname($row));
728         } else {
729             $fullname = $this->assignment->fullname($row);
730         }
732         if (!$this->assignment->is_active_user($row->id)) {
733             $suspendedstring = get_string('userenrolmentsuspended', 'grades');
734             $fullname .= ' ' . html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/enrolmentsuspended'),
735                 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
736             $fullname = html_writer::tag('span', $fullname, array('class' => 'usersuspended'));
737         }
738         return $fullname;
739     }
741     /**
742      * Insert a checkbox for selecting the current row for batch operations.
743      *
744      * @param stdClass $row
745      * @return string
746      */
747     public function col_select(stdClass $row) {
748         $selectcol = '<label class="accesshide" for="selectuser_' . $row->userid . '">';
749         $selectcol .= get_string('selectuser', 'assign', $this->assignment->fullname($row));
750         $selectcol .= '</label>';
751         $selectcol .= '<input type="checkbox"
752                               id="selectuser_' . $row->userid . '"
753                               name="selectedusers"
754                               value="' . $row->userid . '"/>';
755         $selectcol .= '<input type="hidden"
756                               name="grademodified_' . $row->userid . '"
757                               value="' . $row->timemarked . '"/>';
758         return $selectcol;
759     }
761     /**
762      * Return a users grades from the listing of all grade data for this assignment.
763      *
764      * @param int $userid
765      * @return mixed stdClass or false
766      */
767     private function get_gradebook_data_for_user($userid) {
768         if (isset($this->gradinginfo->items[0]) && $this->gradinginfo->items[0]->grades[$userid]) {
769             return $this->gradinginfo->items[0]->grades[$userid];
770         }
771         return false;
772     }
774     /**
775      * Format a column of data for display.
776      *
777      * @param stdClass $row
778      * @return string
779      */
780     public function col_gradecanbechanged(stdClass $row) {
781         $gradingdisabled = $this->assignment->grading_disabled($row->id);
782         if ($gradingdisabled) {
783             return get_string('no');
784         } else {
785             return get_string('yes');
786         }
787     }
789     /**
790      * Format a column of data for display
791      *
792      * @param stdClass $row
793      * @return string
794      */
795     public function col_grademax(stdClass $row) {
796         return format_float($this->assignment->get_instance()->grade, 2);
797     }
799     /**
800      * Format a column of data for display.
801      *
802      * @param stdClass $row
803      * @return string
804      */
805     public function col_grade(stdClass $row) {
806         $o = '';
808         $link = '';
809         $separator = $this->output->spacer(array(), true);
810         $grade = '';
811         $gradingdisabled = $this->assignment->grading_disabled($row->id);
813         if (!$this->is_downloading() && $this->hasgrade) {
814             $name = $this->assignment->fullname($row);
815             $icon = $this->output->pix_icon('gradefeedback',
816                                             get_string('gradeuser', 'assign', $name),
817                                             'mod_assign');
818             $urlparams = array('id' => $this->assignment->get_course_module()->id,
819                                'rownum'=>$this->rownum,
820                                'action'=>'grade');
821             $url = new moodle_url('/mod/assign/view.php', $urlparams);
822             $link = $this->output->action_link($url, $icon);
823             $grade .= $link . $separator;
824         }
826         $grade .= $this->display_grade($row->grade,
827                                        $this->quickgrading && !$gradingdisabled,
828                                        $row->userid,
829                                        $row->timemarked);
831         return $grade;
832     }
834     /**
835      * Format a column of data for display.
836      *
837      * @param stdClass $row
838      * @return string
839      */
840     public function col_finalgrade(stdClass $row) {
841         $o = '';
843         $grade = $this->get_gradebook_data_for_user($row->userid);
844         if ($grade) {
845             $o = $this->display_grade($grade->grade, false, $row->userid, $row->timemarked);
846         }
848         return $o;
849     }
851     /**
852      * Format a column of data for display.
853      *
854      * @param stdClass $row
855      * @return string
856      */
857     public function col_timemarked(stdClass $row) {
858         $o = '-';
860         if ($row->timemarked && $row->grade !== null && $row->grade >= 0) {
861             $o = userdate($row->timemarked);
862         }
863         if ($row->timemarked && $this->is_downloading()) {
864             // Force it for downloads as it affects import.
865             $o = userdate($row->timemarked);
866         }
868         return $o;
869     }
871     /**
872      * Format a column of data for display.
873      *
874      * @param stdClass $row
875      * @return string
876      */
877     public function col_timesubmitted(stdClass $row) {
878         $o = '-';
880         $group = false;
881         $submission = false;
882         $this->get_group_and_submission($row->id, $group, $submission, -1);
883         if ($group && $submission && $submission->timemodified) {
884             $o = userdate($submission->timemodified);
885         } else if ($row->timesubmitted) {
886             $o = userdate($row->timesubmitted);
887         }
889         return $o;
890     }
892     /**
893      * Format a column of data for display
894      *
895      * @param stdClass $row
896      * @return string
897      */
898     public function col_status(stdClass $row) {
899         $o = '';
901         $instance = $this->assignment->get_instance();
903         $due = $instance->duedate;
904         if ($row->extensionduedate) {
905             $due = $row->extensionduedate;
906         }
908         $group = false;
909         $submission = false;
910         $this->get_group_and_submission($row->id, $group, $submission, -1);
911         if ($group && $submission) {
912             $timesubmitted = $submission->timemodified;
913             $status = $submission->status;
914         } else {
915             $timesubmitted = $row->timesubmitted;
916             $status = $row->status;
917         }
919         if ($this->assignment->is_any_submission_plugin_enabled()) {
921             $o .= $this->output->container(get_string('submissionstatus_' . $status, 'assign'),
922                                            array('class'=>'submissionstatus' .$status));
923             if ($due && $timesubmitted > $due) {
924                 $usertime = format_time($timesubmitted - $due);
925                 $latemessage = get_string('submittedlateshort',
926                                           'assign',
927                                           $usertime);
928                 $o .= $this->output->container($latemessage, 'latesubmission');
929             }
930             if ($row->locked) {
931                 $lockedstr = get_string('submissionslockedshort', 'assign');
932                 $o .= $this->output->container($lockedstr, 'lockedsubmission');
933             }
935             // Add status of "grading", use markflow if enabled.
936             if ($instance->markingworkflow) {
937                 $o .= $this->col_workflowstatus($row);
938             } else if ($row->grade !== null && $row->grade >= 0) {
939                 $o .= $this->output->container(get_string('graded', 'assign'), 'submissiongraded');
940             } else if (!$timesubmitted) {
941                 $now = time();
942                 if ($due && ($now > $due)) {
943                     $overduestr = get_string('overdue', 'assign', format_time($now - $due));
944                     $o .= $this->output->container($overduestr, 'overduesubmission');
945                 }
946             }
948             if ($row->extensionduedate) {
949                 $userdate = userdate($row->extensionduedate);
950                 $extensionstr = get_string('userextensiondate', 'assign', $userdate);
951                 $o .= $this->output->container($extensionstr, 'extensiondate');
952             }
953         }
955         if ($this->is_downloading()) {
956             $o = strip_tags(str_replace('</div>', "\n", $o));
957         }
959         return $o;
960     }
962     /**
963      * Format a column of data for display.
964      *
965      * @param stdClass $row
966      * @return string
967      */
968     public function col_userid(stdClass $row) {
969         global $USER;
971         $edit = '';
973         $actions = array();
975         $urlparams = array('id'=>$this->assignment->get_course_module()->id,
976                            'rownum'=>$this->rownum,
977                            'action'=>'grade');
978         $url = new moodle_url('/mod/assign/view.php', $urlparams);
979         $noimage = null;
981         if (!$row->grade) {
982             $description = get_string('grade');
983         } else {
984             $description = get_string('updategrade', 'assign');
985         }
986         $actions['grade'] = new action_menu_link_secondary(
987             $url,
988             $noimage,
989             $description
990         );
992         // Everything we need is in the row.
993         $submission = $row;
994         $flags = $row;
995         if ($this->assignment->get_instance()->teamsubmission) {
996             // Use the cache for this.
997             $submission = false;
998             $group = false;
999             $this->get_group_and_submission($row->id, $group, $submission, -1);
1000         }
1002         $submissionsopen = $this->assignment->submissions_open($row->id,
1003                                                                true,
1004                                                                $submission,
1005                                                                $flags,
1006                                                                $this->gradinginfo);
1007         $caneditsubmission = $this->assignment->can_edit_submission($row->id, $USER->id);
1009         // Hide for offline assignments.
1010         if ($this->assignment->is_any_submission_plugin_enabled()) {
1011             if (!$row->status ||
1012                     $row->status == ASSIGN_SUBMISSION_STATUS_DRAFT ||
1013                     !$this->assignment->get_instance()->submissiondrafts) {
1015                 if (!$row->locked) {
1016                     $urlparams = array('id' => $this->assignment->get_course_module()->id,
1017                                        'userid'=>$row->id,
1018                                        'action'=>'lock',
1019                                        'sesskey'=>sesskey(),
1020                                        'page'=>$this->currpage);
1021                     $url = new moodle_url('/mod/assign/view.php', $urlparams);
1023                     $description = get_string('preventsubmissionsshort', 'assign');
1024                     $actions['lock'] = new action_menu_link_secondary(
1025                         $url,
1026                         $noimage,
1027                         $description
1028                     );
1029                 } else {
1030                     $urlparams = array('id' => $this->assignment->get_course_module()->id,
1031                                        'userid'=>$row->id,
1032                                        'action'=>'unlock',
1033                                        'sesskey'=>sesskey(),
1034                                        'page'=>$this->currpage);
1035                     $url = new moodle_url('/mod/assign/view.php', $urlparams);
1036                     $description = get_string('allowsubmissionsshort', 'assign');
1037                     $actions['unlock'] = new action_menu_link_secondary(
1038                         $url,
1039                         $noimage,
1040                         $description
1041                     );
1042                 }
1043             }
1045             if (($this->assignment->get_instance()->duedate ||
1046                    $this->assignment->get_instance()->cutoffdate) &&
1047                    $this->hasgrantextension) {
1048                 $urlparams = array('id' => $this->assignment->get_course_module()->id,
1049                                    'userid'=>$row->id,
1050                                    'action'=>'grantextension',
1051                                    'sesskey'=>sesskey(),
1052                                    'page'=>$this->currpage);
1053                 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1054                 $description = get_string('grantextension', 'assign');
1055                 $actions['grantextension'] = new action_menu_link_secondary(
1056                     $url,
1057                     $noimage,
1058                     $description
1059                 );
1060             }
1061             if ($submissionsopen &&
1062                     $USER->id != $row->id &&
1063                     $caneditsubmission) {
1064                 $urlparams = array('id' => $this->assignment->get_course_module()->id,
1065                                    'userid'=>$row->id,
1066                                    'action'=>'editsubmission',
1067                                    'sesskey'=>sesskey(),
1068                                    'page'=>$this->currpage);
1069                 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1070                 $description = get_string('editsubmission', 'assign');
1071                 $actions['editsubmission'] = new action_menu_link_secondary(
1072                     $url,
1073                     $noimage,
1074                     $description
1075                 );
1076             }
1077         }
1078         if ($row->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED &&
1079                 $this->assignment->get_instance()->submissiondrafts) {
1080             $urlparams = array('id' => $this->assignment->get_course_module()->id,
1081                                'userid'=>$row->id,
1082                                'action'=>'reverttodraft',
1083                                'sesskey'=>sesskey(),
1084                                'page'=>$this->currpage);
1085             $url = new moodle_url('/mod/assign/view.php', $urlparams);
1086             $description = get_string('reverttodraftshort', 'assign');
1087             $actions['reverttodraft'] = new action_menu_link_secondary(
1088                 $url,
1089                 $noimage,
1090                 $description
1091             );
1092         }
1093         if ($row->status == ASSIGN_SUBMISSION_STATUS_DRAFT &&
1094                 $this->assignment->get_instance()->submissiondrafts &&
1095                 $caneditsubmission &&
1096                 $submissionsopen &&
1097                 $row->id != $USER->id) {
1098             $urlparams = array('id' => $this->assignment->get_course_module()->id,
1099                                'userid'=>$row->id,
1100                                'action'=>'submitotherforgrading',
1101                                'sesskey'=>sesskey(),
1102                                'page'=>$this->currpage);
1103             $url = new moodle_url('/mod/assign/view.php', $urlparams);
1104             $description = get_string('submitforgrading', 'assign');
1105             $actions['submitforgrading'] = new action_menu_link_secondary(
1106                 $url,
1107                 $noimage,
1108                 $description
1109             );
1110         }
1112         $ismanual = $this->assignment->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL;
1113         $hassubmission = !empty($row->status);
1114         $notreopened = $hassubmission && $row->status != ASSIGN_SUBMISSION_STATUS_REOPENED;
1115         $isunlimited = $this->assignment->get_instance()->maxattempts == ASSIGN_UNLIMITED_ATTEMPTS;
1116         $hasattempts = $isunlimited || $row->attemptnumber < $this->assignment->get_instance()->maxattempts - 1;
1118         if ($ismanual && $hassubmission && $notreopened && $hasattempts) {
1119             $urlparams = array('id' => $this->assignment->get_course_module()->id,
1120                                'userid'=>$row->id,
1121                                'action'=>'addattempt',
1122                                'sesskey'=>sesskey(),
1123                                'page'=>$this->currpage);
1124             $url = new moodle_url('/mod/assign/view.php', $urlparams);
1125             $description = get_string('addattempt', 'assign');
1126             $actions['addattempt'] = new action_menu_link_secondary(
1127                 $url,
1128                 $noimage,
1129                 $description
1130             );
1131         }
1133         $menu = new action_menu();
1134         $menu->set_owner_selector('.gradingtable-actionmenu');
1135         $menu->set_alignment(action_menu::TL, action_menu::BL);
1136         $menu->set_constraint('.gradingtable > .no-overflow');
1137         $menu->set_menu_trigger(get_string('edit'));
1138         foreach ($actions as $action) {
1139             $menu->add($action);
1140         }
1142         // Prioritise the menu ahead of all other actions.
1143         $menu->prioritise = true;
1145         $edit .= $this->output->render($menu);
1147         return $edit;
1148     }
1150     /**
1151      * Write the plugin summary with an optional link to view the full feedback/submission.
1152      *
1153      * @param assign_plugin $plugin Submission plugin or feedback plugin
1154      * @param stdClass $item Submission or grade
1155      * @param string $returnaction The return action to pass to the
1156      *                             view_submission page (the current page)
1157      * @param string $returnparams The return params to pass to the view_submission
1158      *                             page (the current page)
1159      * @return string The summary with an optional link
1160      */
1161     private function format_plugin_summary_with_link(assign_plugin $plugin,
1162                                                      stdClass $item,
1163                                                      $returnaction,
1164                                                      $returnparams) {
1165         $link = '';
1166         $showviewlink = false;
1168         $summary = $plugin->view_summary($item, $showviewlink);
1169         $separator = '';
1170         if ($showviewlink) {
1171             $viewstr = get_string('view' . substr($plugin->get_subtype(), strlen('assign')), 'assign');
1172             $icon = $this->output->pix_icon('t/preview', $viewstr);
1173             $urlparams = array('id' => $this->assignment->get_course_module()->id,
1174                                                      'sid'=>$item->id,
1175                                                      'gid'=>$item->id,
1176                                                      'plugin'=>$plugin->get_type(),
1177                                                      'action'=>'viewplugin' . $plugin->get_subtype(),
1178                                                      'returnaction'=>$returnaction,
1179                                                      'returnparams'=>http_build_query($returnparams));
1180             $url = new moodle_url('/mod/assign/view.php', $urlparams);
1181             $link = $this->output->action_link($url, $icon);
1182             $separator = $this->output->spacer(array(), true);
1183         }
1185         return $link . $separator . $summary;
1186     }
1189     /**
1190      * Format the submission and feedback columns.
1191      *
1192      * @param string $colname The column name
1193      * @param stdClass $row The submission row
1194      * @return mixed string or NULL
1195      */
1196     public function other_cols($colname, $row) {
1197         // For extra user fields the result is already in $row.
1198         if (empty($this->plugincache[$colname])) {
1199             return $row->$colname;
1200         }
1202         // This must be a plugin field.
1203         $plugincache = $this->plugincache[$colname];
1205         $plugin = $plugincache[0];
1207         $field = null;
1208         if (isset($plugincache[1])) {
1209             $field = $plugincache[1];
1210         }
1212         if ($plugin->is_visible() && $plugin->is_enabled()) {
1213             if ($plugin->get_subtype() == 'assignsubmission') {
1214                 if ($this->assignment->get_instance()->teamsubmission) {
1215                     $group = false;
1216                     $submission = false;
1218                     $this->get_group_and_submission($row->id, $group, $submission, -1);
1219                     if ($submission) {
1220                         if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
1221                             // For a newly reopened submission - we want to show the previous submission in the table.
1222                             $this->get_group_and_submission($row->id, $group, $submission, $submission->attemptnumber-1);
1223                         }
1224                         if (isset($field)) {
1225                             return $plugin->get_editor_text($field, $submission->id);
1226                         }
1227                         return $this->format_plugin_summary_with_link($plugin,
1228                                                                       $submission,
1229                                                                       'grading',
1230                                                                       array());
1231                     }
1232                 } else if ($row->submissionid) {
1233                     if ($row->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
1234                         // For a newly reopened submission - we want to show the previous submission in the table.
1235                         $submission = $this->assignment->get_user_submission($row->userid, false, $row->attemptnumber - 1);
1236                     } else {
1237                         $submission = new stdClass();
1238                         $submission->id = $row->submissionid;
1239                         $submission->timecreated = $row->firstsubmission;
1240                         $submission->timemodified = $row->timesubmitted;
1241                         $submission->assignment = $this->assignment->get_instance()->id;
1242                         $submission->userid = $row->userid;
1243                         $submission->attemptnumber = $row->attemptnumber;
1244                     }
1245                     // Field is used for only for import/export and refers the the fieldname for the text editor.
1246                     if (isset($field)) {
1247                         return $plugin->get_editor_text($field, $submission->id);
1248                     }
1249                     return $this->format_plugin_summary_with_link($plugin,
1250                                                                   $submission,
1251                                                                   'grading',
1252                                                                   array());
1253                 }
1254             } else {
1255                 $grade = null;
1256                 if (isset($field)) {
1257                     return $plugin->get_editor_text($field, $row->gradeid);
1258                 }
1260                 if ($row->gradeid) {
1261                     $grade = new stdClass();
1262                     $grade->id = $row->gradeid;
1263                     $grade->timecreated = $row->firstmarked;
1264                     $grade->timemodified = $row->timemarked;
1265                     $grade->assignment = $this->assignment->get_instance()->id;
1266                     $grade->userid = $row->userid;
1267                     $grade->grade = $row->grade;
1268                     $grade->mailed = $row->mailed;
1269                     $grade->attemptnumber = $row->attemptnumber;
1270                 }
1271                 if ($this->quickgrading && $plugin->supports_quickgrading()) {
1272                     return $plugin->get_quickgrading_html($row->userid, $grade);
1273                 } else if ($grade) {
1274                     return $this->format_plugin_summary_with_link($plugin,
1275                                                                   $grade,
1276                                                                   'grading',
1277                                                                   array());
1278                 }
1279             }
1280         }
1281         return '';
1282     }
1284     /**
1285      * Using the current filtering and sorting - load all rows and return a single column from them.
1286      *
1287      * @param string $columnname The name of the raw column data
1288      * @return array of data
1289      */
1290     public function get_column_data($columnname) {
1291         $this->setup();
1292         $this->currpage = 0;
1293         $this->query_db($this->tablemaxrows);
1294         $result = array();
1295         foreach ($this->rawdata as $row) {
1296             $result[] = $row->$columnname;
1297         }
1298         return $result;
1299     }
1301     /**
1302      * Return things to the renderer.
1303      *
1304      * @return string the assignment name
1305      */
1306     public function get_assignment_name() {
1307         return $this->assignment->get_instance()->name;
1308     }
1310     /**
1311      * Return things to the renderer.
1312      *
1313      * @return int the course module id
1314      */
1315     public function get_course_module_id() {
1316         return $this->assignment->get_course_module()->id;
1317     }
1319     /**
1320      * Return things to the renderer.
1321      *
1322      * @return int the course id
1323      */
1324     public function get_course_id() {
1325         return $this->assignment->get_course()->id;
1326     }
1328     /**
1329      * Return things to the renderer.
1330      *
1331      * @return stdClass The course context
1332      */
1333     public function get_course_context() {
1334         return $this->assignment->get_course_context();
1335     }
1337     /**
1338      * Return things to the renderer.
1339      *
1340      * @return bool Does this assignment accept submissions
1341      */
1342     public function submissions_enabled() {
1343         return $this->assignment->is_any_submission_plugin_enabled();
1344     }
1346     /**
1347      * Return things to the renderer.
1348      *
1349      * @return bool Can this user view all grades (the gradebook)
1350      */
1351     public function can_view_all_grades() {
1352         $context = $this->assignment->get_course_context();
1353         return has_capability('gradereport/grader:view', $context) &&
1354                has_capability('moodle/grade:viewall', $context);
1355     }
1357     /**
1358      * Override the table show_hide_link to not show for select column.
1359      *
1360      * @param string $column the column name, index into various names.
1361      * @param int $index numerical index of the column.
1362      * @return string HTML fragment.
1363      */
1364     protected function show_hide_link($column, $index) {
1365         if ($index > 0 || !$this->hasgrade) {
1366             return parent::show_hide_link($column, $index);
1367         }
1368         return '';
1369     }