Merge branch 'MDL-36752-MOODLE_23_STABLE-2' of git://git.luns.net.uk/moodle into...
[moodle.git] / mod / assign / gradingtable.php
CommitLineData
bbd0e548
DW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * This file contains the definition for the grading table which subclassses easy_table
19 *
20 * @package mod_assign
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27require_once($CFG->libdir.'/tablelib.php');
28require_once($CFG->libdir.'/gradelib.php');
29require_once($CFG->dirroot.'/mod/assign/locallib.php');
30
31/**
32 * Extends table_sql to provide a table of assignment submissions
33 *
34 * @package mod_assign
35 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 */
38class assign_grading_table extends table_sql implements renderable {
39 /** @var assign $assignment */
40 private $assignment = null;
41 /** @var int $perpage */
42 private $perpage = 10;
43 /** @var int $rownum (global index of current row in table) */
44 private $rownum = -1;
45 /** @var renderer_base for getting output */
46 private $output = null;
47 /** @var stdClass gradinginfo */
48 private $gradinginfo = null;
49 /** @var int $tablemaxrows */
50 private $tablemaxrows = 10000;
bf78ebd6
DW
51 /** @var boolean $quickgrading */
52 private $quickgrading = false;
bbd0e548
DW
53
54 /**
55 * overridden constructor keeps a reference to the assignment class that is displaying this table
56 *
57 * @param assign $assignment The assignment class
58 * @param int $perpage how many per page
59 * @param string $filter The current filter
60 * @param int $rowoffset For showing a subsequent page of results
bf78ebd6 61 * @param bool $quickgrading Is this table wrapped in a quickgrading form?
bbd0e548 62 */
bf78ebd6 63 function __construct(assign $assignment, $perpage, $filter, $rowoffset, $quickgrading) {
a3dbdc2c 64 global $CFG, $PAGE, $DB;
bbd0e548
DW
65 parent::__construct('mod_assign_grading');
66 $this->assignment = $assignment;
67 $this->perpage = $perpage;
bf78ebd6 68 $this->quickgrading = $quickgrading;
bbd0e548
DW
69 $this->output = $PAGE->get_renderer('mod_assign');
70
71 $this->define_baseurl(new moodle_url($CFG->wwwroot . '/mod/assign/view.php', array('action'=>'grading', 'id'=>$assignment->get_course_module()->id)));
72
73 // do some business - then set the sql
74
75 $currentgroup = groups_get_activity_group($assignment->get_course_module(), true);
76
77 if ($rowoffset) {
78 $this->rownum = $rowoffset - 1;
79 }
80
81 $users = array_keys( $assignment->list_participants($currentgroup, true));
82 if (count($users) == 0) {
83 // insert a record that will never match to the sql is still valid.
84 $users[] = -1;
85 }
86
87 $params = array();
a3dbdc2c
DW
88 $params['assignmentid1'] = (int)$this->assignment->get_instance()->id;
89 $params['assignmentid2'] = (int)$this->assignment->get_instance()->id;
bbd0e548 90
d8e6e58e 91 $fields = user_picture::fields('u') . ', u.id as userid, ';
bbd0e548
DW
92 $fields .= 's.status as status, s.id as submissionid, s.timecreated as firstsubmission, s.timemodified as timesubmitted, ';
93 $fields .= 'g.id as gradeid, g.grade as grade, g.timemodified as timemarked, g.timecreated as firstmarked, g.mailed as mailed, g.locked as locked';
a3dbdc2c
DW
94 $from = '{user} u LEFT JOIN {assign_submission} s ON u.id = s.userid AND s.assignment = :assignmentid1' .
95 ' LEFT JOIN {assign_grades} g ON u.id = g.userid AND g.assignment = :assignmentid2';
bbd0e548
DW
96
97 $userparams = array();
a3dbdc2c
DW
98 $userindex = 0;
99
100 list($userwhere, $userparams) = $DB->get_in_or_equal($users, SQL_PARAMS_NAMED, 'user');
101 $where = 'u.id ' . $userwhere;
102 $params = array_merge($params, $userparams);
9682626e 103
bbd0e548
DW
104 if ($filter == ASSIGN_FILTER_SUBMITTED) {
105 $where .= ' AND s.timecreated > 0 ';
106 }
107 if ($filter == ASSIGN_FILTER_REQUIRE_GRADING) {
145a300b 108 $where .= ' AND (s.timemodified > g.timemodified OR (s.timemodified IS NOT NULL AND g.timemodified IS NULL))';
bbd0e548
DW
109 }
110 if (strpos($filter, ASSIGN_FILTER_SINGLE_USER) === 0) {
111 $userfilter = (int) array_pop(explode('=', $filter));
a3dbdc2c
DW
112 $where .= ' AND (u.id = :userid)';
113 $params['userid'] = $userfilter;
bbd0e548
DW
114 }
115 $this->set_sql($fields, $from, $where, $params);
116
117 $columns = array();
118 $headers = array();
119
120 // Select
bbd0e548 121 if (!$this->is_downloading()) {
b666bdda
DW
122 $columns[] = 'select';
123 $headers[] = get_string('select') . '<div class="selectall"><input type="checkbox" name="selectall" title="' . get_string('selectall') . '"/></div>';
bbd0e548
DW
124 }
125
126 // User picture
127 $columns[] = 'picture';
128 $headers[] = get_string('pictureofuser');
129
130 // Fullname
131 $columns[] = 'fullname';
132 $headers[] = get_string('fullname');
133
134 // Submission status
135 if ($assignment->is_any_submission_plugin_enabled()) {
136 $columns[] = 'status';
137 $headers[] = get_string('status');
138 }
139
140
141 // Grade
142 $columns[] = 'grade';
143 $headers[] = get_string('grade');
a5b62b8f
NK
144 if (!$this->is_downloading()) {
145 // We have to call this column userid so we can use userid as a default sortable column.
146 $columns[] = 'userid';
147 $headers[] = get_string('edit');
148 }
bbd0e548
DW
149
150 // Submission plugins
151 if ($assignment->is_any_submission_plugin_enabled()) {
152 $columns[] = 'timesubmitted';
153 $headers[] = get_string('lastmodifiedsubmission', 'assign');
154
155 foreach ($this->assignment->get_submission_plugins() as $plugin) {
156 if ($plugin->is_visible() && $plugin->is_enabled()) {
157 $columns[] = 'assignsubmission_' . $plugin->get_type();
158 $headers[] = $plugin->get_name();
159 }
160 }
161 }
162
163 // time marked
164 $columns[] = 'timemarked';
165 $headers[] = get_string('lastmodifiedgrade', 'assign');
166
167 // Feedback plugins
168 foreach ($this->assignment->get_feedback_plugins() as $plugin) {
169 if ($plugin->is_visible() && $plugin->is_enabled()) {
170 $columns[] = 'assignfeedback_' . $plugin->get_type();
171 $headers[] = $plugin->get_name();
172 }
173 }
174
175 // final grade
176 $columns[] = 'finalgrade';
177 $headers[] = get_string('finalgrade', 'grades');
178
a769a001
DW
179 // load the grading info for all users
180 $this->gradinginfo = grade_get_grades($this->assignment->get_course()->id, 'mod', 'assign', $this->assignment->get_instance()->id, $users);
181
182 if (!empty($CFG->enableoutcomes) && !empty($this->gradinginfo->outcomes)) {
183 $columns[] = 'outcomes';
184 $headers[] = get_string('outcomes', 'grades');
185 }
bbd0e548
DW
186
187
188 // set the columns
189 $this->define_columns($columns);
190 $this->define_headers($headers);
b666bdda
DW
191 // We require at least one unique column for the sort.
192 $this->sortable(true, 'userid');
bbd0e548 193 $this->no_sorting('finalgrade');
b666bdda 194 $this->no_sorting('userid');
bbd0e548 195 $this->no_sorting('select');
a769a001
DW
196 $this->no_sorting('outcomes');
197
bbd0e548
DW
198 foreach ($this->assignment->get_submission_plugins() as $plugin) {
199 if ($plugin->is_visible() && $plugin->is_enabled()) {
200 $this->no_sorting('assignsubmission_' . $plugin->get_type());
201 }
202 }
203 foreach ($this->assignment->get_feedback_plugins() as $plugin) {
204 if ($plugin->is_visible() && $plugin->is_enabled()) {
205 $this->no_sorting('assignfeedback_' . $plugin->get_type());
206 }
207 }
208
bbd0e548
DW
209 }
210
dc99b426
DW
211 /**
212 * Before adding each row to the table make sure rownum is incremented
213 *
214 * @param array $row row of data from db used to make one row of the table.
215 * @return array one row for the table
216 */
217 function format_row($row) {
218 if ($this->rownum < 0) {
219 $this->rownum = $this->currpage * $this->pagesize;
220 } else {
221 $this->rownum += 1;
222 }
223
224 return parent::format_row($row);
225 }
226
bbd0e548
DW
227 /**
228 * Add the userid to the row class so it can be updated via ajax
229 *
230 * @param stdClass $row The row of data
231 * @return string The row class
232 */
233 function get_row_class($row) {
234 return 'user' . $row->userid;
235 }
236
237 /**
238 * Return the number of rows to display on a single page
239 *
240 * @return int The number of rows per page
241 */
242 function get_rows_per_page() {
243 return $this->perpage;
244 }
245
246 /**
247 * Display a grade with scales etc.
248 *
249 * @param string $grade
bf78ebd6 250 * @param boolean $editable
2a4fbc32
SH
251 * @param int $userid The user id of the user this grade belongs to
252 * @param int $modified Timestamp showing when the grade was last modified
bbd0e548
DW
253 * @return string The formatted grade
254 */
bf78ebd6 255 function display_grade($grade, $editable, $userid, $modified) {
bbd0e548
DW
256 if ($this->is_downloading()) {
257 return $grade;
258 }
bf78ebd6 259 $o = $this->assignment->display_grade($grade, $editable, $userid, $modified);
bbd0e548
DW
260 return $o;
261 }
262
a769a001
DW
263 /**
264 * Format a list of outcomes
265 *
266 * @param stdClass $row
267 * @return string
268 */
269 function col_outcomes(stdClass $row) {
270 $outcomes = '';
271 foreach($this->gradinginfo->outcomes as $index=>$outcome) {
272 $options = make_grades_menu(-$outcome->scaleid);
273
274 $options[0] = get_string('nooutcome', 'grades');
2c6a3dbf 275 if ($this->quickgrading && !($outcome->grades[$row->userid]->locked)) {
bf78ebd6
DW
276 $select = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
277 foreach ($options as $optionindex => $optionvalue) {
278 $selected = '';
279 if ($outcome->grades[$row->userid]->grade == $optionindex) {
280 $selected = 'selected="selected"';
281 }
282 $select .= '<option value="' . $optionindex . '"' . $selected . '>' . $optionvalue . '</option>';
283 }
284 $select .= '</select>';
285 $outcomes .= $this->output->container($outcome->name . ': ' . $select, 'outcome');
286 } else {
287 $outcomes .= $this->output->container($outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade], 'outcome');
288 }
a769a001
DW
289 }
290
291 return $outcomes;
292 }
293
294
bbd0e548 295 /**
dc99b426 296 * Format a user picture for display
bbd0e548
DW
297 *
298 * @param stdClass $row
299 * @return string
300 */
301 function col_picture(stdClass $row) {
302 if ($row->picture) {
303 return $this->output->user_picture($row);
304 }
305 return '';
306 }
307
308 /**
8c74ab86 309 * Format a user record for display (link to profile)
bbd0e548
DW
310 *
311 * @param stdClass $row
312 * @return string
313 */
314 function col_fullname($row) {
8c74ab86
RW
315 $courseid = $this->assignment->get_course()->id;
316 $link= new moodle_url('/user/view.php', array('id' =>$row->id, 'course'=>$courseid));
317 return $this->output->action_link($link, fullname($row));
bbd0e548
DW
318 }
319
320 /**
321 * Insert a checkbox for selecting the current row for batch operations
322 *
323 * @param stdClass $row
324 * @return string
325 */
326 function col_select(stdClass $row) {
5382eabb 327 return '<input type="checkbox" name="selectedusers" value="' . $row->userid . '"/>';
bbd0e548
DW
328 }
329
330 /**
331 * Return a users grades from the listing of all grade data for this assignment
332 *
333 * @param int $userid
334 * @return mixed stdClass or false
335 */
336 private function get_gradebook_data_for_user($userid) {
337 if (isset($this->gradinginfo->items[0]) && $this->gradinginfo->items[0]->grades[$userid]) {
338 return $this->gradinginfo->items[0]->grades[$userid];
339 }
340 return false;
341 }
342
343 /**
344 * Format a column of data for display
345 *
346 * @param stdClass $row
347 * @return string
348 */
349 function col_grade(stdClass $row) {
350 $o = '';
351
352 $link = '';
353 $separator = '';
354 $grade = '';
355
356 if (!$this->is_downloading()) {
80238a3c
DW
357 $name = fullname($row);
358 $icon = $this->output->pix_icon('gradefeedback', get_string('gradeuser', 'assign', $name), 'mod_assign');
bbd0e548
DW
359 $url = new moodle_url('/mod/assign/view.php',
360 array('id' => $this->assignment->get_course_module()->id,
361 'rownum'=>$this->rownum,'action'=>'grade'));
362 $link = $this->output->action_link($url, $icon);
363 $separator = $this->output->spacer(array(), true);
364 }
09b46f0e
AA
365 $gradingdisabled = $this->assignment->grading_disabled($row->id);
366 $grade = $this->display_grade($row->grade, $this->quickgrading && !$gradingdisabled, $row->userid, $row->timemarked);
bbd0e548 367
bbd0e548
DW
368 //return $grade . $separator . $link;
369 return $link . $separator . $grade;
370 }
371
372 /**
373 * Format a column of data for display
374 *
375 * @param stdClass $row
376 * @return string
377 */
378 function col_finalgrade(stdClass $row) {
379 $o = '';
380
381 $grade = $this->get_gradebook_data_for_user($row->userid);
382 if ($grade) {
bf78ebd6 383 $o = $this->display_grade($grade->grade, false, $row->userid, $row->timemarked);
bbd0e548
DW
384 }
385
386 return $o;
387 }
388
389 /**
390 * Format a column of data for display
391 *
392 * @param stdClass $row
393 * @return string
394 */
395 function col_timemarked(stdClass $row) {
396 $o = '-';
397
99467a9f 398 if ($row->timemarked && $row->grade !== NULL && $row->grade >= 0) {
bbd0e548
DW
399 $o = userdate($row->timemarked);
400 }
401
402 return $o;
403 }
404
405 /**
406 * Format a column of data for display
407 *
408 * @param stdClass $row
409 * @return string
410 */
411 function col_timesubmitted(stdClass $row) {
412 $o = '-';
413
414 if ($row->timesubmitted) {
415 $o = userdate($row->timesubmitted);
416 }
417
418 return $o;
419 }
420
421 /**
422 * Format a column of data for display
423 *
424 * @param stdClass $row
425 * @return string
426 */
427 function col_status(stdClass $row) {
428 $o = '';
429
430 if ($this->assignment->is_any_submission_plugin_enabled()) {
431
432 $o .= $this->output->container(get_string('submissionstatus_' . $row->status, 'assign'), array('class'=>'submissionstatus' .$row->status));
433 if ($this->assignment->get_instance()->duedate && $row->timesubmitted > $this->assignment->get_instance()->duedate) {
434 $o .= $this->output->container(get_string('submittedlateshort', 'assign', format_time($row->timesubmitted - $this->assignment->get_instance()->duedate)), 'latesubmission');
435 }
436 if ($row->locked) {
437 $o .= $this->output->container(get_string('submissionslockedshort', 'assign'), 'lockedsubmission');
438 }
571cc0b7 439 if ($row->grade !== NULL && $row->grade >= 0) {
bbd0e548
DW
440 $o .= $this->output->container(get_string('graded', 'assign'), 'submissiongraded');
441 }
442 }
443
444 return $o;
445 }
446
447 /**
448 * Format a column of data for display
449 *
450 * @param stdClass $row
451 * @return string
452 */
b666bdda 453 function col_userid(stdClass $row) {
bbd0e548 454 $edit = '';
bbd0e548
DW
455
456 $actions = array();
457
458 $url = new moodle_url('/mod/assign/view.php',
459 array('id' => $this->assignment->get_course_module()->id,
460 'rownum'=>$this->rownum,'action'=>'grade'));
461 if (!$row->grade) {
462 $description = get_string('grade');
463 }else{
464 $description = get_string('updategrade','assign');
465 }
466 $actions[$url->out(false)] = $description;
467
468 if (!$row->status || $row->status == ASSIGN_SUBMISSION_STATUS_DRAFT || !$this->assignment->get_instance()->submissiondrafts) {
469 if (!$row->locked) {
470 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
471 'userid'=>$row->id,
472 'action'=>'lock',
473 'sesskey'=>sesskey(),
474 'page'=>$this->currpage));
475 $description = get_string('preventsubmissionsshort', 'assign');
476 $actions[$url->out(false)] = $description;
477 } else {
478 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
479 'userid'=>$row->id,
480 'action'=>'unlock',
481 'sesskey'=>sesskey(),
482 'page'=>$this->currpage));
483 $description = get_string('allowsubmissionsshort', 'assign');
484 $actions[$url->out(false)] = $description;
485 }
486 }
487 if ($row->status == ASSIGN_SUBMISSION_STATUS_SUBMITTED && $this->assignment->get_instance()->submissiondrafts) {
488 $url = new moodle_url('/mod/assign/view.php', array('id' => $this->assignment->get_course_module()->id,
489 'userid'=>$row->id,
490 'action'=>'reverttodraft',
491 'sesskey'=>sesskey(),
492 'page'=>$this->currpage));
493 $description = get_string('reverttodraftshort', 'assign');
494 $actions[$url->out(false)] = $description;
495 }
496
497 $edit .= $this->output->container_start(array('yui3-menu', 'actionmenu'), 'actionselect' . $row->id);
498 $edit .= $this->output->container_start(array('yui3-menu-content'));
499 $edit .= html_writer::start_tag('ul');
500 $edit .= html_writer::start_tag('li', array('class'=>'menuicon'));
501
502 $menuicon = $this->output->pix_icon('i/menu', get_string('actions'));
503 $edit .= $this->output->action_link('#menu' . $row->id, $menuicon, null, array('class'=>'yui3-menu-label'));
504 $edit .= $this->output->container_start(array('yui3-menu', 'yui3-loading'), 'menu' . $row->id);
505 $edit .= $this->output->container_start(array('yui3-menu-content'));
506 $edit .= html_writer::start_tag('ul');
507
508 foreach ($actions as $url => $description) {
509 $edit .= html_writer::start_tag('li', array('class'=>'yui3-menuitem'));
510
511 $edit .= $this->output->action_link($url, $description, null, array('class'=>'yui3-menuitem-content'));
512
513 $edit .= html_writer::end_tag('li');
514 }
515 $edit .= html_writer::end_tag('ul');
516 $edit .= $this->output->container_end();
517 $edit .= $this->output->container_end();
518 $edit .= html_writer::end_tag('li');
519 $edit .= html_writer::end_tag('ul');
520
521 $edit .= $this->output->container_end();
522 $edit .= $this->output->container_end();
523
524 return $edit;
525 }
526
527 /**
528 * Write the plugin summary with an optional link to view the full feedback/submission.
529 *
530 * @param assign_plugin $plugin Submission plugin or feedback plugin
531 * @param stdClass $item Submission or grade
532 * @param string $returnaction The return action to pass to the view_submission page (the current page)
533 * @param string $returnparams The return params to pass to the view_submission page (the current page)
534 * @return string The summary with an optional link
535 */
536 private function format_plugin_summary_with_link(assign_plugin $plugin, stdClass $item, $returnaction, $returnparams) {
537 $link = '';
538 $showviewlink = false;
2c6a3dbf 539
bbd0e548
DW
540 $summary = $plugin->view_summary($item, $showviewlink);
541 $separator = '';
542 if ($showviewlink) {
543 $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($plugin->get_subtype(), strlen('assign')), 'mod_assign'));
544 $link = $this->output->action_link(
545 new moodle_url('/mod/assign/view.php',
546 array('id' => $this->assignment->get_course_module()->id,
547 'sid'=>$item->id,
548 'gid'=>$item->id,
549 'plugin'=>$plugin->get_type(),
550 'action'=>'viewplugin' . $plugin->get_subtype(),
551 'returnaction'=>$returnaction,
552 'returnparams'=>http_build_query($returnparams))),
553 $icon);
554 $separator = $this->output->spacer(array(), true);
555 }
556
557 return $link . $separator . $summary;
558 }
559
560
561 /**
562 * Format the submission and feedback columns
563 *
564 * @param string $colname The column name
565 * @param stdClass $row The submission row
566 * @return mixed string or NULL
567 */
568 function other_cols($colname, $row){
569 if (($pos = strpos($colname, 'assignsubmission_')) !== false) {
570 $plugin = $this->assignment->get_submission_plugin_by_type(substr($colname, strlen('assignsubmission_')));
2c6a3dbf 571
bbd0e548
DW
572 if ($plugin->is_visible() && $plugin->is_enabled()) {
573 if ($row->submissionid) {
574 $submission = new stdClass();
575 $submission->id = $row->submissionid;
576 $submission->timecreated = $row->firstsubmission;
577 $submission->timemodified = $row->timesubmitted;
578 $submission->assignment = $this->assignment->get_instance()->id;
579 $submission->userid = $row->userid;
bbd0e548
DW
580 return $this->format_plugin_summary_with_link($plugin, $submission, 'grading', array());
581 }
582 }
583 return '';
584 }
585 if (($pos = strpos($colname, 'feedback_')) !== false) {
586 $plugin = $this->assignment->get_feedback_plugin_by_type(substr($colname, strlen('assignfeedback_')));
587 if ($plugin->is_visible() && $plugin->is_enabled()) {
2c6a3dbf 588 $grade = null;
bbd0e548
DW
589 if ($row->gradeid) {
590 $grade = new stdClass();
591 $grade->id = $row->gradeid;
592 $grade->timecreated = $row->firstmarked;
593 $grade->timemodified = $row->timemarked;
594 $grade->assignment = $this->assignment->get_instance()->id;
595 $grade->userid = $row->userid;
596 $grade->grade = $row->grade;
597 $grade->mailed = $row->mailed;
2c6a3dbf
DW
598 }
599 if ($this->quickgrading && $plugin->supports_quickgrading()) {
600 return $plugin->get_quickgrading_html($row->userid, $grade);
601 } else if ($grade) {
bbd0e548
DW
602 return $this->format_plugin_summary_with_link($plugin, $grade, 'grading', array());
603 }
604 }
605 return '';
606 }
607 return NULL;
608 }
609
610 /**
611 * Using the current filtering and sorting - load all rows and return a single column from them
612 *
613 * @param string $columnname The name of the raw column data
614 * @return array of data
615 */
616 function get_column_data($columnname) {
617 $this->setup();
618 $this->currpage = 0;
619 $this->query_db($this->tablemaxrows);
620 $result = array();
621 foreach ($this->rawdata as $row) {
622 $result[] = $row->$columnname;
623 }
624 return $result;
625 }
626 /**
627 * Using the current filtering and sorting - load a single row and return a single column from it
628 *
629 * @param int $rownumber The rownumber to load
630 * @param string $columnname The name of the raw column data
631 * @param bool $lastrow Set to true if this is the last row in the table
632 * @return mixed string or false
633 */
634 function get_cell_data($rownumber, $columnname, $lastrow) {
635 $this->setup();
636 $this->currpage = $rownumber;
637 $this->query_db(1);
638 if ($rownumber == $this->totalrows-1) {
639 $lastrow = true;
640 }
641 foreach ($this->rawdata as $row) {
642 return $row->$columnname;
643 }
644 return false;
645 }
646
647 /**
648 * Return things to the renderer
649 *
650 * @return string the assignment name
651 */
652 function get_assignment_name() {
653 return $this->assignment->get_instance()->name;
654 }
655
656 /**
657 * Return things to the renderer
658 *
659 * @return int the course module id
660 */
661 function get_course_module_id() {
662 return $this->assignment->get_course_module()->id;
663 }
664
665 /**
666 * Return things to the renderer
667 *
668 * @return int the course id
669 */
670 function get_course_id() {
671 return $this->assignment->get_course()->id;
672 }
673
674 /**
675 * Return things to the renderer
676 *
677 * @return stdClass The course context
678 */
679 function get_course_context() {
680 return $this->assignment->get_course_context();
681 }
682
683 /**
684 * Return things to the renderer
685 *
686 * @return bool Does this assignment accept submissions
687 */
688 function submissions_enabled() {
689 return $this->assignment->is_any_submission_plugin_enabled();
690 }
691
692 /**
693 * Return things to the renderer
694 *
695 * @return bool Can this user view all grades (the gradebook)
696 */
697 function can_view_all_grades() {
698 return has_capability('gradereport/grader:view', $this->assignment->get_course_context()) && has_capability('moodle/grade:viewall', $this->assignment->get_course_context());
699 }
700
701 /**
702 * Override the table show_hide_link to not show for select column
703 *
704 * @param string $column the column name, index into various names.
705 * @param int $index numerical index of the column.
706 * @return string HTML fragment.
707 */
708 protected function show_hide_link($column, $index) {
709 if ($index > 0) {
710 return parent::show_hide_link($column, $index);
711 }
712 return '';
713 }
714}