2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * This file contains the definition for the grading table which subclassses easy_table
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
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');
32 * Extends table_sql to provide a table of assignment submissions
35 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
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) */
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;
69 * overridden constructor keeps a reference to the assignment class that is displaying this table
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
78 public function __construct(assign
$assignment,
83 $downloadfilename = null) {
84 global $CFG, $PAGE, $DB, $USER;
85 parent
::__construct('mod_assign_grading');
86 $this->is_persistent(true);
87 $this->assignment
= $assignment;
89 // Check permissions up front.
90 $this->hasgrantextension
= has_capability('mod/assign:grantextension',
91 $this->assignment
->get_context());
92 $this->hasgrade
= $this->assignment
->can_grade();
94 // Check if we have the elevated view capablities to see the blind details.
95 $this->hasviewblind
= has_capability('mod/assign:viewblinddetails',
96 $this->assignment
->get_context());
98 foreach ($assignment->get_feedback_plugins() as $plugin) {
99 if ($plugin->is_visible() && $plugin->is_enabled()) {
100 foreach ($plugin->get_grading_batch_operations() as $action => $description) {
101 if (empty($this->plugingradingbatchoperations
)) {
102 $this->plugingradingbatchoperations
[$plugin->get_type()] = array();
104 $this->plugingradingbatchoperations
[$plugin->get_type()][$action] = $description;
108 $this->perpage
= $perpage;
109 $this->quickgrading
= $quickgrading && $this->hasgrade
;
110 $this->output
= $PAGE->get_renderer('mod_assign');
112 $urlparams = array('action'=>'grading', 'id'=>$assignment->get_course_module()->id
);
113 $url = new moodle_url($CFG->wwwroot
. '/mod/assign/view.php', $urlparams);
114 $this->define_baseurl($url);
116 // Do some business - then set the sql.
117 $currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
120 $this->rownum
= $rowoffset - 1;
123 $users = array_keys( $assignment->list_participants($currentgroup, true));
124 if (count($users) == 0) {
125 // Insert a record that will never match to the sql is still valid.
130 $params['assignmentid1'] = (int)$this->assignment
->get_instance()->id
;
131 $params['assignmentid2'] = (int)$this->assignment
->get_instance()->id
;
132 $params['assignmentid3'] = (int)$this->assignment
->get_instance()->id
;
134 $params['assignmentid5'] = (int)$this->assignment
->get_instance()->id
;
135 $params['assignmentid6'] = (int)$this->assignment
->get_instance()->id
;
136 $params['assignmentid7'] = (int)$this->assignment
->get_instance()->id
;
137 $params['assignmentid8'] = (int)$this->assignment
->get_instance()->id
;
138 $params['assignmentid9'] = (int)$this->assignment
->get_instance()->id
;
140 $extrauserfields = get_extra_user_fields($this->assignment
->get_context());
142 $fields = user_picture
::fields('u', $extrauserfields) . ', ';
143 $fields .= 'u.id as userid, ';
144 $fields .= 's.status as status, ';
145 $fields .= 's.id as submissionid, ';
146 $fields .= 's.timecreated as firstsubmission, ';
147 $fields .= 's.timemodified as timesubmitted, ';
148 $fields .= 's.attemptnumber as attemptnumber, ';
149 $fields .= 'g.id as gradeid, ';
150 $fields .= 'g.grade as grade, ';
151 $fields .= 'g.timemodified as timemarked, ';
152 $fields .= 'g.timecreated as firstmarked, ';
153 $fields .= 'uf.mailed as mailed, ';
154 $fields .= 'uf.locked as locked, ';
155 $fields .= 'uf.extensionduedate as extensionduedate, ';
156 $fields .= 'uf.workflowstate as workflowstate, ';
157 $fields .= 'uf.allocatedmarker as allocatedmarker';
160 LEFT JOIN {assign_submission} s
162 AND s.assignment = :assignmentid1
164 LEFT JOIN {assign_grades} g
166 AND g.assignment = :assignmentid2 ';
168 // For group submissions we don't immediately create an entry in the assign_submission table for each user,
169 // instead the userid is set to 0. In this case we use a different query to retrieve the grade for the user.
170 if ($this->assignment
->get_instance()->teamsubmission
) {
171 $params['assignmentid4'] = (int) $this->assignment
->get_instance()->id
;
172 $grademaxattempt = 'SELECT mxg.userid, MAX(mxg.attemptnumber) AS maxattempt
173 FROM {assign_grades} mxg
174 WHERE mxg.assignment = :assignmentid4
175 GROUP BY mxg.userid';
176 $from .= 'LEFT JOIN (' . $grademaxattempt . ') gmx
178 AND g.attemptnumber = gmx.maxattempt ';
180 $from .= 'AND g.attemptnumber = s.attemptnumber ';
183 $from .= 'LEFT JOIN {assign_user_flags} uf
185 AND uf.assignment = :assignmentid3 ';
187 $hasoverrides = $this->assignment
->has_overrides();
190 $fields .= ', priority.priority, ';
191 $fields .= 'effective.allowsubmissionsfromdate, ';
192 $fields .= 'effective.duedate, ';
193 $fields .= 'effective.cutoffdate ';
195 $from .= ' LEFT JOIN (
196 SELECT merged.userid, min(merged.priority) priority FROM (
197 ( SELECT u.id as userid, 9999999 AS priority
201 ( SELECT uo.userid, 0 AS priority
202 FROM {assign_overrides} uo
203 WHERE uo.assignid = :assignmentid5
206 ( SELECT gm.userid, go.sortorder AS priority
207 FROM {assign_overrides} go
208 JOIN {groups} g ON g.id = go.groupid
209 JOIN {groups_members} gm ON gm.groupid = g.id
210 WHERE go.assignid = :assignmentid6
213 GROUP BY merged.userid
214 ) priority ON priority.userid = u.id
217 (SELECT 9999999 AS priority,
220 a.allowsubmissionsfromdate,
224 JOIN {assign} a ON a.id = :assignmentid7
227 (SELECT 0 AS priority,
230 uo.allowsubmissionsfromdate,
233 FROM {assign_overrides} uo
234 WHERE uo.assignid = :assignmentid8
237 (SELECT go.sortorder AS priority,
240 go.allowsubmissionsfromdate,
243 FROM {assign_overrides} go
244 JOIN {groups} g ON g.id = go.groupid
245 JOIN {groups_members} gm ON gm.groupid = g.id
246 WHERE go.assignid = :assignmentid9
249 ) AS effective ON effective.priority = priority.priority AND effective.userid = priority.userid ';
252 if (!empty($this->assignment
->get_instance()->blindmarking
)) {
253 $from .= 'LEFT JOIN {assign_user_mapping} um
255 AND um.assignment = :assignmentid5 ';
256 $params['assignmentid5'] = (int)$this->assignment
->get_instance()->id
;
257 $fields .= ', um.id as recordid ';
260 $userparams = array();
263 list($userwhere, $userparams) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED
, 'user');
264 $where = 'u.id ' . $userwhere;
265 $params = array_merge($params, $userparams);
267 // The filters do not make sense when there are no submissions, so do not apply them.
268 if ($this->assignment
->is_any_submission_plugin_enabled()) {
269 if ($filter == ASSIGN_FILTER_SUBMITTED
) {
270 $where .= ' AND (s.timemodified IS NOT NULL AND
271 s.status = :submitted) ';
272 $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED
;
274 } else if ($filter == ASSIGN_FILTER_NOT_SUBMITTED
) {
275 $where .= ' AND (s.timemodified IS NULL OR s.status != :submitted) ';
276 $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED
;
277 } else if ($filter == ASSIGN_FILTER_REQUIRE_GRADING
) {
278 $where .= ' AND (s.timemodified IS NOT NULL AND
279 s.status = :submitted AND
280 (s.timemodified >= g.timemodified OR g.timemodified IS NULL OR g.grade IS NULL';
282 if ($this->assignment
->get_grade_item()->gradetype
== GRADE_TYPE_SCALE
) {
283 // Scale grades are set to -1 when not graded.
284 $where .= ' OR g.grade = -1';
288 $params['submitted'] = ASSIGN_SUBMISSION_STATUS_SUBMITTED
;
290 } else if (strpos($filter, ASSIGN_FILTER_SINGLE_USER
) === 0) {
291 $userfilter = (int) array_pop(explode('=', $filter));
292 $where .= ' AND (u.id = :userid)';
293 $params['userid'] = $userfilter;
297 if ($this->assignment
->get_instance()->markingworkflow
&&
298 $this->assignment
->get_instance()->markingallocation
) {
299 if (has_capability('mod/assign:manageallocations', $this->assignment
->get_context())) {
300 // Check to see if marker filter is set.
301 $markerfilter = (int)get_user_preferences('assign_markerfilter', '');
302 if (!empty($markerfilter)) {
303 if ($markerfilter == ASSIGN_MARKER_FILTER_NO_MARKER
) {
304 $where .= ' AND (uf.allocatedmarker IS NULL OR uf.allocatedmarker = 0)';
310 if ($this->assignment
->get_instance()->markingworkflow
) {
311 $workflowstates = $this->assignment
->get_marking_workflow_states_for_current_user();
312 if (!empty($workflowstates)) {
313 $workflowfilter = get_user_preferences('assign_workflowfilter', '');
314 if ($workflowfilter == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED
) {
315 $where .= ' AND (uf.workflowstate = :workflowstate OR uf.workflowstate IS NULL OR '.
316 $DB->sql_isempty('assign_user_flags', 'workflowstate', true, true).')';
317 $params['workflowstate'] = $workflowfilter;
318 } else if (array_key_exists($workflowfilter, $workflowstates)) {
319 $where .= ' AND uf.workflowstate = :workflowstate';
320 $params['workflowstate'] = $workflowfilter;
325 $this->set_sql($fields, $from, $where, $params);
327 if ($downloadfilename) {
328 $this->is_downloading('csv', $downloadfilename);
335 if (!$this->is_downloading() && $this->hasgrade
) {
336 $columns[] = 'select';
337 $headers[] = get_string('select') .
338 '<div class="selectall"><label class="accesshide" for="selectall">' . get_string('selectall') . '</label>
339 <input type="checkbox" id="selectall" name="selectall" title="' . get_string('selectall') . '"/></div>';
343 if ($this->hasviewblind ||
!$this->assignment
->is_blind_marking()) {
344 if (!$this->is_downloading()) {
345 $columns[] = 'picture';
346 $headers[] = get_string('pictureofuser');
348 $columns[] = 'recordid';
349 $headers[] = get_string('recordid', 'assign');
353 $columns[] = 'fullname';
354 $headers[] = get_string('fullname');
356 // Participant # details if can view real identities.
357 if ($this->assignment
->is_blind_marking()) {
358 if (!$this->is_downloading()) {
359 $columns[] = 'recordid';
360 $headers[] = get_string('recordid', 'assign');
364 foreach ($extrauserfields as $extrafield) {
365 $columns[] = $extrafield;
366 $headers[] = get_user_field_name($extrafield);
370 $columns[] = 'recordid';
371 $headers[] = get_string('recordid', 'assign');
374 // Submission status.
375 $columns[] = 'status';
376 $headers[] = get_string('status', 'assign');
379 // Allowsubmissionsfromdate.
380 $columns[] = 'allowsubmissionsfromdate';
381 $headers[] = get_string('allowsubmissionsfromdate', 'assign');
384 $columns[] = 'duedate';
385 $headers[] = get_string('duedate', 'assign');
388 $columns[] = 'cutoffdate';
389 $headers[] = get_string('cutoffdate', 'assign');
392 // Team submission columns.
393 if ($assignment->get_instance()->teamsubmission
) {
395 $headers[] = get_string('submissionteam', 'assign');
398 if ($this->assignment
->get_instance()->markingworkflow
&&
399 $this->assignment
->get_instance()->markingallocation
&&
400 has_capability('mod/assign:manageallocations', $this->assignment
->get_context())) {
401 // Add a column for the allocated marker.
402 $columns[] = 'allocatedmarker';
403 $headers[] = get_string('marker', 'assign');
406 $columns[] = 'grade';
407 $headers[] = get_string('grade');
408 if ($this->is_downloading()) {
409 if ($this->assignment
->get_instance()->grade
>= 0) {
410 $columns[] = 'grademax';
411 $headers[] = get_string('maxgrade', 'assign');
413 // This is a custom scale.
414 $columns[] = 'scale';
415 $headers[] = get_string('scale', 'assign');
418 if ($this->assignment
->get_instance()->markingworkflow
) {
419 // Add a column for the marking workflow state.
420 $columns[] = 'workflowstate';
421 $headers[] = get_string('markingworkflowstate', 'assign');
423 // Add a column for the list of valid marking workflow states.
424 $columns[] = 'gradecanbechanged';
425 $headers[] = get_string('gradecanbechanged', 'assign');
427 if (!$this->is_downloading() && $this->hasgrade
) {
428 // We have to call this column userid so we can use userid as a default sortable column.
429 $columns[] = 'userid';
430 $headers[] = get_string('edit');
433 // Submission plugins.
434 if ($assignment->is_any_submission_plugin_enabled()) {
435 $columns[] = 'timesubmitted';
436 $headers[] = get_string('lastmodifiedsubmission', 'assign');
438 foreach ($this->assignment
->get_submission_plugins() as $plugin) {
439 if ($this->is_downloading()) {
440 if ($plugin->is_visible() && $plugin->is_enabled()) {
441 foreach ($plugin->get_editor_fields() as $field => $description) {
442 $index = 'plugin' . count($this->plugincache
);
443 $this->plugincache
[$index] = array($plugin, $field);
445 $headers[] = $plugin->get_name();
449 if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
450 $index = 'plugin' . count($this->plugincache
);
451 $this->plugincache
[$index] = array($plugin);
453 $headers[] = $plugin->get_name();
460 $columns[] = 'timemarked';
461 $headers[] = get_string('lastmodifiedgrade', 'assign');
464 foreach ($this->assignment
->get_feedback_plugins() as $plugin) {
465 if ($this->is_downloading()) {
466 if ($plugin->is_visible() && $plugin->is_enabled()) {
467 foreach ($plugin->get_editor_fields() as $field => $description) {
468 $index = 'plugin' . count($this->plugincache
);
469 $this->plugincache
[$index] = array($plugin, $field);
471 $headers[] = $description;
474 } else if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
475 $index = 'plugin' . count($this->plugincache
);
476 $this->plugincache
[$index] = array($plugin);
478 $headers[] = $plugin->get_name();
482 // Exclude 'Final grade' column in downloaded grading worksheets.
483 if (!$this->is_downloading()) {
485 $columns[] = 'finalgrade';
486 $headers[] = get_string('finalgrade', 'grades');
489 // Load the grading info for all users.
490 $this->gradinginfo
= grade_get_grades($this->assignment
->get_course()->id
,
493 $this->assignment
->get_instance()->id
,
496 if (!empty($CFG->enableoutcomes
) && !empty($this->gradinginfo
->outcomes
)) {
497 $columns[] = 'outcomes';
498 $headers[] = get_string('outcomes', 'grades');
502 $this->define_columns($columns);
503 $this->define_headers($headers);
504 foreach ($extrauserfields as $extrafield) {
505 $this->column_class($extrafield, $extrafield);
507 $this->no_sorting('recordid');
508 $this->no_sorting('finalgrade');
509 $this->no_sorting('userid');
510 $this->no_sorting('select');
511 $this->no_sorting('outcomes');
513 if ($assignment->get_instance()->teamsubmission
) {
514 $this->no_sorting('team');
517 $plugincolumnindex = 0;
518 foreach ($this->assignment
->get_submission_plugins() as $plugin) {
519 if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
520 $submissionpluginindex = 'plugin' . $plugincolumnindex++
;
521 $this->no_sorting($submissionpluginindex);
524 foreach ($this->assignment
->get_feedback_plugins() as $plugin) {
525 if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
526 $feedbackpluginindex = 'plugin' . $plugincolumnindex++
;
527 $this->no_sorting($feedbackpluginindex);
531 // When there is no data we still want the column headers printed in the csv file.
532 if ($this->is_downloading()) {
533 $this->start_output();
538 * Before adding each row to the table make sure rownum is incremented.
540 * @param array $row row of data from db used to make one row of the table.
541 * @return array one row for the table
543 public function format_row($row) {
544 if ($this->rownum
< 0) {
545 $this->rownum
= $this->currpage
* $this->pagesize
;
550 return parent
::format_row($row);
554 * Add a column with an ID that uniquely identifies this user in this assignment.
556 * @param stdClass $row
559 public function col_recordid(stdClass
$row) {
560 if (empty($row->recordid
)) {
561 $row->recordid
= $this->assignment
->get_uniqueid_for_user($row->userid
);
563 return get_string('hiddenuser', 'assign') . $row->recordid
;
568 * Add the userid to the row class so it can be updated via ajax.
570 * @param stdClass $row The row of data
571 * @return string The row class
573 public function get_row_class($row) {
574 return 'user' . $row->userid
;
578 * Return the number of rows to display on a single page.
580 * @return int The number of rows per page
582 public function get_rows_per_page() {
583 return $this->perpage
;
587 * list current marking workflow state
589 * @param stdClass $row
592 public function col_workflowstatus(stdClass
$row) {
595 $gradingdisabled = $this->assignment
->grading_disabled($row->id
);
596 // The function in the assignment keeps a static cache of this list of states.
597 $workflowstates = $this->assignment
->get_marking_workflow_states_for_current_user();
598 $workflowstate = $row->workflowstate
;
599 if (empty($workflowstate)) {
600 $workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED
;
602 if ($this->quickgrading
&& !$gradingdisabled) {
603 $notmarked = get_string('markingworkflowstatenotmarked', 'assign');
604 $name = 'quickgrade_' . $row->id
. '_workflowstate';
605 $o .= html_writer
::select($workflowstates, $name, $workflowstate, array('' => $notmarked));
606 // Check if this user is a marker that can't manage allocations and doesn't have the marker column added.
607 if ($this->assignment
->get_instance()->markingworkflow
&&
608 $this->assignment
->get_instance()->markingallocation
&&
609 !has_capability('mod/assign:manageallocations', $this->assignment
->get_context())) {
611 $name = 'quickgrade_' . $row->id
. '_allocatedmarker';
612 $o .= html_writer
::empty_tag('input', array('type' => 'hidden', 'name' => $name,
613 'value' => $row->allocatedmarker
));
616 $o .= $this->output
->container(get_string('markingworkflowstate' . $workflowstate, 'assign'), $workflowstate);
622 * For download only - list current marking workflow state
624 * @param stdClass $row - The row of data
625 * @return string The current marking workflow state
627 public function col_workflowstate($row) {
628 $state = $row->workflowstate
;
630 $state = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED
;
633 return get_string('markingworkflowstate' . $state, 'assign');
637 * list current marker
639 * @param stdClass $row - The row of data
640 * @return id the user->id of the marker.
642 public function col_allocatedmarker(stdClass
$row) {
643 static $markers = null;
644 static $markerlist = array();
645 if ($markers === null) {
646 list($sort, $params) = users_order_by_sql();
647 $markers = get_users_by_capability($this->assignment
->get_context(), 'mod/assign:grade', '', $sort);
648 $markerlist[0] = get_string('choosemarker', 'assign');
649 $viewfullnames = has_capability('moodle/site:viewfullnames', $this->assignment
->get_context());
650 foreach ($markers as $marker) {
651 $markerlist[$marker->id
] = fullname($marker, $viewfullnames);
654 if (empty($markerlist)) {
655 // TODO: add some form of notification here that no markers are available.
658 if ($this->is_downloading()) {
659 if (isset($markers[$row->allocatedmarker
])) {
660 return fullname($markers[$row->allocatedmarker
],
661 has_capability('moodle/site:viewfullnames', $this->assignment
->get_context()));
667 if ($this->quickgrading
&& has_capability('mod/assign:manageallocations', $this->assignment
->get_context()) &&
668 (empty($row->workflowstate
) ||
669 $row->workflowstate
== ASSIGN_MARKING_WORKFLOW_STATE_INMARKING ||
670 $row->workflowstate
== ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED
)) {
672 $name = 'quickgrade_' . $row->id
. '_allocatedmarker';
673 return html_writer
::select($markerlist, $name, $row->allocatedmarker
, false);
674 } else if (!empty($row->allocatedmarker
)) {
676 if ($this->quickgrading
) { // Add hidden field for quickgrading page.
677 $name = 'quickgrade_' . $row->id
. '_allocatedmarker';
678 $output .= html_writer
::empty_tag('input', array('type'=>'hidden', 'name'=>$name, 'value'=>$row->allocatedmarker
));
680 $output .= $markerlist[$row->allocatedmarker
];
685 * For download only - list all the valid options for this custom scale.
687 * @param stdClass $row - The row of data
688 * @return string A list of valid options for the current scale
690 public function col_scale($row) {
693 if (empty($this->scale
)) {
694 $dbparams = array('id'=>-($this->assignment
->get_instance()->grade
));
695 $this->scale
= $DB->get_record('scale', $dbparams);
698 if (!empty($this->scale
->scale
)) {
699 return implode("\n", explode(',', $this->scale
->scale
));
705 * Display a grade with scales etc.
707 * @param string $grade
708 * @param boolean $editable
709 * @param int $userid The user id of the user this grade belongs to
710 * @param int $modified Timestamp showing when the grade was last modified
711 * @return string The formatted grade
713 public function display_grade($grade, $editable, $userid, $modified) {
714 if ($this->is_downloading()) {
715 if ($this->assignment
->get_instance()->grade
>= 0) {
716 if ($grade == -1 ||
$grade === null) {
719 $gradeitem = $this->assignment
->get_grade_item();
720 return format_float($grade, $gradeitem->get_decimals());
722 // This is a custom scale.
723 $scale = $this->assignment
->display_grade($grade, false);
730 return $this->assignment
->display_grade($grade, $editable, $userid, $modified);
734 * Get the team info for this user.
736 * @param stdClass $row
737 * @return string The team name
739 public function col_team(stdClass
$row) {
742 $this->get_group_and_submission($row->id
, $group, $submission, -1);
745 } else if ($this->assignment
->get_instance()->preventsubmissionnotingroup
) {
746 $usergroups = $this->assignment
->get_all_groups($row->id
);
747 if (count($usergroups) > 1) {
748 return get_string('multipleteamsgrader', 'assign');
750 return get_string('noteamgrader', 'assign');
753 return get_string('defaultteam', 'assign');
757 * Use a static cache to try and reduce DB calls.
759 * @param int $userid The user id for this submission
760 * @param int $group The groupid (returned)
761 * @param stdClass|false $submission The stdClass submission or false (returned)
762 * @param int $attemptnumber Return a specific attempt number (-1 for latest)
764 protected function get_group_and_submission($userid, &$group, &$submission, $attemptnumber) {
766 if (isset($this->submissiongroups
[$userid])) {
767 $group = $this->submissiongroups
[$userid];
769 $group = $this->assignment
->get_submission_group($userid, false);
770 $this->submissiongroups
[$userid] = $group;
775 $groupid = $group->id
;
778 // Static cache is keyed by groupid and attemptnumber.
779 // We may need both the latest and previous attempt in the same page.
780 if (isset($this->groupsubmissions
[$groupid . ':' . $attemptnumber])) {
781 $submission = $this->groupsubmissions
[$groupid . ':' . $attemptnumber];
783 $submission = $this->assignment
->get_group_submission($userid, $groupid, false, $attemptnumber);
784 $this->groupsubmissions
[$groupid . ':' . $attemptnumber] = $submission;
789 * Format a list of outcomes.
791 * @param stdClass $row
794 public function col_outcomes(stdClass
$row) {
796 foreach ($this->gradinginfo
->outcomes
as $index => $outcome) {
797 $options = make_grades_menu(-$outcome->scaleid
);
799 $options[0] = get_string('nooutcome', 'grades');
800 if ($this->quickgrading
&& !($outcome->grades
[$row->userid
]->locked
)) {
801 $select = '<select name="outcome_' . $index . '_' . $row->userid
. '" class="quickgrade">';
802 foreach ($options as $optionindex => $optionvalue) {
804 if ($outcome->grades
[$row->userid
]->grade
== $optionindex) {
805 $selected = 'selected="selected"';
807 $select .= '<option value="' . $optionindex . '"' . $selected . '>' . $optionvalue . '</option>';
809 $select .= '</select>';
810 $outcomes .= $this->output
->container($outcome->name
. ': ' . $select, 'outcome');
812 $name = $outcome->name
. ': ' . $options[$outcome->grades
[$row->userid
]->grade
];
813 if ($this->is_downloading()) {
816 $outcomes .= $this->output
->container($name, 'outcome');
826 * Format a user picture for display.
828 * @param stdClass $row
831 public function col_picture(stdClass
$row) {
832 return $this->output
->user_picture($row);
836 * Format a user record for display (link to profile).
838 * @param stdClass $row
841 public function col_fullname($row) {
842 if (!$this->is_downloading()) {
843 $courseid = $this->assignment
->get_course()->id
;
844 $link= new moodle_url('/user/view.php', array('id' =>$row->id
, 'course'=>$courseid));
845 $fullname = $this->output
->action_link($link, $this->assignment
->fullname($row));
847 $fullname = $this->assignment
->fullname($row);
850 if (!$this->assignment
->is_active_user($row->id
)) {
851 $suspendedstring = get_string('userenrolmentsuspended', 'grades');
852 $fullname .= ' ' . html_writer
::empty_tag('img', array('src' => $this->output
->pix_url('i/enrolmentsuspended'),
853 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
854 $fullname = html_writer
::tag('span', $fullname, array('class' => 'usersuspended'));
860 * Insert a checkbox for selecting the current row for batch operations.
862 * @param stdClass $row
865 public function col_select(stdClass
$row) {
866 $selectcol = '<label class="accesshide" for="selectuser_' . $row->userid
. '">';
867 $selectcol .= get_string('selectuser', 'assign', $this->assignment
->fullname($row));
868 $selectcol .= '</label>';
869 $selectcol .= '<input type="checkbox"
870 id="selectuser_' . $row->userid
. '"
872 value="' . $row->userid
. '"/>';
873 $selectcol .= '<input type="hidden"
874 name="grademodified_' . $row->userid
. '"
875 value="' . $row->timemarked
. '"/>';
876 $selectcol .= '<input type="hidden"
877 name="gradeattempt_' . $row->userid
. '"
878 value="' . $row->attemptnumber
. '"/>';
883 * Return a users grades from the listing of all grade data for this assignment.
886 * @return mixed stdClass or false
888 private function get_gradebook_data_for_user($userid) {
889 if (isset($this->gradinginfo
->items
[0]) && $this->gradinginfo
->items
[0]->grades
[$userid]) {
890 return $this->gradinginfo
->items
[0]->grades
[$userid];
896 * Format a column of data for display.
898 * @param stdClass $row
901 public function col_gradecanbechanged(stdClass
$row) {
902 $gradingdisabled = $this->assignment
->grading_disabled($row->id
);
903 if ($gradingdisabled) {
904 return get_string('no');
906 return get_string('yes');
911 * Format a column of data for display
913 * @param stdClass $row
916 public function col_grademax(stdClass
$row) {
917 $gradeitem = $this->assignment
->get_grade_item();
918 return format_float($this->assignment
->get_instance()->grade
, $gradeitem->get_decimals());
922 * Format a column of data for display.
924 * @param stdClass $row
927 public function col_grade(stdClass
$row) {
931 $separator = $this->output
->spacer(array(), true);
933 $gradingdisabled = $this->assignment
->grading_disabled($row->id
);
935 if (!$this->is_downloading() && $this->hasgrade
) {
936 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
938 'action' => 'grader');
940 if ($this->assignment
->is_blind_marking()) {
941 if (empty($row->recordid
)) {
942 $row->recordid
= $this->assignment
->get_uniqueid_for_user($row->userid
);
944 $urlparams['blindid'] = $row->recordid
;
946 $urlparams['userid'] = $row->userid
;
949 $url = new moodle_url('/mod/assign/view.php', $urlparams);
950 $link = '<a href="' . $url . '" class="btn btn-primary">' . get_string('grade') . '</a>';
951 $grade .= $link . $separator;
954 $grade .= $this->display_grade($row->grade
,
955 $this->quickgrading
&& !$gradingdisabled,
963 * Format a column of data for display.
965 * @param stdClass $row
968 public function col_finalgrade(stdClass
$row) {
971 $grade = $this->get_gradebook_data_for_user($row->userid
);
973 $o = $this->display_grade($grade->grade
, false, $row->userid
, $row->timemarked
);
980 * Format a column of data for display.
982 * @param stdClass $row
985 public function col_timemarked(stdClass
$row) {
988 if ($row->timemarked
&& $row->grade
!== null && $row->grade
>= 0) {
989 $o = userdate($row->timemarked
);
991 if ($row->timemarked
&& $this->is_downloading()) {
992 // Force it for downloads as it affects import.
993 $o = userdate($row->timemarked
);
1000 * Format a column of data for display.
1002 * @param stdClass $row
1005 public function col_timesubmitted(stdClass
$row) {
1009 $submission = false;
1010 $this->get_group_and_submission($row->id
, $group, $submission, -1);
1011 if ($submission && $submission->timemodified
&& $submission->status
!= ASSIGN_SUBMISSION_STATUS_NEW
) {
1012 $o = userdate($submission->timemodified
);
1013 } else if ($row->timesubmitted
&& $row->status
!= ASSIGN_SUBMISSION_STATUS_NEW
) {
1014 $o = userdate($row->timesubmitted
);
1021 * Format a column of data for display
1023 * @param stdClass $row
1026 public function col_status(stdClass
$row) {
1029 $instance = $this->assignment
->get_instance();
1031 $due = $instance->duedate
;
1032 if ($row->extensionduedate
) {
1033 $due = $row->extensionduedate
;
1034 } else if (!empty($row->duedate
)) {
1035 // The override due date.
1036 $due = $row->duedate
;
1040 $submission = false;
1041 $this->get_group_and_submission($row->id
, $group, $submission, -1);
1043 if ($instance->teamsubmission
&& !$group && !$instance->preventsubmissionnotingroup
) {
1047 if ($group && $submission) {
1048 $timesubmitted = $submission->timemodified
;
1049 $status = $submission->status
;
1051 $timesubmitted = $row->timesubmitted
;
1052 $status = $row->status
;
1055 $displaystatus = $status;
1056 if ($displaystatus == 'new') {
1057 $displaystatus = '';
1060 if ($this->assignment
->is_any_submission_plugin_enabled()) {
1062 $o .= $this->output
->container(get_string('submissionstatus_' . $displaystatus, 'assign'),
1063 array('class'=>'submissionstatus' .$displaystatus));
1064 if ($due && $timesubmitted > $due && $status != ASSIGN_SUBMISSION_STATUS_NEW
) {
1065 $usertime = format_time($timesubmitted - $due);
1066 $latemessage = get_string('submittedlateshort',
1069 $o .= $this->output
->container($latemessage, 'latesubmission');
1072 $lockedstr = get_string('submissionslockedshort', 'assign');
1073 $o .= $this->output
->container($lockedstr, 'lockedsubmission');
1076 // Add status of "grading" if markflow is not enabled.
1077 if (!$instance->markingworkflow
) {
1078 if ($row->grade
!== null && $row->grade
>= 0) {
1079 $o .= $this->output
->container(get_string('graded', 'assign'), 'submissiongraded');
1080 } else if (!$timesubmitted ||
$status == ASSIGN_SUBMISSION_STATUS_NEW
) {
1082 if ($due && ($now > $due)) {
1083 $overduestr = get_string('overdue', 'assign', format_time($now - $due));
1084 $o .= $this->output
->container($overduestr, 'overduesubmission');
1090 if ($instance->markingworkflow
) {
1091 $o .= $this->col_workflowstatus($row);
1093 if ($row->extensionduedate
) {
1094 $userdate = userdate($row->extensionduedate
);
1095 $extensionstr = get_string('userextensiondate', 'assign', $userdate);
1096 $o .= $this->output
->container($extensionstr, 'extensiondate');
1099 if ($this->is_downloading()) {
1100 $o = strip_tags(rtrim(str_replace('</div>', ' - ', $o), '- '));
1107 * Format a column of data for display.
1109 * @param stdClass $row
1112 public function col_allowsubmissionsfromdate(stdClass
$row) {
1115 if ($row->allowsubmissionsfromdate
) {
1116 $userdate = userdate($row->allowsubmissionsfromdate
);
1117 $o = $this->output
->container($userdate, 'allowsubmissionsfromdate');
1125 * Format a column of data for display.
1127 * @param stdClass $row
1130 public function col_duedate(stdClass
$row) {
1133 if ($row->duedate
) {
1134 $userdate = userdate($row->duedate
);
1135 $o = $this->output
->container($userdate, 'duedate');
1143 * Format a column of data for display.
1145 * @param stdClass $row
1148 public function col_cutoffdate(stdClass
$row) {
1151 if ($row->cutoffdate
) {
1152 $userdate = userdate($row->cutoffdate
);
1153 $o = $this->output
->container($userdate, 'cutoffdate');
1161 * Format a column of data for display.
1163 * @param stdClass $row
1166 public function col_userid(stdClass
$row) {
1173 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
1175 'action' => 'grader');
1177 if ($this->assignment
->is_blind_marking()) {
1178 if (empty($row->recordid
)) {
1179 $row->recordid
= $this->assignment
->get_uniqueid_for_user($row->userid
);
1181 $urlparams['blindid'] = $row->recordid
;
1183 $urlparams['userid'] = $row->userid
;
1185 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1189 $description = get_string('grade');
1191 $description = get_string('updategrade', 'assign');
1193 $actions['grade'] = new action_menu_link_secondary(
1199 // Everything we need is in the row.
1202 if ($this->assignment
->get_instance()->teamsubmission
) {
1203 // Use the cache for this.
1204 $submission = false;
1206 $this->get_group_and_submission($row->id
, $group, $submission, -1);
1209 $submissionsopen = $this->assignment
->submissions_open($row->id
,
1213 $this->gradinginfo
);
1214 $caneditsubmission = $this->assignment
->can_edit_submission($row->id
, $USER->id
);
1216 // Hide for offline assignments.
1217 if ($this->assignment
->is_any_submission_plugin_enabled()) {
1218 if (!$row->status ||
1219 $row->status
== ASSIGN_SUBMISSION_STATUS_DRAFT ||
1220 !$this->assignment
->get_instance()->submissiondrafts
) {
1222 if (!$row->locked
) {
1223 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
1226 'sesskey'=>sesskey(),
1227 'page'=>$this->currpage
);
1228 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1230 $description = get_string('preventsubmissionsshort', 'assign');
1231 $actions['lock'] = new action_menu_link_secondary(
1237 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
1240 'sesskey'=>sesskey(),
1241 'page'=>$this->currpage
);
1242 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1243 $description = get_string('allowsubmissionsshort', 'assign');
1244 $actions['unlock'] = new action_menu_link_secondary(
1252 if ($submissionsopen &&
1253 $USER->id
!= $row->id
&&
1254 $caneditsubmission) {
1255 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
1257 'action'=>'editsubmission',
1258 'sesskey'=>sesskey(),
1259 'page'=>$this->currpage
);
1260 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1261 $description = get_string('editsubmission', 'assign');
1262 $actions['editsubmission'] = new action_menu_link_secondary(
1269 if (($this->assignment
->get_instance()->duedate ||
1270 $this->assignment
->get_instance()->cutoffdate
) &&
1271 $this->hasgrantextension
) {
1272 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
1273 'userid' => $row->id
,
1274 'action' => 'grantextension',
1275 'sesskey' => sesskey(),
1276 'page' => $this->currpage
);
1277 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1278 $description = get_string('grantextension', 'assign');
1279 $actions['grantextension'] = new action_menu_link_secondary(
1285 if ($row->status
== ASSIGN_SUBMISSION_STATUS_SUBMITTED
&&
1286 $this->assignment
->get_instance()->submissiondrafts
) {
1287 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
1289 'action'=>'reverttodraft',
1290 'sesskey'=>sesskey(),
1291 'page'=>$this->currpage
);
1292 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1293 $description = get_string('reverttodraftshort', 'assign');
1294 $actions['reverttodraft'] = new action_menu_link_secondary(
1300 if ($row->status
== ASSIGN_SUBMISSION_STATUS_DRAFT
&&
1301 $this->assignment
->get_instance()->submissiondrafts
&&
1302 $caneditsubmission &&
1304 $row->id
!= $USER->id
) {
1305 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
1307 'action'=>'submitotherforgrading',
1308 'sesskey'=>sesskey(),
1309 'page'=>$this->currpage
);
1310 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1311 $description = get_string('submitforgrading', 'assign');
1312 $actions['submitforgrading'] = new action_menu_link_secondary(
1319 $ismanual = $this->assignment
->get_instance()->attemptreopenmethod
== ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL
;
1320 $hassubmission = !empty($row->status
);
1321 $notreopened = $hassubmission && $row->status
!= ASSIGN_SUBMISSION_STATUS_REOPENED
;
1322 $isunlimited = $this->assignment
->get_instance()->maxattempts
== ASSIGN_UNLIMITED_ATTEMPTS
;
1323 $hasattempts = $isunlimited ||
$row->attemptnumber
< $this->assignment
->get_instance()->maxattempts
- 1;
1325 if ($ismanual && $hassubmission && $notreopened && $hasattempts) {
1326 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
1328 'action'=>'addattempt',
1329 'sesskey'=>sesskey(),
1330 'page'=>$this->currpage
);
1331 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1332 $description = get_string('addattempt', 'assign');
1333 $actions['addattempt'] = new action_menu_link_secondary(
1340 $menu = new action_menu();
1341 $menu->set_owner_selector('.gradingtable-actionmenu');
1342 $menu->set_alignment(action_menu
::TL
, action_menu
::BL
);
1343 $menu->set_constraint('.gradingtable > .no-overflow');
1344 $menu->set_menu_trigger(get_string('edit'));
1345 foreach ($actions as $action) {
1346 $menu->add($action);
1349 // Prioritise the menu ahead of all other actions.
1350 $menu->prioritise
= true;
1352 $edit .= $this->output
->render($menu);
1358 * Write the plugin summary with an optional link to view the full feedback/submission.
1360 * @param assign_plugin $plugin Submission plugin or feedback plugin
1361 * @param stdClass $item Submission or grade
1362 * @param string $returnaction The return action to pass to the
1363 * view_submission page (the current page)
1364 * @param string $returnparams The return params to pass to the view_submission
1365 * page (the current page)
1366 * @return string The summary with an optional link
1368 private function format_plugin_summary_with_link(assign_plugin
$plugin,
1373 $showviewlink = false;
1375 $summary = $plugin->view_summary($item, $showviewlink);
1377 if ($showviewlink) {
1378 $viewstr = get_string('view' . substr($plugin->get_subtype(), strlen('assign')), 'assign');
1379 $icon = $this->output
->pix_icon('t/preview', $viewstr);
1380 $urlparams = array('id' => $this->assignment
->get_course_module()->id
,
1383 'plugin'=>$plugin->get_type(),
1384 'action'=>'viewplugin' . $plugin->get_subtype(),
1385 'returnaction'=>$returnaction,
1386 'returnparams'=>http_build_query($returnparams));
1387 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1388 $link = $this->output
->action_link($url, $icon);
1389 $separator = $this->output
->spacer(array(), true);
1392 return $link . $separator . $summary;
1397 * Format the submission and feedback columns.
1399 * @param string $colname The column name
1400 * @param stdClass $row The submission row
1401 * @return mixed string or NULL
1403 public function other_cols($colname, $row) {
1404 // For extra user fields the result is already in $row.
1405 if (empty($this->plugincache
[$colname])) {
1406 return $row->$colname;
1409 // This must be a plugin field.
1410 $plugincache = $this->plugincache
[$colname];
1412 $plugin = $plugincache[0];
1415 if (isset($plugincache[1])) {
1416 $field = $plugincache[1];
1419 if ($plugin->is_visible() && $plugin->is_enabled()) {
1420 if ($plugin->get_subtype() == 'assignsubmission') {
1421 if ($this->assignment
->get_instance()->teamsubmission
) {
1423 $submission = false;
1425 $this->get_group_and_submission($row->id
, $group, $submission, -1);
1427 if ($submission->status
== ASSIGN_SUBMISSION_STATUS_REOPENED
) {
1428 // For a newly reopened submission - we want to show the previous submission in the table.
1429 $this->get_group_and_submission($row->id
, $group, $submission, $submission->attemptnumber
-1);
1431 if (isset($field)) {
1432 return $plugin->get_editor_text($field, $submission->id
);
1434 return $this->format_plugin_summary_with_link($plugin,
1439 } else if ($row->submissionid
) {
1440 if ($row->status
== ASSIGN_SUBMISSION_STATUS_REOPENED
) {
1441 // For a newly reopened submission - we want to show the previous submission in the table.
1442 $submission = $this->assignment
->get_user_submission($row->userid
, false, $row->attemptnumber
- 1);
1444 $submission = new stdClass();
1445 $submission->id
= $row->submissionid
;
1446 $submission->timecreated
= $row->firstsubmission
;
1447 $submission->timemodified
= $row->timesubmitted
;
1448 $submission->assignment
= $this->assignment
->get_instance()->id
;
1449 $submission->userid
= $row->userid
;
1450 $submission->attemptnumber
= $row->attemptnumber
;
1452 // Field is used for only for import/export and refers the the fieldname for the text editor.
1453 if (isset($field)) {
1454 return $plugin->get_editor_text($field, $submission->id
);
1456 return $this->format_plugin_summary_with_link($plugin,
1463 if (isset($field)) {
1464 return $plugin->get_editor_text($field, $row->gradeid
);
1467 if ($row->gradeid
) {
1468 $grade = new stdClass();
1469 $grade->id
= $row->gradeid
;
1470 $grade->timecreated
= $row->firstmarked
;
1471 $grade->timemodified
= $row->timemarked
;
1472 $grade->assignment
= $this->assignment
->get_instance()->id
;
1473 $grade->userid
= $row->userid
;
1474 $grade->grade
= $row->grade
;
1475 $grade->mailed
= $row->mailed
;
1476 $grade->attemptnumber
= $row->attemptnumber
;
1478 if ($this->quickgrading
&& $plugin->supports_quickgrading()) {
1479 return $plugin->get_quickgrading_html($row->userid
, $grade);
1480 } else if ($grade) {
1481 return $this->format_plugin_summary_with_link($plugin,
1492 * Using the current filtering and sorting - load all rows and return a single column from them.
1494 * @param string $columnname The name of the raw column data
1495 * @return array of data
1497 public function get_column_data($columnname) {
1499 $this->currpage
= 0;
1500 $this->query_db($this->tablemaxrows
);
1502 foreach ($this->rawdata
as $row) {
1503 $result[] = $row->$columnname;
1509 * Return things to the renderer.
1511 * @return string the assignment name
1513 public function get_assignment_name() {
1514 return $this->assignment
->get_instance()->name
;
1518 * Return things to the renderer.
1520 * @return int the course module id
1522 public function get_course_module_id() {
1523 return $this->assignment
->get_course_module()->id
;
1527 * Return things to the renderer.
1529 * @return int the course id
1531 public function get_course_id() {
1532 return $this->assignment
->get_course()->id
;
1536 * Return things to the renderer.
1538 * @return stdClass The course context
1540 public function get_course_context() {
1541 return $this->assignment
->get_course_context();
1545 * Return things to the renderer.
1547 * @return bool Does this assignment accept submissions
1549 public function submissions_enabled() {
1550 return $this->assignment
->is_any_submission_plugin_enabled();
1554 * Return things to the renderer.
1556 * @return bool Can this user view all grades (the gradebook)
1558 public function can_view_all_grades() {
1559 $context = $this->assignment
->get_course_context();
1560 return has_capability('gradereport/grader:view', $context) &&
1561 has_capability('moodle/grade:viewall', $context);
1565 * Always return a valid sort - even if the userid column is missing.
1566 * @return array column name => SORT_... constant.
1568 public function get_sort_columns() {
1569 $result = parent
::get_sort_columns();
1571 $assignment = $this->assignment
->get_instance();
1572 if (empty($assignment->blindmarking
)) {
1573 $result = array_merge($result, array('userid' => SORT_ASC
));
1575 $result = array_merge($result, [
1576 'COALESCE(s.timecreated, ' . time() . ')' => SORT_ASC
,
1577 'COALESCE(s.id, ' . PHP_INT_MAX
. ')' => SORT_ASC
,
1578 'um.id' => SORT_ASC
,
1585 * Override the table show_hide_link to not show for select column.
1587 * @param string $column the column name, index into various names.
1588 * @param int $index numerical index of the column.
1589 * @return string HTML fragment.
1591 protected function show_hide_link($column, $index) {
1592 if ($index > 0 ||
!$this->hasgrade
) {
1593 return parent
::show_hide_link($column, $index);
1599 * Overides setup to ensure it will only run a single time.
1601 public function setup() {
1602 // Check if the setup function has been called before, we should not run it twice.
1603 // If we do the sortorder of the table will be broken.
1604 if (!empty($this->setup
)) {