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 array $groupsubmissions - A static cache of group submissions */
56 private $groupsubmissions = array();
57 /** @var array $submissiongroups - A static cache of submission groups */
58 private $submissiongroups = array();
59 /** @var string $plugingradingbatchoperations - List of plugin supported batch operations */
60 public $plugingradingbatchoperations = array();
61 /** @var array $plugincache - A cache of plugin lookups to match a column name to a plugin efficiently */
62 private $plugincache = array();
63 /** @var array $scale - A list of the keys and descriptions for the custom scale */
64 private $scale = null;
67 * overridden constructor keeps a reference to the assignment class that is displaying this table
69 * @param assign $assignment The assignment class
70 * @param int $perpage how many per page
71 * @param string $filter The current filter
72 * @param int $rowoffset For showing a subsequent page of results
73 * @param bool $quickgrading Is this table wrapped in a quickgrading form?
75 public function __construct(assign $assignment, $perpage, $filter, $rowoffset, $quickgrading, $downloadfilename = null) {
76 global $CFG, $PAGE, $DB;
77 parent::__construct('mod_assign_grading');
78 $this->assignment = $assignment;
80 foreach ($assignment->get_feedback_plugins() as $plugin) {
81 if ($plugin->is_visible() && $plugin->is_enabled()) {
82 foreach ($plugin->get_grading_batch_operations() as $action => $description) {
83 if (empty($this->plugingradingbatchoperations)) {
84 $this->plugingradingbatchoperations[$plugin->get_type()] = array();
86 $this->plugingradingbatchoperations[$plugin->get_type()][$action] = $description;
90 $this->perpage = $perpage;
91 $this->quickgrading = $quickgrading;
92 $this->output = $PAGE->get_renderer('mod_assign');
94 $this->define_baseurl(new moodle_url($CFG->wwwroot . '/mod/assign/view.php', array('action'=>'grading', 'id'=>$assignment->get_course_module()->id)));
96 // do some business - then set the sql
98 $currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
101 $this->rownum = $rowoffset - 1;
104 $users = array_keys( $assignment->list_participants($currentgroup, true));
105 if (count($users) == 0) {
106 // insert a record that will never match to the sql is still valid.
111 $params['assignmentid1'] = (int)$this->assignment->get_instance()->id;
112 $params['assignmentid2'] = (int)$this->assignment->get_instance()->id;
114 $fields = user_picture::fields('u') . ', ';
115 $fields .= 'u.id as userid, ';
116 $fields .= 's.status as status, ';
117 $fields .= 's.id as submissionid, ';
118 $fields .= 's.timecreated as firstsubmission, ';
119 $fields .= 's.timemodified as timesubmitted, ';
120 $fields .= 'g.id as gradeid, ';
121 $fields .= 'g.grade as grade, ';
122 $fields .= 'g.timemodified as timemarked, ';
123 $fields .= 'g.timecreated as firstmarked, ';
124 $fields .= 'g.mailed as mailed, ';
125 $fields .= 'g.locked as locked, ';
126 $fields .= 'g.extensionduedate as extensionduedate';
127 $from = '{user} u LEFT JOIN {assign_submission} s ON u.id = s.userid AND s.assignment = :assignmentid1' .
128 ' LEFT JOIN {assign_grades} g ON u.id = g.userid AND g.assignment = :assignmentid2';
130 $userparams = array();
133 list($userwhere, $userparams) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED, 'user');
134 $where = 'u.id ' . $userwhere;
135 $params = array_merge($params, $userparams);
137 if ($filter == ASSIGN_FILTER_SUBMITTED) {
138 $where .= ' AND s.timecreated > 0 ';
140 if ($filter == ASSIGN_FILTER_REQUIRE_GRADING) {
141 $where .= ' AND (s.timemodified > g.timemodified OR (s.timemodified IS NOT NULL AND g.timemodified IS NULL))';
143 if (strpos($filter, ASSIGN_FILTER_SINGLE_USER) === 0) {
144 $userfilter = (int) array_pop(explode('=', $filter));
145 $where .= ' AND (u.id = :userid)';
146 $params['userid'] = $userfilter;
148 $this->set_sql($fields, $from, $where, $params);
150 if ($downloadfilename) {
151 $this->is_downloading('csv', $downloadfilename);
158 if (!$this->is_downloading()) {
159 $columns[] = 'select';
160 $headers[] = get_string('select') .
161 '<div class="selectall"><input type="checkbox" name="selectall" title="' .
162 get_string('selectall') .
167 if (!$this->assignment->is_blind_marking()) {
168 if (!$this->is_downloading()) {
169 $columns[] = 'picture';
170 $headers[] = get_string('pictureofuser');
172 $columns[] = 'recordid';
173 $headers[] = get_string('recordid', 'assign');
177 $columns[] = 'fullname';
178 $headers[] = get_string('fullname');
181 $columns[] = 'recordid';
182 $headers[] = get_string('recordid', 'assign');
186 if ($assignment->is_any_submission_plugin_enabled()) {
187 $columns[] = 'status';
188 $headers[] = get_string('status');
191 // Team submission columns
192 if ($assignment->get_instance()->teamsubmission) {
194 $headers[] = get_string('submissionteam', 'assign');
196 $columns[] = 'teamstatus';
197 $headers[] = get_string('teamsubmissionstatus', 'assign');
201 $columns[] = 'grade';
202 $headers[] = get_string('grade');
203 if ($this->is_downloading()) {
204 if ($this->assignment->get_instance()->grade >= 0) {
205 $columns[] = 'grademax';
206 $headers[] = get_string('maxgrade', 'assign');
208 // This is a custom scale.
209 $columns[] = 'scale';
210 $headers[] = get_string('scale', 'assign');
213 if (!$this->is_downloading()) {
214 // We have to call this column userid so we can use userid as a default sortable column.
215 $columns[] = 'userid';
216 $headers[] = get_string('edit');
219 // Submission plugins
220 if ($assignment->is_any_submission_plugin_enabled()) {
221 $columns[] = 'timesubmitted';
222 $headers[] = get_string('lastmodifiedsubmission', 'assign');
224 foreach ($this->assignment->get_submission_plugins() as $plugin) {
225 if ($this->is_downloading()) {
226 if ($plugin->is_visible() && $plugin->is_enabled()) {
227 foreach ($plugin->get_editor_fields() as $field => $description) {
228 $index = 'plugin' . count($this->plugincache);
229 $this->plugincache[$index] = array($plugin, $field);
231 $headers[] = $plugin->get_name();
235 if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
236 $index = 'plugin' . count($this->plugincache);
237 $this->plugincache[$index] = array($plugin);
239 $headers[] = $plugin->get_name();
246 $columns[] = 'timemarked';
247 $headers[] = get_string('lastmodifiedgrade', 'assign');
250 foreach ($this->assignment->get_feedback_plugins() as $plugin) {
251 if ($this->is_downloading()) {
252 if ($plugin->is_visible() && $plugin->is_enabled()) {
253 foreach ($plugin->get_editor_fields() as $field => $description) {
254 $index = 'plugin' . count($this->plugincache);
255 $this->plugincache[$index] = array($plugin, $field);
257 $headers[] = $description;
260 } else if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
261 $index = 'plugin' . count($this->plugincache);
262 $this->plugincache[$index] = array($plugin);
264 $headers[] = $plugin->get_name();
268 // Exclude 'Final grade' column in downloaded grading worksheets.
269 if (!$this->is_downloading()) {
271 $columns[] = 'finalgrade';
272 $headers[] = get_string('finalgrade', 'grades');
275 // load the grading info for all users
276 $this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users);
277 $this->hasgrantextension = has_capability('mod/assign:grantextension', $this->assignment->get_context());
279 if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) {
280 $columns[] = 'outcomes';
281 $headers[] = get_string('outcomes', 'grades');
286 $this->define_columns($columns);
287 $this->define_headers($headers);
288 // We require at least one unique column for the sort.
289 $this->sortable(true, 'userid');
290 $this->no_sorting('recordid');
291 $this->no_sorting('finalgrade');
292 $this->no_sorting('userid');
293 $this->no_sorting('select');
294 $this->no_sorting('outcomes');
296 if ($assignment->get_instance()->teamsubmission) {
297 $this->no_sorting('team');
298 $this->no_sorting('teamstatus');
301 $plugincolumnindex = 0;
302 foreach ($this->assignment->get_submission_plugins() as $plugin) {
303 if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
304 $submissionpluginindex = 'plugin' . $plugincolumnindex++;
305 $this->no_sorting($submissionpluginindex);
308 foreach ($this->assignment->get_feedback_plugins() as $plugin) {
309 if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
310 $feedbackpluginindex = 'plugin' . $plugincolumnindex++;
311 $this->no_sorting($feedbackpluginindex);
315 // When there is no data we still want the column headers printed in the csv file.
316 if ($this->is_downloading()) {
317 $this->start_output();
322 * Add a column with an ID that uniquely identifies this user in this assignment
326 function col_recordid(stdClass $row) {
327 return get_string('hiddenuser', 'assign') . $this->assignment->get_uniqueid_for_user($row->userid);
332 * Add the userid to the row class so it can be updated via ajax
334 * @param stdClass $row The row of data
335 * @return string The row class
337 function get_row_class($row) {
338 return 'user' . $row->userid;
342 * Return the number of rows to display on a single page
344 * @return int The number of rows per page
346 function get_rows_per_page() {
347 return $this->perpage;
351 * For download only - list all the valid options for this custom scale.
353 * @param stdClass $row - The row of data
354 * @return string A list of valid options for the current scale
356 public function col_scale($row) {
359 if (empty($this->scale)) {
360 $this->scale = $DB->get_record('scale', array('id'=>-($this->assignment->get_instance()->grade)));
363 if (!empty($this->scale->scale)) {
364 return implode("\n", explode(',', $this->scale->scale));
370 * Display a grade with scales etc.
372 * @param string $grade
373 * @param boolean $editable
374 * @param int $userid The user id of the user this grade belongs to
375 * @param int $modified Timestamp showing when the grade was last modified
376 * @return string The formatted grade
378 function display_grade($grade, $editable, $userid, $modified) {
379 if ($this->is_downloading()) {
380 if ($this->assignment->get_instance()->grade >= 0) {
381 if ($grade == -1 || $grade === null) {
384 return format_float($grade);
386 // This is a custom scale.
387 $scale = $this->assignment->display_grade($grade, false);
394 return $this->assignment->display_grade($grade, $editable, $userid, $modified);
398 * Get the team info for this user
400 * @param stdClass $row
401 * @return string The team name
403 function col_team(stdClass $row) {
406 $this->get_group_and_submission($row->id, $group, $submission);
410 return get_string('defaultteam', 'assign');
414 * Use a static cache to try and reduce DB calls.
416 * @param int $userid The user id for this submission
417 * @param int $groupid The groupid (returned)
418 * @param mixed $submission The stdClass submission or false (returned)
420 function get_group_and_submission($userid, &$group, &$submission) {
422 if (isset($this->submissiongroups[$userid])) {
423 $group = $this->submissiongroups[$userid];
425 $group = $this->assignment->get_submission_group($userid, false);
426 $this->submissiongroups[$userid] = $group;
431 $groupid = $group->id;
434 if (isset($this->groupsubmissions[$groupid])) {
435 $submission = $this->groupsubmissions[$groupid];
437 $submission = $this->assignment->get_group_submission($userid, $groupid, false);
438 $this->groupsubmissions[$groupid] = $submission;
444 * Get the team status for this user
446 * @param stdClass $row
447 * @return string The team name
449 function col_teamstatus(stdClass $row) {
452 $this->get_group_and_submission($row->id, $group, $submission);
456 $status = $submission->status;
458 return get_string('submissionstatus_' . $status, 'assign');
463 * Format a list of outcomes
465 * @param stdClass $row
468 function col_outcomes(stdClass $row) {
470 foreach($this->gradinginfo->outcomes as $index=>$outcome) {
471 $options = make_grades_menu(-$outcome->scaleid);
473 $options[0] = get_string('nooutcome', 'grades');
474 if ($this->quickgrading && !($outcome->grades[$row->userid]->locked)) {
475 $select = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
476 foreach ($options as $optionindex => $optionvalue) {
478 if ($outcome->grades[$row->userid]->grade == $optionindex) {
479 $selected = 'selected="selected"';
481 $select .= '<option value="' . $optionindex . '"' . $selected . '>' . $optionvalue . '</option>';
483 $select .= '</select>';
484 $outcomes .= $this->output->container($outcome->name . ': ' . $select, 'outcome');
486 $outcomes .= $this->output->container($outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade], 'outcome');
495 * Format a user picture for display (and update rownum as a sideeffect)
497 * @param stdClass $row
500 function col_picture(stdClass $row) {
502 return $this->output->user_picture($row);
508 * Format a user record for display (link to profile)
510 * @param stdClass $row
513 function col_fullname($row) {
514 if (!$this->is_downloading()) {
515 $courseid = $this->assignment->get_course()->id;
516 $link= new moodle_url('/user/view.php', array('id' =>$row->id, 'course'=>$courseid));
517 return $this->output->action_link($link, fullname($row));
519 return fullname($row);
524 * Insert a checkbox for selecting the current row for batch operations
526 * @param stdClass $row
529 function col_select(stdClass $row) {
530 return '<input type="checkbox" name="selectedusers" value="' . $row->userid . '"/>';
534 * Return a users grades from the listing of all grade data for this assignment
537 * @return mixed stdClass or false
539 private function get_gradebook_data_for_user($userid) {
540 if (isset($this->gradinginfo->items[0]) && $this->gradinginfo->items[0]->grades[$userid]) {
541 return $this->gradinginfo->items[0]->grades[$userid];
547 * Format a column of data for display
549 * @param stdClass $row
552 public function col_grademax(stdClass $row) {
553 return format_float($this->assignment->get_instance()->grade, 2);
557 * Format a column of data for display
559 * @param stdClass $row
562 function col_grade(stdClass $row) {
568 $gradingdisabled = $this->assignment->grading_disabled($row->id);
570 if (!$this->is_downloading()) {
571 $icon = $this->output->pix_icon('gradefeedback', get_string('grade'), 'mod_assign');
572 $url = new moodle_url('/mod/assign/view.php',
573 array('id' => $this->assignment->get_course_module()->id,
574 'rownum'=>$this->rownum,'action'=>'grade'));
575 $link = $this->output->action_link($url, $icon);
576 $separator = $this->output->spacer(array(), true);
578 $grade = $this->display_grade($row->grade, $this->quickgrading && !$gradingdisabled, $row->userid, $row->timemarked);
580 return $link . $separator . $grade;
584 * Format a column of data for display
586 * @param stdClass $row
589 function col_finalgrade(stdClass $row) {
592 $grade = $this->get_gradebook_data_for_user($row->userid);
594 $o = $this->display_grade($grade->grade, false, $row->userid, $row->timemarked);
601 * Format a column of data for display
603 * @param stdClass $row
606 function col_timemarked(stdClass $row) {
609 if ($row->timemarked && $row->grade !== NULL && $row->grade >= 0) {
610 $o = userdate($row->timemarked);
617 * Format a column of data for display
619 * @param stdClass $row
622 function col_timesubmitted(stdClass $row) {
625 if ($row->timesubmitted) {
626 $o = userdate($row->timesubmitted);
633 * Format a column of data for display
635 * @param stdClass $row
638 function col_status(stdClass $row) {
641 if ($this->assignment->is_any_submission_plugin_enabled()) {
643 $o .= $this->output->container(get_string('submissionstatus_' . $row->status, 'assign'),
644 array('class'=>'submissionstatus' .$row->status));
645 if ($this->assignment->get_instance()->duedate && $row->timesubmitted > $this->assignment->get_instance()->duedate) {
646 if (!$row->extensionduedate || $row->timesubmitted > $row->extensionduedate) {
647 $latemessage = get_string('submittedlateshort', 'assign',
648 format_time($row->timesubmitted - $this->assignment->get_instance()->duedate));
649 $o .= $this->output->container($latemessage, 'latesubmission');
653 $o .= $this->output->container(get_string('submissionslockedshort', 'assign'), 'lockedsubmission');
655 if ($row->grade !== NULL && $row->grade >= 0) {
656 $o .= $this->output->container(get_string('graded', 'assign'), 'submissiongraded');
658 if (!$row->timesubmitted) {
660 $due = $this->assignment->get_instance()->duedate;
661 if ($row->extensionduedate) {
662 $due = $row->extensionduedate;
664 if ($due && ($now > $due)) {
665 $o .= $this->output->container(get_string('overdue', 'assign', format_time($now - $due)), 'overduesubmission');
668 if ($row->extensionduedate) {
669 $o .= $this->output->container(get_string('userextensiondate', 'assign', userdate($row->extensionduedate)), 'extensiondate');
673 if ($this->is_downloading()) {
674 $o = strip_tags(str_replace('</div>', "\n", $o));
681 * Format a column of data for display
683 * @param stdClass $row
686 function col_userid(stdClass $row) {
688 if ($this->rownum < 0) {
689 $this->rownum = $this->currpage * $this->pagesize;
696 $url = new moodle_url('/mod/assign/view.php',
697 array('id' => $this->assignment->get_course_module()->id,
698 'rownum'=>$this->rownum,'action'=>'grade'));
700 $description = get_string('grade');
702 $description = get_string('updategrade','assign');
704 $actions[$url->out(false)] = $description;
706 // Hide for offline assignments.
707 if ($this->assignment->is_any_submission_plugin_enabled()) {
709 $row->status == ASSIGN_SUBMISSION_STATUS_DRAFT ||
710 !$this->assignment->get_instance()->submissiondrafts) {
713 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
716 'sesskey'=>sesskey(),
717 'page'=>$this->currpage));
718 $description = get_string('preventsubmissionsshort', 'assign');
719 $actions[$url->out(false)] = $description;
721 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
724 'sesskey'=>sesskey(),
725 'page'=>$this->currpage));
726 $description = get_string('allowsubmissionsshort', 'assign');
727 $actions[$url->out(false)] = $description;
731 if (($this->assignment->get_instance()->duedate ||
732 $this->assignment->get_instance()->cutoffdate) &&
733 $this->hasgrantextension) {
734 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
736 'action'=>'grantextension',
737 'sesskey'=>sesskey(),
738 'page'=>$this->currpage));
739 $description = get_string('grantextension', 'assign');
740 $actions[$url->out(false)] = $description;
744 if ($row->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED && $this->assignment->get_instance()->submissiondrafts) {
745 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
747 'action'=>'reverttodraft',
748 'sesskey'=>sesskey(),
749 'page'=>$this->currpage));
750 $description = get_string('reverttodraftshort', 'assign');
751 $actions[$url->out(false)] = $description;
754 $edit .= $this->output->container_start(array('yui3-menu', 'actionmenu'), 'actionselect' . $row->id);
755 $edit .= $this->output->container_start(array('yui3-menu-content'));
756 $edit .= html_writer::start_tag('ul');
757 $edit .= html_writer::start_tag('li', array('class'=>'menuicon'));
759 $menuicon = $this->output->pix_icon('i/menu', get_string('actions'));
760 $edit .= $this->output->action_link('#menu' . $row->id, $menuicon, null, array('class'=>'yui3-menu-label'));
761 $edit .= $this->output->container_start(array('yui3-menu', 'yui3-loading'), 'menu' . $row->id);
762 $edit .= $this->output->container_start(array('yui3-menu-content'));
763 $edit .= html_writer::start_tag('ul');
765 foreach ($actions as $url => $description) {
766 $edit .= html_writer::start_tag('li', array('class'=>'yui3-menuitem'));
768 $edit .= $this->output->action_link($url, $description, null, array('class'=>'yui3-menuitem-content'));
770 $edit .= html_writer::end_tag('li');
772 $edit .= html_writer::end_tag('ul');
773 $edit .= $this->output->container_end();
774 $edit .= $this->output->container_end();
775 $edit .= html_writer::end_tag('li');
776 $edit .= html_writer::end_tag('ul');
778 $edit .= $this->output->container_end();
779 $edit .= $this->output->container_end();
785 * Write the plugin summary with an optional link to view the full feedback/submission.
787 * @param assign_plugin $plugin Submission plugin or feedback plugin
788 * @param stdClass $item Submission or grade
789 * @param string $returnaction The return action to pass to the view_submission page (the current page)
790 * @param string $returnparams The return params to pass to the view_submission page (the current page)
791 * @return string The summary with an optional link
793 private function format_plugin_summary_with_link(assign_plugin $plugin, stdClass $item, $returnaction, $returnparams) {
795 $showviewlink = false;
797 $summary = $plugin->view_summary($item, $showviewlink);
800 $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($plugin->get_subtype(), strlen('assign')), 'mod_assign'));
801 $link = $this->output->action_link(
802 new moodle_url('/mod/assign/view.php',
803 array('id' => $this->assignment->get_course_module()->id,
806 'plugin'=>$plugin->get_type(),
807 'action'=>'viewplugin' . $plugin->get_subtype(),
808 'returnaction'=>$returnaction,
809 'returnparams'=>http_build_query($returnparams))),
811 $separator = $this->output->spacer(array(), true);
814 return $link . $separator . $summary;
819 * Format the submission and feedback columns
821 * @param string $colname The column name
822 * @param stdClass $row The submission row
823 * @return mixed string or NULL
825 function other_cols($colname, $row){
826 $plugincache = $this->plugincache[$colname];
828 $plugin = $plugincache[0];
831 if (isset($plugincache[1])) {
832 $field = $plugincache[1];
835 if ($plugin->is_visible() && $plugin->is_enabled()) {
836 if ($plugin->get_subtype() == 'assignsubmission') {
837 if ($this->assignment->get_instance()->teamsubmission) {
840 $this->get_group_and_submission($row->id, $group, $submission);
843 return $plugin->get_editor_text($field, $submission->id);
845 return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array());
847 } else if ($row->submissionid) {
849 return $plugin->get_editor_text($field, $row->submissionid);
851 $submission = new stdClass();
852 $submission->id = $row->submissionid;
853 $submission->timecreated = $row->firstsubmission;
854 $submission->timemodified = $row->timesubmitted;
855 $submission->assignment = $this->assignment->get_instance()->id;
856 $submission->userid = $row->userid;
857 return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array());
862 return $plugin->get_editor_text($field, $row->gradeid);
866 $grade = new stdClass();
867 $grade->id = $row->gradeid;
868 $grade->timecreated = $row->firstmarked;
869 $grade->timemodified = $row->timemarked;
870 $grade->assignment = $this->assignment->get_instance()->id;
871 $grade->userid = $row->userid;
872 $grade->grade = $row->grade;
873 $grade->mailed = $row->mailed;
875 if ($this->quickgrading && $plugin->supports_quickgrading()) {
876 return $plugin->get_quickgrading_html($row->userid, $grade);
878 return $this->format_plugin_summary_with_link($plugin, $grade, 'grading', array());
886 * Using the current filtering and sorting - load all rows and return a single column from them
888 * @param string $columnname The name of the raw column data
889 * @return array of data
891 function get_column_data($columnname) {
894 $this->query_db($this->tablemaxrows);
896 foreach ($this->rawdata as $row) {
897 $result[] = $row->$columnname;
902 * Using the current filtering and sorting - load a single row and return a single column from it
904 * @param int $rownumber The rownumber to load
905 * @param string $columnname The name of the raw column data
906 * @param bool $lastrow Set to true if this is the last row in the table
907 * @return mixed string or false
909 function get_cell_data($rownumber, $columnname, $lastrow) {
911 $this->currpage = $rownumber;
913 if ($rownumber == $this->totalrows-1) {
916 foreach ($this->rawdata as $row) {
917 return $row->$columnname;
923 * Return things to the renderer
925 * @return string the assignment name
927 function get_assignment_name() {
928 return $this->assignment->get_instance()->name;
932 * Return things to the renderer
934 * @return int the course module id
936 function get_course_module_id() {
937 return $this->assignment->get_course_module()->id;
941 * Return things to the renderer
943 * @return int the course id
945 function get_course_id() {
946 return $this->assignment->get_course()->id;
950 * Return things to the renderer
952 * @return stdClass The course context
954 function get_course_context() {
955 return $this->assignment->get_course_context();
959 * Return things to the renderer
961 * @return bool Does this assignment accept submissions
963 function submissions_enabled() {
964 return $this->assignment->is_any_submission_plugin_enabled();
968 * Return things to the renderer
970 * @return bool Can this user view all grades (the gradebook)
972 function can_view_all_grades() {
973 return has_capability('gradereport/grader:view', $this->assignment->get_course_context()) && has_capability('moodle/grade:viewall', $this->assignment->get_course_context());
977 * Override the table show_hide_link to not show for select column
979 * @param string $column the column name, index into various names.
980 * @param int $index numerical index of the column.
981 * @return string HTML fragment.
983 protected function show_hide_link($column, $index) {
985 return parent::show_hide_link($column, $index);