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"><label class="accesshide" for="selectall">' . get_string('selectall') . '</label>
162 <input type="checkbox" id="selectall" name="selectall" title="' . get_string('selectall') . '"/></div>';
166 if (!$this->assignment->is_blind_marking()) {
167 if (!$this->is_downloading()) {
168 $columns[] = 'picture';
169 $headers[] = get_string('pictureofuser');
171 $columns[] = 'recordid';
172 $headers[] = get_string('recordid', 'assign');
176 $columns[] = 'fullname';
177 $headers[] = get_string('fullname');
180 $columns[] = 'recordid';
181 $headers[] = get_string('recordid', 'assign');
185 if ($assignment->is_any_submission_plugin_enabled()) {
186 $columns[] = 'status';
187 $headers[] = get_string('status');
190 // Team submission columns
191 if ($assignment->get_instance()->teamsubmission) {
193 $headers[] = get_string('submissionteam', 'assign');
195 $columns[] = 'teamstatus';
196 $headers[] = get_string('teamsubmissionstatus', 'assign');
200 $columns[] = 'grade';
201 $headers[] = get_string('grade');
202 if ($this->is_downloading()) {
203 if ($this->assignment->get_instance()->grade >= 0) {
204 $columns[] = 'grademax';
205 $headers[] = get_string('maxgrade', 'assign');
207 // This is a custom scale.
208 $columns[] = 'scale';
209 $headers[] = get_string('scale', 'assign');
212 if (!$this->is_downloading()) {
213 // We have to call this column userid so we can use userid as a default sortable column.
214 $columns[] = 'userid';
215 $headers[] = get_string('edit');
218 // Submission plugins
219 if ($assignment->is_any_submission_plugin_enabled()) {
220 $columns[] = 'timesubmitted';
221 $headers[] = get_string('lastmodifiedsubmission', 'assign');
223 foreach ($this->assignment->get_submission_plugins() as $plugin) {
224 if ($this->is_downloading()) {
225 if ($plugin->is_visible() && $plugin->is_enabled()) {
226 foreach ($plugin->get_editor_fields() as $field => $description) {
227 $index = 'plugin' . count($this->plugincache);
228 $this->plugincache[$index] = array($plugin, $field);
230 $headers[] = $plugin->get_name();
234 if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
235 $index = 'plugin' . count($this->plugincache);
236 $this->plugincache[$index] = array($plugin);
238 $headers[] = $plugin->get_name();
245 $columns[] = 'timemarked';
246 $headers[] = get_string('lastmodifiedgrade', 'assign');
249 foreach ($this->assignment->get_feedback_plugins() as $plugin) {
250 if ($this->is_downloading()) {
251 if ($plugin->is_visible() && $plugin->is_enabled()) {
252 foreach ($plugin->get_editor_fields() as $field => $description) {
253 $index = 'plugin' . count($this->plugincache);
254 $this->plugincache[$index] = array($plugin, $field);
256 $headers[] = $description;
259 } else if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
260 $index = 'plugin' . count($this->plugincache);
261 $this->plugincache[$index] = array($plugin);
263 $headers[] = $plugin->get_name();
267 // Exclude 'Final grade' column in downloaded grading worksheets.
268 if (!$this->is_downloading()) {
270 $columns[] = 'finalgrade';
271 $headers[] = get_string('finalgrade', 'grades');
274 // load the grading info for all users
275 $this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users);
276 $this->hasgrantextension = has_capability('mod/assign:grantextension', $this->assignment->get_context());
278 if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) {
279 $columns[] = 'outcomes';
280 $headers[] = get_string('outcomes', 'grades');
285 $this->define_columns($columns);
286 $this->define_headers($headers);
287 // We require at least one unique column for the sort.
288 $this->sortable(true, 'userid');
289 $this->no_sorting('recordid');
290 $this->no_sorting('finalgrade');
291 $this->no_sorting('userid');
292 $this->no_sorting('select');
293 $this->no_sorting('outcomes');
295 if ($assignment->get_instance()->teamsubmission) {
296 $this->no_sorting('team');
297 $this->no_sorting('teamstatus');
300 $plugincolumnindex = 0;
301 foreach ($this->assignment->get_submission_plugins() as $plugin) {
302 if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
303 $submissionpluginindex = 'plugin' . $plugincolumnindex++;
304 $this->no_sorting($submissionpluginindex);
307 foreach ($this->assignment->get_feedback_plugins() as $plugin) {
308 if ($plugin->is_visible() && $plugin->is_enabled() && $plugin->has_user_summary()) {
309 $feedbackpluginindex = 'plugin' . $plugincolumnindex++;
310 $this->no_sorting($feedbackpluginindex);
314 // When there is no data we still want the column headers printed in the csv file.
315 if ($this->is_downloading()) {
316 $this->start_output();
321 * Add a column with an ID that uniquely identifies this user in this assignment
325 function col_recordid(stdClass $row) {
326 return get_string('hiddenuser', 'assign') . $this->assignment->get_uniqueid_for_user($row->userid);
331 * Add the userid to the row class so it can be updated via ajax
333 * @param stdClass $row The row of data
334 * @return string The row class
336 function get_row_class($row) {
337 return 'user' . $row->userid;
341 * Return the number of rows to display on a single page
343 * @return int The number of rows per page
345 function get_rows_per_page() {
346 return $this->perpage;
350 * For download only - list all the valid options for this custom scale.
352 * @param stdClass $row - The row of data
353 * @return string A list of valid options for the current scale
355 public function col_scale($row) {
358 if (empty($this->scale)) {
359 $this->scale = $DB->get_record('scale', array('id'=>-($this->assignment->get_instance()->grade)));
362 if (!empty($this->scale->scale)) {
363 return implode("\n", explode(',', $this->scale->scale));
369 * Display a grade with scales etc.
371 * @param string $grade
372 * @param boolean $editable
373 * @param int $userid The user id of the user this grade belongs to
374 * @param int $modified Timestamp showing when the grade was last modified
375 * @return string The formatted grade
377 function display_grade($grade, $editable, $userid, $modified) {
378 if ($this->is_downloading()) {
379 if ($this->assignment->get_instance()->grade >= 0) {
380 if ($grade == -1 || $grade === null) {
383 return format_float($grade);
385 // This is a custom scale.
386 $scale = $this->assignment->display_grade($grade, false);
393 return $this->assignment->display_grade($grade, $editable, $userid, $modified);
397 * Get the team info for this user
399 * @param stdClass $row
400 * @return string The team name
402 function col_team(stdClass $row) {
405 $this->get_group_and_submission($row->id, $group, $submission);
409 return get_string('defaultteam', 'assign');
413 * Use a static cache to try and reduce DB calls.
415 * @param int $userid The user id for this submission
416 * @param int $groupid The groupid (returned)
417 * @param mixed $submission The stdClass submission or false (returned)
419 function get_group_and_submission($userid, &$group, &$submission) {
421 if (isset($this->submissiongroups[$userid])) {
422 $group = $this->submissiongroups[$userid];
424 $group = $this->assignment->get_submission_group($userid, false);
425 $this->submissiongroups[$userid] = $group;
430 $groupid = $group->id;
433 if (isset($this->groupsubmissions[$groupid])) {
434 $submission = $this->groupsubmissions[$groupid];
436 $submission = $this->assignment->get_group_submission($userid, $groupid, false);
437 $this->groupsubmissions[$groupid] = $submission;
443 * Get the team status for this user
445 * @param stdClass $row
446 * @return string The team name
448 function col_teamstatus(stdClass $row) {
451 $this->get_group_and_submission($row->id, $group, $submission);
455 $status = $submission->status;
457 return get_string('submissionstatus_' . $status, 'assign');
462 * Format a list of outcomes
464 * @param stdClass $row
467 function col_outcomes(stdClass $row) {
469 foreach($this->gradinginfo->outcomes as $index=>$outcome) {
470 $options = make_grades_menu(-$outcome->scaleid);
472 $options[0] = get_string('nooutcome', 'grades');
473 if ($this->quickgrading && !($outcome->grades[$row->userid]->locked)) {
474 $select = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
475 foreach ($options as $optionindex => $optionvalue) {
477 if ($outcome->grades[$row->userid]->grade == $optionindex) {
478 $selected = 'selected="selected"';
480 $select .= '<option value="' . $optionindex . '"' . $selected . '>' . $optionvalue . '</option>';
482 $select .= '</select>';
483 $outcomes .= $this->output->container($outcome->name . ': ' . $select, 'outcome');
485 $outcomes .= $this->output->container($outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade], 'outcome');
494 * Format a user picture for display (and update rownum as a sideeffect)
496 * @param stdClass $row
499 function col_picture(stdClass $row) {
501 return $this->output->user_picture($row);
507 * Format a user record for display (link to profile)
509 * @param stdClass $row
512 function col_fullname($row) {
513 if (!$this->is_downloading()) {
514 $courseid = $this->assignment->get_course()->id;
515 $link= new moodle_url('/user/view.php', array('id' =>$row->id, 'course'=>$courseid));
516 return $this->output->action_link($link, fullname($row));
518 return fullname($row);
523 * Insert a checkbox for selecting the current row for batch operations
525 * @param stdClass $row
528 function col_select(stdClass $row) {
529 return '<label class="accesshide" for="selectuser_' . $row->userid . '">' .
530 get_string('selectuser', 'assign', fullname($row)) . '</label>
531 <input type="checkbox" id="selectuser_' . $row->userid . '" name="selectedusers" value="' . $row->userid . '"/>';
535 * Return a users grades from the listing of all grade data for this assignment
538 * @return mixed stdClass or false
540 private function get_gradebook_data_for_user($userid) {
541 if (isset($this->gradinginfo->items[0]) && $this->gradinginfo->items[0]->grades[$userid]) {
542 return $this->gradinginfo->items[0]->grades[$userid];
548 * Format a column of data for display
550 * @param stdClass $row
553 public function col_grademax(stdClass $row) {
554 return format_float($this->assignment->get_instance()->grade, 2);
558 * Format a column of data for display
560 * @param stdClass $row
563 function col_grade(stdClass $row) {
569 $gradingdisabled = $this->assignment->grading_disabled($row->id);
571 if (!$this->is_downloading()) {
572 $icon = $this->output->pix_icon('gradefeedback', get_string('grade'), 'mod_assign');
573 $url = new moodle_url('/mod/assign/view.php',
574 array('id' => $this->assignment->get_course_module()->id,
575 'rownum'=>$this->rownum,'action'=>'grade'));
576 $link = $this->output->action_link($url, $icon);
577 $separator = $this->output->spacer(array(), true);
579 $grade = $this->display_grade($row->grade, $this->quickgrading && !$gradingdisabled, $row->userid, $row->timemarked);
581 return $link . $separator . $grade;
585 * Format a column of data for display
587 * @param stdClass $row
590 function col_finalgrade(stdClass $row) {
593 $grade = $this->get_gradebook_data_for_user($row->userid);
595 $o = $this->display_grade($grade->grade, false, $row->userid, $row->timemarked);
602 * Format a column of data for display
604 * @param stdClass $row
607 function col_timemarked(stdClass $row) {
610 if ($row->timemarked && $row->grade !== NULL && $row->grade >= 0) {
611 $o = userdate($row->timemarked);
618 * Format a column of data for display
620 * @param stdClass $row
623 function col_timesubmitted(stdClass $row) {
626 if ($row->timesubmitted) {
627 $o = userdate($row->timesubmitted);
634 * Format a column of data for display
636 * @param stdClass $row
639 function col_status(stdClass $row) {
642 if ($this->assignment->is_any_submission_plugin_enabled()) {
644 $o .= $this->output->container(get_string('submissionstatus_' . $row->status, 'assign'),
645 array('class'=>'submissionstatus' .$row->status));
646 if ($this->assignment->get_instance()->duedate && $row->timesubmitted > $this->assignment->get_instance()->duedate) {
647 if (!$row->extensionduedate || $row->timesubmitted > $row->extensionduedate) {
648 $latemessage = get_string('submittedlateshort', 'assign',
649 format_time($row->timesubmitted - $this->assignment->get_instance()->duedate));
650 $o .= $this->output->container($latemessage, 'latesubmission');
654 $o .= $this->output->container(get_string('submissionslockedshort', 'assign'), 'lockedsubmission');
656 if ($row->grade !== NULL && $row->grade >= 0) {
657 $o .= $this->output->container(get_string('graded', 'assign'), 'submissiongraded');
659 if (!$row->timesubmitted) {
661 $due = $this->assignment->get_instance()->duedate;
662 if ($row->extensionduedate) {
663 $due = $row->extensionduedate;
665 if ($due && ($now > $due)) {
666 $o .= $this->output->container(get_string('overdue', 'assign', format_time($now - $due)), 'overduesubmission');
669 if ($row->extensionduedate) {
670 $o .= $this->output->container(get_string('userextensiondate', 'assign', userdate($row->extensionduedate)), 'extensiondate');
674 if ($this->is_downloading()) {
675 $o = strip_tags(str_replace('</div>', "\n", $o));
682 * Format a column of data for display
684 * @param stdClass $row
687 function col_userid(stdClass $row) {
689 if ($this->rownum < 0) {
690 $this->rownum = $this->currpage * $this->pagesize;
697 $url = new moodle_url('/mod/assign/view.php',
698 array('id' => $this->assignment->get_course_module()->id,
699 'rownum'=>$this->rownum,'action'=>'grade'));
701 $description = get_string('grade');
703 $description = get_string('updategrade','assign');
705 $actions[$url->out(false)] = $description;
707 // Hide for offline assignments.
708 if ($this->assignment->is_any_submission_plugin_enabled()) {
710 $row->status == ASSIGN_SUBMISSION_STATUS_DRAFT ||
711 !$this->assignment->get_instance()->submissiondrafts) {
714 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
717 'sesskey'=>sesskey(),
718 'page'=>$this->currpage));
719 $description = get_string('preventsubmissionsshort', 'assign');
720 $actions[$url->out(false)] = $description;
722 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
725 'sesskey'=>sesskey(),
726 'page'=>$this->currpage));
727 $description = get_string('allowsubmissionsshort', 'assign');
728 $actions[$url->out(false)] = $description;
732 if (($this->assignment->get_instance()->duedate ||
733 $this->assignment->get_instance()->cutoffdate) &&
734 $this->hasgrantextension) {
735 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
737 'action'=>'grantextension',
738 'sesskey'=>sesskey(),
739 'page'=>$this->currpage));
740 $description = get_string('grantextension', 'assign');
741 $actions[$url->out(false)] = $description;
745 if ($row->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED && $this->assignment->get_instance()->submissiondrafts) {
746 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
748 'action'=>'reverttodraft',
749 'sesskey'=>sesskey(),
750 'page'=>$this->currpage));
751 $description = get_string('reverttodraftshort', 'assign');
752 $actions[$url->out(false)] = $description;
755 $edit .= $this->output->container_start(array('yui3-menu', 'actionmenu'), 'actionselect' . $row->id);
756 $edit .= $this->output->container_start(array('yui3-menu-content'));
757 $edit .= html_writer::start_tag('ul');
758 $edit .= html_writer::start_tag('li', array('class'=>'menuicon'));
760 $menuicon = $this->output->pix_icon('i/menu', get_string('actions'));
761 $edit .= $this->output->action_link('#menu' . $row->id, $menuicon, null, array('class'=>'yui3-menu-label'));
762 $edit .= $this->output->container_start(array('yui3-menu', 'yui3-loading'), 'menu' . $row->id);
763 $edit .= $this->output->container_start(array('yui3-menu-content'));
764 $edit .= html_writer::start_tag('ul');
766 foreach ($actions as $url => $description) {
767 $edit .= html_writer::start_tag('li', array('class'=>'yui3-menuitem'));
769 $edit .= $this->output->action_link($url, $description, null, array('class'=>'yui3-menuitem-content'));
771 $edit .= html_writer::end_tag('li');
773 $edit .= html_writer::end_tag('ul');
774 $edit .= $this->output->container_end();
775 $edit .= $this->output->container_end();
776 $edit .= html_writer::end_tag('li');
777 $edit .= html_writer::end_tag('ul');
779 $edit .= $this->output->container_end();
780 $edit .= $this->output->container_end();
786 * Write the plugin summary with an optional link to view the full feedback/submission.
788 * @param assign_plugin $plugin Submission plugin or feedback plugin
789 * @param stdClass $item Submission or grade
790 * @param string $returnaction The return action to pass to the view_submission page (the current page)
791 * @param string $returnparams The return params to pass to the view_submission page (the current page)
792 * @return string The summary with an optional link
794 private function format_plugin_summary_with_link(assign_plugin $plugin, stdClass $item, $returnaction, $returnparams) {
796 $showviewlink = false;
798 $summary = $plugin->view_summary($item, $showviewlink);
801 $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($plugin->get_subtype(), strlen('assign')), 'mod_assign'));
802 $link = $this->output->action_link(
803 new moodle_url('/mod/assign/view.php',
804 array('id' => $this->assignment->get_course_module()->id,
807 'plugin'=>$plugin->get_type(),
808 'action'=>'viewplugin' . $plugin->get_subtype(),
809 'returnaction'=>$returnaction,
810 'returnparams'=>http_build_query($returnparams))),
812 $separator = $this->output->spacer(array(), true);
815 return $link . $separator . $summary;
820 * Format the submission and feedback columns
822 * @param string $colname The column name
823 * @param stdClass $row The submission row
824 * @return mixed string or NULL
826 function other_cols($colname, $row){
827 $plugincache = $this->plugincache[$colname];
829 $plugin = $plugincache[0];
832 if (isset($plugincache[1])) {
833 $field = $plugincache[1];
836 if ($plugin->is_visible() && $plugin->is_enabled()) {
837 if ($plugin->get_subtype() == 'assignsubmission') {
838 if ($this->assignment->get_instance()->teamsubmission) {
841 $this->get_group_and_submission($row->id, $group, $submission);
844 return $plugin->get_editor_text($field, $submission->id);
846 return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array());
848 } else if ($row->submissionid) {
850 return $plugin->get_editor_text($field, $row->submissionid);
852 $submission = new stdClass();
853 $submission->id = $row->submissionid;
854 $submission->timecreated = $row->firstsubmission;
855 $submission->timemodified = $row->timesubmitted;
856 $submission->assignment = $this->assignment->get_instance()->id;
857 $submission->userid = $row->userid;
858 return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array());
863 return $plugin->get_editor_text($field, $row->gradeid);
867 $grade = new stdClass();
868 $grade->id = $row->gradeid;
869 $grade->timecreated = $row->firstmarked;
870 $grade->timemodified = $row->timemarked;
871 $grade->assignment = $this->assignment->get_instance()->id;
872 $grade->userid = $row->userid;
873 $grade->grade = $row->grade;
874 $grade->mailed = $row->mailed;
876 if ($this->quickgrading && $plugin->supports_quickgrading()) {
877 return $plugin->get_quickgrading_html($row->userid, $grade);
879 return $this->format_plugin_summary_with_link($plugin, $grade, 'grading', array());
887 * Using the current filtering and sorting - load all rows and return a single column from them
889 * @param string $columnname The name of the raw column data
890 * @return array of data
892 function get_column_data($columnname) {
895 $this->query_db($this->tablemaxrows);
897 foreach ($this->rawdata as $row) {
898 $result[] = $row->$columnname;
903 * Using the current filtering and sorting - load a single row and return a single column from it
905 * @param int $rownumber The rownumber to load
906 * @param string $columnname The name of the raw column data
907 * @param bool $lastrow Set to true if this is the last row in the table
908 * @return mixed string or false
910 function get_cell_data($rownumber, $columnname, $lastrow) {
912 $this->currpage = $rownumber;
914 if ($rownumber == $this->totalrows-1) {
917 foreach ($this->rawdata as $row) {
918 return $row->$columnname;
924 * Return things to the renderer
926 * @return string the assignment name
928 function get_assignment_name() {
929 return $this->assignment->get_instance()->name;
933 * Return things to the renderer
935 * @return int the course module id
937 function get_course_module_id() {
938 return $this->assignment->get_course_module()->id;
942 * Return things to the renderer
944 * @return int the course id
946 function get_course_id() {
947 return $this->assignment->get_course()->id;
951 * Return things to the renderer
953 * @return stdClass The course context
955 function get_course_context() {
956 return $this->assignment->get_course_context();
960 * Return things to the renderer
962 * @return bool Does this assignment accept submissions
964 function submissions_enabled() {
965 return $this->assignment->is_any_submission_plugin_enabled();
969 * Return things to the renderer
971 * @return bool Can this user view all grades (the gradebook)
973 function can_view_all_grades() {
974 return has_capability('gradereport/grader:view', $this->assignment->get_course_context()) && has_capability('moodle/grade:viewall', $this->assignment->get_course_context());
978 * Override the table show_hide_link to not show for select column
980 * @param string $column the column name, index into various names.
981 * @param int $index numerical index of the column.
982 * @return string HTML fragment.
984 protected function show_hide_link($column, $index) {
986 return parent::show_hide_link($column, $index);