MDL-50526 mod_assign: Highlight error message when user has no group
[moodle.git] / mod / assign / renderer.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 a renderer for the assignment class
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
bbd0e548
DW
27require_once($CFG->dirroot . '/mod/assign/locallib.php');
28
bbd0e548
DW
29/**
30 * A custom renderer class that extends the plugin_renderer_base and is used by the assign module.
31 *
32 * @package mod_assign
33 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 */
36class mod_assign_renderer extends plugin_renderer_base {
37
38 /**
e5403f8c 39 * Rendering assignment files
bbd0e548
DW
40 *
41 * @param context $context
42 * @param int $userid
43 * @param string $filearea
44 * @param string $component
45 * @return string
46 */
47 public function assign_files(context $context, $userid, $filearea, $component) {
48 return $this->render(new assign_files($context, $userid, $filearea, $component));
49 }
50
51 /**
e5403f8c 52 * Rendering assignment files
bbd0e548
DW
53 *
54 * @param assign_files $tree
55 * @return string
56 */
57 public function render_assign_files(assign_files $tree) {
9a046c06 58 $this->htmlid = html_writer::random_id('assign_files_tree');
bbd0e548
DW
59 $this->page->requires->js_init_call('M.mod_assign.init_tree', array(true, $this->htmlid));
60 $html = '<div id="'.$this->htmlid.'">';
61 $html .= $this->htmllize_tree($tree, $tree->dir);
62 $html .= '</div>';
63
64 if ($tree->portfolioform) {
65 $html .= $tree->portfolioform;
66 }
67 return $html;
68 }
69
70 /**
71 * Utility function to add a row of data to a table with 2 columns. Modified
72 * the table param and does not return a value
73 *
74 * @param html_table $table The table to append the row of data to
75 * @param string $first The first column text
76 * @param string $second The second column text
77 * @return void
78 */
79 private function add_table_row_tuple(html_table $table, $first, $second) {
80 $row = new html_table_row();
81 $cell1 = new html_table_cell($first);
82 $cell2 = new html_table_cell($second);
83 $row->cells = array($cell1, $cell2);
84 $table->data[] = $row;
85 }
86
bf78ebd6 87 /**
df211804
DW
88 * Render a grading message notification
89 * @param assign_gradingmessage $result The result to render
bf78ebd6
DW
90 * @return string
91 */
df211804 92 public function render_assign_gradingmessage(assign_gradingmessage $result) {
e5403f8c 93 $urlparams = array('id' => $result->coursemoduleid, 'action'=>'grading');
cfdd3e5c
GF
94 if (!empty($result->page)) {
95 $urlparams['page'] = $result->page;
96 }
e5403f8c 97 $url = new moodle_url('/mod/assign/view.php', $urlparams);
153510ea 98 $classes = $result->gradingerror ? 'notifyproblem' : 'notifysuccess';
2a4fbc32 99
bf78ebd6 100 $o = '';
df211804 101 $o .= $this->output->heading($result->heading, 4);
153510ea 102 $o .= $this->output->notification($result->message, $classes);
2a4fbc32 103 $o .= $this->output->continue_button($url);
bf78ebd6
DW
104 return $o;
105 }
106
bbd0e548
DW
107 /**
108 * Render the generic form
109 * @param assign_form $form The form to render
110 * @return string
111 */
112 public function render_assign_form(assign_form $form) {
113 $o = '';
bf78ebd6
DW
114 if ($form->jsinitfunction) {
115 $this->page->requires->js_init_call($form->jsinitfunction, array());
116 }
bbd0e548
DW
117 $o .= $this->output->box_start('boxaligncenter ' . $form->classname);
118 $o .= $this->moodleform($form->form);
119 $o .= $this->output->box_end();
120 return $o;
121 }
122
123 /**
124 * Render the user summary
125 *
126 * @param assign_user_summary $summary The user summary to render
127 * @return string
128 */
129 public function render_assign_user_summary(assign_user_summary $summary) {
130 $o = '';
a69944eb
RT
131 $supendedclass = '';
132 $suspendedicon = '';
bbd0e548
DW
133
134 if (!$summary->user) {
135 return;
136 }
a69944eb
RT
137
138 if ($summary->suspendeduser) {
139 $supendedclass = ' usersuspended';
140 $suspendedstring = get_string('userenrolmentsuspended', 'grades');
1ecb8044 141 $suspendedicon = ' ' . html_writer::empty_tag('img', array('src' => $this->pix_url('i/enrolmentsuspended'),
a69944eb
RT
142 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
143 }
bbd0e548 144 $o .= $this->output->container_start('usersummary');
a69944eb 145 $o .= $this->output->box_start('boxaligncenter usersummarysection'.$supendedclass);
b473171a 146 if ($summary->blindmarking) {
a69944eb 147 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser.$suspendedicon;
b473171a
DW
148 } else {
149 $o .= $this->output->user_picture($summary->user);
150 $o .= $this->output->spacer(array('width'=>30));
e5403f8c
DW
151 $urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid);
152 $url = new moodle_url('/user/view.php', $urlparams);
d08e6c31
DW
153 $fullname = fullname($summary->user, $summary->viewfullnames);
154 $extrainfo = array();
155 foreach ($summary->extrauserfields as $extrafield) {
156 $extrainfo[] = $summary->user->$extrafield;
157 }
158 if (count($extrainfo)) {
159 $fullname .= ' (' . implode(', ', $extrainfo) . ')';
160 }
a69944eb 161 $fullname .= $suspendedicon;
d08e6c31 162 $o .= $this->output->action_link($url, $fullname);
b473171a 163 }
bbd0e548
DW
164 $o .= $this->output->box_end();
165 $o .= $this->output->container_end();
166
167 return $o;
168 }
169
170 /**
171 * Render the submit for grading page
172 *
173 * @param assign_submit_for_grading_page $page
174 * @return string
175 */
176 public function render_assign_submit_for_grading_page($page) {
177 $o = '';
178
179 $o .= $this->output->container_start('submitforgrading');
180 $o .= $this->output->heading(get_string('submitassignment', 'assign'), 3);
181 $o .= $this->output->spacer(array('height'=>30));
182
183 $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
184 if (count($page->notifications)) {
e5403f8c 185 // At least one of the submission plugins is not ready for submission.
bbd0e548
DW
186
187 $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
188
189 foreach ($page->notifications as $notification) {
190 $o .= $this->output->notification($notification);
191 }
192
193 $o .= $this->output->continue_button($cancelurl);
194 } else {
e5403f8c 195 // All submission plugins ready - show the confirmation form.
df211804 196 $o .= $this->output->box_start('generalbox submitconfirm');
94f26900 197 $o .= $this->moodleform($page->confirmform);
df211804 198 $o .= $this->output->box_end();
bbd0e548
DW
199 }
200 $o .= $this->output->container_end();
201
bbd0e548
DW
202 return $o;
203 }
204
205 /**
e5403f8c 206 * Page is done - render the footer.
bbd0e548
DW
207 *
208 * @return void
209 */
210 public function render_footer() {
211 return $this->output->footer();
212 }
213
214 /**
e5403f8c 215 * Render the header.
bbd0e548
DW
216 *
217 * @param assign_header $header
218 * @return string
219 */
220 public function render_assign_header(assign_header $header) {
221 $o = '';
222
223 if ($header->subpage) {
224 $this->page->navbar->add($header->subpage);
225 }
226
227 $this->page->set_title(get_string('pluginname', 'assign'));
bea4ed1b 228 $this->page->set_heading($this->page->course->fullname);
bbd0e548
DW
229
230 $o .= $this->output->header();
bea4ed1b
RW
231 $heading = format_string($header->assign->name, false, array('context' => $header->context));
232 $o .= $this->output->heading($heading);
a1e54f4d
DW
233 if ($header->preface) {
234 $o .= $header->preface;
235 }
bbd0e548
DW
236
237 if ($header->showintro) {
238 $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
239 $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
7faf78cb 240 $o .= $header->postfix;
bbd0e548
DW
241 $o .= $this->output->box_end();
242 }
243
244 return $o;
245 }
246
af904bd7
HB
247 /**
248 * Render the header for an individual plugin.
249 *
250 * @param assign_plugin_header $header
251 * @return string
252 */
253 public function render_assign_plugin_header(assign_plugin_header $header) {
254 $o = $header->plugin->view_header();
255 return $o;
256 }
257
bbd0e548 258 /**
e5403f8c 259 * Render a table containing the current status of the grading process.
bbd0e548
DW
260 *
261 * @param assign_grading_summary $summary
262 * @return string
263 */
264 public function render_assign_grading_summary(assign_grading_summary $summary) {
e5403f8c 265 // Create a table for the data.
bbd0e548
DW
266 $o = '';
267 $o .= $this->output->container_start('gradingsummary');
268 $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
269 $o .= $this->output->box_start('boxaligncenter gradingsummarytable');
270 $t = new html_table();
271
e5403f8c 272 // Status.
12a1a0da 273 if ($summary->teamsubmission) {
e528997a
AH
274 if ($summary->warnofungroupedusers) {
275 $o .= $this->output->notification(get_string('ungroupedusers', 'assign'));
276 }
277
12a1a0da
DW
278 $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
279 $summary->participantcount);
280 } else {
281 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
282 $summary->participantcount);
283 }
bbd0e548 284
bf57184c
RW
285 // Drafts count and dont show drafts count when using offline assignment.
286 if ($summary->submissiondraftsenabled && $summary->submissionsenabled) {
bbd0e548
DW
287 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
288 $summary->submissiondraftscount);
e5403f8c 289 }
bbd0e548 290
e5403f8c 291 // Submitted for grading.
bbd0e548
DW
292 if ($summary->submissionsenabled) {
293 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
294 $summary->submissionssubmittedcount);
8f7e1c05
DW
295 if (!$summary->teamsubmission) {
296 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
297 $summary->submissionsneedgradingcount);
298 }
bbd0e548
DW
299 }
300
301 $time = time();
302 if ($summary->duedate) {
e5403f8c 303 // Due date.
bbd0e548
DW
304 $duedate = $summary->duedate;
305 $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
306 userdate($duedate));
307
e5403f8c 308 // Time remaining.
bbd0e548
DW
309 $due = '';
310 if ($duedate - $time <= 0) {
311 $due = get_string('assignmentisdue', 'assign');
312 } else {
313 $due = format_time($duedate - $time);
314 }
315 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
9e795179
DW
316
317 if ($duedate < $time) {
318 $cutoffdate = $summary->cutoffdate;
319 if ($cutoffdate) {
320 if ($cutoffdate > $time) {
b351e446 321 $late = get_string('latesubmissionsaccepted', 'assign', userdate($summary->cutoffdate));
9e795179
DW
322 } else {
323 $late = get_string('nomoresubmissionsaccepted', 'assign');
324 }
325 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
326 }
327 }
328
bbd0e548
DW
329 }
330
e5403f8c 331 // All done - write the table.
bbd0e548
DW
332 $o .= html_writer::table($t);
333 $o .= $this->output->box_end();
334
e5403f8c 335 // Link to the grading page.
d9a88f42 336 $o .= $this->output->container_start('submissionlinks');
e5403f8c
DW
337 $urlparams = array('id' => $summary->coursemoduleid, 'action'=>'grading');
338 $url = new moodle_url('/mod/assign/view.php', $urlparams);
339 $o .= $this->output->action_link($url, get_string('viewgrading', 'assign'));
d9a88f42 340 $o .= $this->output->container_end();
bbd0e548 341
e5403f8c 342 // Close the container and insert a spacer.
bbd0e548
DW
343 $o .= $this->output->container_end();
344
345 return $o;
346 }
347
348 /**
e5403f8c 349 * Render a table containing all the current grades and feedback.
bbd0e548
DW
350 *
351 * @param assign_feedback_status $status
352 * @return string
353 */
354 public function render_assign_feedback_status(assign_feedback_status $status) {
355 global $DB, $CFG;
356 $o = '';
357
358 $o .= $this->output->container_start('feedback');
359 $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
360 $o .= $this->output->box_start('boxaligncenter feedbacktable');
361 $t = new html_table();
362
e5403f8c 363 // Grade.
46692c3a
DW
364 if (isset($status->gradefordisplay)) {
365 $row = new html_table_row();
366 $cell1 = new html_table_cell(get_string('grade'));
367 $cell2 = new html_table_cell($status->gradefordisplay);
368 $row->cells = array($cell1, $cell2);
369 $t->data[] = $row;
bbd0e548 370
46692c3a
DW
371 // Grade date.
372 $row = new html_table_row();
373 $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
374 $cell2 = new html_table_cell(userdate($status->gradeddate));
375 $row->cells = array($cell1, $cell2);
376 $t->data[] = $row;
377 }
bbd0e548
DW
378
379 if ($status->grader) {
e5403f8c 380 // Grader.
bbd0e548
DW
381 $row = new html_table_row();
382 $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
e5403f8c
DW
383 $userdescription = $this->output->user_picture($status->grader) .
384 $this->output->spacer(array('width'=>30)) .
385 fullname($status->grader);
386 $cell2 = new html_table_cell($userdescription);
bbd0e548
DW
387 $row->cells = array($cell1, $cell2);
388 $t->data[] = $row;
389 }
390
391 foreach ($status->feedbackplugins as $plugin) {
df47b77f
DW
392 if ($plugin->is_enabled() &&
393 $plugin->is_visible() &&
394 $plugin->has_user_summary() &&
395 !empty($status->grade) &&
396 !$plugin->is_empty($status->grade)) {
397
bbd0e548
DW
398 $row = new html_table_row();
399 $cell1 = new html_table_cell($plugin->get_name());
e5403f8c
DW
400 $displaymode = assign_feedback_plugin_feedback::SUMMARY;
401 $pluginfeedback = new assign_feedback_plugin_feedback($plugin,
402 $status->grade,
403 $displaymode,
404 $status->coursemoduleid,
405 $status->returnaction,
406 $status->returnparams);
bbd0e548
DW
407 $cell2 = new html_table_cell($this->render($pluginfeedback));
408 $row->cells = array($cell1, $cell2);
409 $t->data[] = $row;
410 }
411 }
412
bbd0e548
DW
413 $o .= html_writer::table($t);
414 $o .= $this->output->box_end();
415
416 $o .= $this->output->container_end();
417 return $o;
418 }
419
420 /**
e5403f8c 421 * Render a table containing the current status of the submission.
bbd0e548
DW
422 *
423 * @param assign_submission_status $status
424 * @return string
425 */
426 public function render_assign_submission_status(assign_submission_status $status) {
427 $o = '';
428 $o .= $this->output->container_start('submissionstatustable');
429 $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
430 $time = time();
431
432 if ($status->allowsubmissionsfromdate &&
433 $time <= $status->allowsubmissionsfromdate) {
434 $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
435 if ($status->alwaysshowdescription) {
e5403f8c
DW
436 $date = userdate($status->allowsubmissionsfromdate);
437 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
bbd0e548 438 } else {
e5403f8c
DW
439 $date = userdate($status->allowsubmissionsfromdate);
440 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
bbd0e548
DW
441 }
442 $o .= $this->output->box_end();
443 }
444 $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
445
446 $t = new html_table();
447
12a1a0da
DW
448 if ($status->teamsubmissionenabled) {
449 $row = new html_table_row();
450 $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
451 $group = $status->submissiongroup;
452 if ($group) {
453 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
e528997a 454 } else if ($status->preventsubmissionnotingroup) {
ee5d4eef 455 if (count($status->usergroups) == 0) {
08a54173
AH
456 $cell2 = new html_table_cell(
457 html_writer::span(get_string('noteam', 'assign'), 'alert alert-error')
458 );
ee5d4eef 459 } else if (count($status->usergroups) > 1) {
08a54173
AH
460 $cell2 = new html_table_cell(
461 html_writer::span(get_string('multipleteams', 'assign'), 'alert alert-error')
462 );
ee5d4eef 463 }
12a1a0da
DW
464 } else {
465 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
466 }
467 $row->cells = array($cell1, $cell2);
468 $t->data[] = $row;
469 }
470
df211804
DW
471 if ($status->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
472 $currentattempt = 1;
473 if (!$status->teamsubmissionenabled) {
474 if ($status->submission) {
475 $currentattempt = $status->submission->attemptnumber + 1;
476 }
477 } else {
478 if ($status->teamsubmission) {
479 $currentattempt = $status->teamsubmission->attemptnumber + 1;
480 }
481 }
482
483 $row = new html_table_row();
484 $cell1 = new html_table_cell(get_string('attemptnumber', 'assign'));
485 $maxattempts = $status->maxattempts;
486 if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) {
487 $message = get_string('currentattempt', 'assign', $currentattempt);
488 } else {
489 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt,
490 'maxattempts'=>$maxattempts));
491 }
492 $cell2 = new html_table_cell($message);
493 $row->cells = array($cell1, $cell2);
494 $t->data[] = $row;
495 }
496
bbd0e548
DW
497 $row = new html_table_row();
498 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
12a1a0da 499 if (!$status->teamsubmissionenabled) {
9e3eee67 500 if ($status->submission && $status->submission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
e5403f8c
DW
501 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign');
502 $cell2 = new html_table_cell($statusstr);
12a1a0da
DW
503 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
504 } else {
505 if (!$status->submissionsenabled) {
506 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
507 } else {
df211804 508 $cell2 = new html_table_cell(get_string('noattempt', 'assign'));
12a1a0da
DW
509 }
510 }
511 $row->cells = array($cell1, $cell2);
512 $t->data[] = $row;
bbd0e548 513 } else {
12a1a0da
DW
514 $row = new html_table_row();
515 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
e528997a
AH
516 $group = $status->submissiongroup;
517 if (!$group && $status->preventsubmissionnotingroup) {
518 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
519 } else if ($status->teamsubmission && $status->teamsubmission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
e5403f8c
DW
520 $teamstatus = $status->teamsubmission->status;
521 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
12a1a0da
DW
522 $groupid = 0;
523 if ($status->submissiongroup) {
524 $groupid = $status->submissiongroup->id;
525 }
526
527 $members = $status->submissiongroupmemberswhoneedtosubmit;
528 $userslist = array();
529 foreach ($members as $member) {
e5403f8c
DW
530 $urlparams = array('id' => $member->id, 'course'=>$status->courseid);
531 $url = new moodle_url('/user/view.php', $urlparams);
88cfe469
DW
532 if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
533 $userslist[] = $member->alias;
534 } else {
e5403f8c
DW
535 $fullname = fullname($member, $status->canviewfullnames);
536 $userslist[] = $this->output->action_link($url, $fullname);
88cfe469 537 }
12a1a0da
DW
538 }
539 if (count($userslist) > 0) {
540 $userstr = join(', ', $userslist);
e5403f8c
DW
541 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
542 $submissionsummary .= $this->output->container($formatteduserstr);
12a1a0da
DW
543 }
544
545 $cell2 = new html_table_cell($submissionsummary);
546 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
bbd0e548
DW
547 } else {
548 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
12a1a0da
DW
549 if (!$status->submissionsenabled) {
550 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
551 } else {
552 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
553 }
bbd0e548 554 }
12a1a0da
DW
555 $row->cells = array($cell1, $cell2);
556 $t->data[] = $row;
bbd0e548 557 }
bbd0e548 558
e5403f8c 559 // Is locked?
bbd0e548
DW
560 if ($status->locked) {
561 $row = new html_table_row();
562 $cell1 = new html_table_cell();
563 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
564 $cell2->attributes = array('class'=>'submissionlocked');
565 $row->cells = array($cell1, $cell2);
566 $t->data[] = $row;
567 }
568
e5403f8c 569 // Grading status.
bbd0e548
DW
570 $row = new html_table_row();
571 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
572
bd3ee807
MN
573 if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
574 $status->gradingstatus == ASSIGN_GRADING_STATUS_NOT_GRADED) {
575 $cell2 = new html_table_cell(get_string($status->gradingstatus, 'assign'));
bbd0e548 576 } else {
bd3ee807
MN
577 $gradingstatus = 'markingworkflowstate' . $status->gradingstatus;
578 $cell2 = new html_table_cell(get_string($gradingstatus, 'assign'));
579 }
580 if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
581 $status->gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
582 $cell2->attributes = array('class' => 'submissiongraded');
583 } else {
584 $cell2->attributes = array('class' => 'submissionnotgraded');
bbd0e548
DW
585 }
586 $row->cells = array($cell1, $cell2);
587 $t->data[] = $row;
588
79397b56 589 $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
bbd0e548 590 $duedate = $status->duedate;
9e795179 591 if ($duedate > 0) {
e5403f8c 592 // Due date.
bbd0e548
DW
593 $row = new html_table_row();
594 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
595 $cell2 = new html_table_cell(userdate($duedate));
596 $row->cells = array($cell1, $cell2);
597 $t->data[] = $row;
598
9e795179
DW
599 if ($status->view == assign_submission_status::GRADER_VIEW) {
600 if ($status->cutoffdate) {
e5403f8c 601 // Cut off date.
9e795179
DW
602 $row = new html_table_row();
603 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
604 $cell2 = new html_table_cell(userdate($status->cutoffdate));
605 $row->cells = array($cell1, $cell2);
606 $t->data[] = $row;
607 }
608 }
609
610 if ($status->extensionduedate) {
e5403f8c 611 // Extension date.
9e795179
DW
612 $row = new html_table_row();
613 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
614 $cell2 = new html_table_cell(userdate($status->extensionduedate));
615 $row->cells = array($cell1, $cell2);
616 $t->data[] = $row;
617 $duedate = $status->extensionduedate;
618 }
619
620 // Time remaining.
bbd0e548
DW
621 $row = new html_table_row();
622 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
623 if ($duedate - $time <= 0) {
79397b56
DB
624 if (!$submission ||
625 $submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
bbd0e548 626 if ($status->submissionsenabled) {
e5403f8c
DW
627 $overduestr = get_string('overdue', 'assign', format_time($time - $duedate));
628 $cell2 = new html_table_cell($overduestr);
bbd0e548
DW
629 $cell2->attributes = array('class'=>'overdue');
630 } else {
631 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
632 }
633 } else {
79397b56 634 if ($submission->timemodified > $duedate) {
e5403f8c
DW
635 $latestr = get_string('submittedlate',
636 'assign',
79397b56 637 format_time($submission->timemodified - $duedate));
e5403f8c 638 $cell2 = new html_table_cell($latestr);
bbd0e548
DW
639 $cell2->attributes = array('class'=>'latesubmission');
640 } else {
e5403f8c
DW
641 $earlystr = get_string('submittedearly',
642 'assign',
79397b56 643 format_time($submission->timemodified - $duedate));
e5403f8c 644 $cell2 = new html_table_cell($earlystr);
bbd0e548
DW
645 $cell2->attributes = array('class'=>'earlysubmission');
646 }
647 }
648 } else {
649 $cell2 = new html_table_cell(format_time($duedate - $time));
650 }
651 $row->cells = array($cell1, $cell2);
652 $t->data[] = $row;
653 }
654
9e795179
DW
655 // Show graders whether this submission is editable by students.
656 if ($status->view == assign_submission_status::GRADER_VIEW) {
657 $row = new html_table_row();
848ade1d 658 $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
9e795179
DW
659 if ($status->canedit) {
660 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
661 $cell2->attributes = array('class'=>'submissioneditable');
662 } else {
663 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
664 $cell2->attributes = array('class'=>'submissionnoteditable');
665 }
6c712479
DW
666 $row->cells = array($cell1, $cell2);
667 $t->data[] = $row;
ec32d068
RW
668 }
669
670 // Grading criteria preview.
671 if (!empty($status->gradingcontrollerpreview)) {
672 $row = new html_table_row();
673 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
674 $cell2 = new html_table_cell($status->gradingcontrollerpreview);
9e795179
DW
675 $row->cells = array($cell1, $cell2);
676 $t->data[] = $row;
677 }
678
679 // Last modified.
12a1a0da 680 if ($submission) {
bbd0e548
DW
681 $row = new html_table_row();
682 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
12a1a0da 683 $cell2 = new html_table_cell(userdate($submission->timemodified));
bbd0e548
DW
684 $row->cells = array($cell1, $cell2);
685 $t->data[] = $row;
686
e528997a
AH
687 if (!$status->teamsubmission || $status->submissiongroup != false || !$status->preventsubmissionnotingroup) {
688 foreach ($status->submissionplugins as $plugin) {
689 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
690 if ($plugin->is_enabled() &&
691 $plugin->is_visible() &&
692 $plugin->has_user_summary() &&
693 $pluginshowsummary
694 ) {
695
696 $row = new html_table_row();
697 $cell1 = new html_table_cell($plugin->get_name());
698 $displaymode = assign_submission_plugin_submission::SUMMARY;
699 $pluginsubmission = new assign_submission_plugin_submission($plugin,
700 $submission,
701 $displaymode,
702 $status->coursemoduleid,
703 $status->returnaction,
704 $status->returnparams);
705 $cell2 = new html_table_cell($this->render($pluginsubmission));
706 $row->cells = array($cell1, $cell2);
707 $t->data[] = $row;
708 }
bbd0e548
DW
709 }
710 }
711 }
712
bbd0e548
DW
713 $o .= html_writer::table($t);
714 $o .= $this->output->box_end();
715
9e795179
DW
716 // Links.
717 if ($status->view == assign_submission_status::STUDENT_VIEW) {
718 if ($status->canedit) {
9e3eee67 719 if (!$submission || $submission->status == ASSIGN_SUBMISSION_STATUS_NEW) {
df211804 720 $o .= $this->output->box_start('generalbox submissionaction');
9e795179
DW
721 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
722 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
723 get_string('addsubmission', 'assign'), 'get');
df211804
DW
724 $o .= $this->output->box_start('boxaligncenter submithelp');
725 $o .= get_string('editsubmission_help', 'assign');
726 $o .= $this->output->box_end();
727 $o .= $this->output->box_end();
728 } else if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
729 $o .= $this->output->box_start('generalbox submissionaction');
e9fe65d5
DW
730 $urlparams = array('id' => $status->coursemoduleid,
731 'action' => 'editprevioussubmission',
732 'sesskey'=>sesskey());
df211804
DW
733 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
734 get_string('addnewattemptfromprevious', 'assign'), 'get');
735 $o .= $this->output->box_start('boxaligncenter submithelp');
736 $o .= get_string('addnewattemptfromprevious_help', 'assign');
737 $o .= $this->output->box_end();
738 $o .= $this->output->box_end();
739 $o .= $this->output->box_start('generalbox submissionaction');
740 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
741 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
742 get_string('addnewattempt', 'assign'), 'get');
743 $o .= $this->output->box_start('boxaligncenter submithelp');
744 $o .= get_string('addnewattempt_help', 'assign');
745 $o .= $this->output->box_end();
746 $o .= $this->output->box_end();
9e795179 747 } else {
df211804 748 $o .= $this->output->box_start('generalbox submissionaction');
9e795179
DW
749 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
750 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
751 get_string('editsubmission', 'assign'), 'get');
df211804
DW
752 $o .= $this->output->box_start('boxaligncenter submithelp');
753 $o .= get_string('editsubmission_help', 'assign');
754 $o .= $this->output->box_end();
755 $o .= $this->output->box_end();
9e795179 756 }
caff10a0 757 }
bbd0e548 758
9e795179
DW
759 if ($status->cansubmit) {
760 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
df211804 761 $o .= $this->output->box_start('generalbox submissionaction');
9e795179
DW
762 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
763 get_string('submitassignment', 'assign'), 'get');
764 $o .= $this->output->box_start('boxaligncenter submithelp');
765 $o .= get_string('submitassignment_help', 'assign');
766 $o .= $this->output->box_end();
df211804 767 $o .= $this->output->box_end();
9e795179 768 }
bbd0e548
DW
769 }
770
771 $o .= $this->output->container_end();
772 return $o;
773 }
774
df211804
DW
775 /**
776 * Output the attempt history for this assignment
777 *
778 * @param assign_attempt_history $history
779 * @return string
780 */
781 public function render_assign_attempt_history(assign_attempt_history $history) {
782 $o = '';
783
784 $submittedstr = get_string('submitted', 'assign');
785 $gradestr = get_string('grade');
786 $gradedonstr = get_string('gradedon', 'assign');
787 $gradedbystr = get_string('gradedby', 'assign');
788
789 // Don't show the last one because it is the current submission.
790 array_pop($history->submissions);
791
792 // Show newest to oldest.
793 $history->submissions = array_reverse($history->submissions);
794
795 if (empty($history->submissions)) {
796 return '';
797 }
798
799 $containerid = 'attempthistory' . uniqid();
800 $o .= $this->heading(get_string('attempthistory', 'assign'), 3);
801 $o .= $this->box_start('attempthistory', $containerid);
802
803 foreach ($history->submissions as $i => $submission) {
804 $grade = null;
805 foreach ($history->grades as $onegrade) {
806 if ($onegrade->attemptnumber == $submission->attemptnumber) {
807 $grade = $onegrade;
808 break;
809 }
810 }
811
812 $editbtn = '';
813
814 if ($submission) {
815 $submissionsummary = userdate($submission->timemodified);
816 } else {
817 $submissionsummary = get_string('nosubmission', 'assign');
818 }
819
820 $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+1,
821 'submissionsummary'=>$submissionsummary);
822 $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4);
823
824 $t = new html_table();
825
826 if ($submission) {
827 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
828 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status, 'assign'));
829 $t->data[] = new html_table_row(array($cell1, $cell2));
830
831 foreach ($history->submissionplugins as $plugin) {
832 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
833 if ($plugin->is_enabled() &&
834 $plugin->is_visible() &&
835 $plugin->has_user_summary() &&
836 $pluginshowsummary) {
837
838 $cell1 = new html_table_cell($plugin->get_name());
839 $pluginsubmission = new assign_submission_plugin_submission($plugin,
840 $submission,
841 assign_submission_plugin_submission::SUMMARY,
842 $history->coursemoduleid,
843 $history->returnaction,
844 $history->returnparams);
845 $cell2 = new html_table_cell($this->render($pluginsubmission));
846
847 $t->data[] = new html_table_row(array($cell1, $cell2));
848 }
849 }
850 }
851
852 if ($grade) {
853 // Heading 'feedback'.
854 $title = get_string('feedback', 'assign', $i);
855 $title .= $this->output->spacer(array('width'=>10));
856 if ($history->cangrade) {
857 // Edit previous feedback.
858 $returnparams = http_build_query($history->returnparams);
859 $urlparams = array('id' => $history->coursemoduleid,
99758819
DW
860 'rownum'=>$history->rownum,
861 'useridlistid'=>$history->useridlistid,
df211804
DW
862 'attemptnumber'=>$grade->attemptnumber,
863 'action'=>'grade',
df211804
DW
864 'returnaction'=>$history->returnaction,
865 'returnparams'=>$returnparams);
866 $url = new moodle_url('/mod/assign/view.php', $urlparams);
867 $icon = new pix_icon('gradefeedback',
868 get_string('editattemptfeedback', 'assign', $grade->attemptnumber+1),
869 'mod_assign');
870 $title .= $this->output->action_icon($url, $icon);
871 }
872 $cell = new html_table_cell($title);
873 $cell->attributes['class'] = 'feedbacktitle';
874 $cell->colspan = 2;
875 $t->data[] = new html_table_row(array($cell));
876
877 // Grade.
878 $cell1 = new html_table_cell($gradestr);
879 $cell2 = $grade->gradefordisplay;
880 $t->data[] = new html_table_row(array($cell1, $cell2));
881
882 // Graded on.
883 $cell1 = new html_table_cell($gradedonstr);
884 $cell2 = new html_table_cell(userdate($grade->timemodified));
885 $t->data[] = new html_table_row(array($cell1, $cell2));
886
887 // Graded by.
888 $cell1 = new html_table_cell($gradedbystr);
889 $cell2 = new html_table_cell($this->output->user_picture($grade->grader) .
890 $this->output->spacer(array('width'=>30)) . fullname($grade->grader));
891 $t->data[] = new html_table_row(array($cell1, $cell2));
892
893 // Feedback from plugins.
894 foreach ($history->feedbackplugins as $plugin) {
895 if ($plugin->is_enabled() &&
896 $plugin->is_visible() &&
897 $plugin->has_user_summary() &&
898 !$plugin->is_empty($grade)) {
899
900 $cell1 = new html_table_cell($plugin->get_name());
901 $pluginfeedback = new assign_feedback_plugin_feedback(
902 $plugin, $grade, assign_feedback_plugin_feedback::SUMMARY, $history->coursemoduleid,
903 $history->returnaction, $history->returnparams
904 );
905 $cell2 = new html_table_cell($this->render($pluginfeedback));
906 $t->data[] = new html_table_row(array($cell1, $cell2));
907 }
908
909 }
910
911 }
912
913 $o .= html_writer::table($t);
914 }
915 $o .= $this->box_end();
916 $jsparams = array($containerid);
917
918 $this->page->requires->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history');
919
920 return $o;
921 }
922
bbd0e548 923 /**
e5403f8c 924 * Render a submission plugin submission
bbd0e548
DW
925 *
926 * @param assign_submission_plugin_submission $submissionplugin
927 * @return string
928 */
929 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
930 $o = '';
931
932 if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
bbd0e548 933 $showviewlink = false;
e5403f8c
DW
934 $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission,
935 $showviewlink);
936
937 $classsuffix = $submissionplugin->plugin->get_subtype() .
938 '_' .
939 $submissionplugin->plugin->get_type() .
940 '_' .
941 $submissionplugin->submission->id;
66d3fe37 942
66d3fe37
DW
943 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
944
945 $link = '';
bbd0e548 946 if ($showviewlink) {
66d3fe37
DW
947 $previewstr = get_string('viewsubmission', 'assign');
948 $icon = $this->output->pix_icon('t/preview', $previewstr);
949
950 $expandstr = get_string('viewfull', 'assign');
e5403f8c
DW
951 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
952 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
66d3fe37
DW
953
954 $jsparams = array($submissionplugin->plugin->get_subtype(),
955 $submissionplugin->plugin->get_type(),
956 $submissionplugin->submission->id);
e5403f8c 957
66d3fe37
DW
958 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
959
e5403f8c
DW
960 $action = 'viewplugin' . $submissionplugin->plugin->get_subtype();
961 $returnparams = http_build_query($submissionplugin->returnparams);
66d3fe37 962 $link .= '<noscript>';
e5403f8c
DW
963 $urlparams = array('id' => $submissionplugin->coursemoduleid,
964 'sid'=>$submissionplugin->submission->id,
965 'plugin'=>$submissionplugin->plugin->get_type(),
966 'action'=>$action,
967 'returnaction'=>$submissionplugin->returnaction,
968 'returnparams'=>$returnparams);
969 $url = new moodle_url('/mod/assign/view.php', $urlparams);
970 $link .= $this->output->action_link($url, $icon);
66d3fe37 971 $link .= '</noscript>';
bbd0e548
DW
972
973 $link .= $this->output->spacer(array('width'=>15));
974 }
975
976 $o .= $link . $summary;
66d3fe37
DW
977 $o .= $this->output->box_end();
978 if ($showviewlink) {
979 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
980 $classes = 'expandsummaryicon contract_' . $classsuffix;
981 $o .= $this->output->pix_icon('t/switch_minus',
982 get_string('viewsummary', 'assign'),
983 null,
984 array('class'=>$classes));
985 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
986 $o .= $this->output->box_end();
987 }
bbd0e548
DW
988 } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
989 $o .= $this->output->box_start('boxaligncenter submissionfull');
990 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
991 $o .= $this->output->box_end();
992 }
993
994 return $o;
995 }
996
997 /**
e5403f8c 998 * Render the grading table.
bbd0e548
DW
999 *
1000 * @param assign_grading_table $table
1001 * @return string
1002 */
1003 public function render_assign_grading_table(assign_grading_table $table) {
1004 $o = '';
1005 $o .= $this->output->box_start('boxaligncenter gradingtable');
df47b77f 1006
bbd0e548
DW
1007 $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
1008 $this->page->requires->string_for_js('nousersselected', 'assign');
9e795179 1009 $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
bbd0e548 1010 $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
bbd0e548 1011 $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
9e795179 1012 $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
df211804 1013 $this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign');
f8d107b3
DM
1014 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
1015 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
bbd0e548 1016 $this->page->requires->string_for_js('editaction', 'assign');
df47b77f
DW
1017 foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
1018 foreach ($operations as $operation => $description) {
e5403f8c
DW
1019 $this->page->requires->string_for_js('batchoperationconfirm' . $operation,
1020 'assignfeedback_' . $plugin);
df47b77f
DW
1021 }
1022 }
bbd0e548
DW
1023 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
1024 $o .= $this->output->box_end();
1025
1026 return $o;
e5403f8c 1027 }
bbd0e548
DW
1028
1029 /**
1030 * Render a feedback plugin feedback
1031 *
1032 * @param assign_feedback_plugin_feedback $feedbackplugin
1033 * @return string
1034 */
1035 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
1036 $o = '';
1037
1038 if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
bbd0e548
DW
1039 $showviewlink = false;
1040 $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
66d3fe37 1041
e5403f8c
DW
1042 $classsuffix = $feedbackplugin->plugin->get_subtype() .
1043 '_' .
1044 $feedbackplugin->plugin->get_type() .
1045 '_' .
1046 $feedbackplugin->grade->id;
66d3fe37
DW
1047 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1048
1049 $link = '';
bbd0e548 1050 if ($showviewlink) {
66d3fe37
DW
1051 $previewstr = get_string('viewfeedback', 'assign');
1052 $icon = $this->output->pix_icon('t/preview', $previewstr);
1053
1054 $expandstr = get_string('viewfull', 'assign');
e5403f8c
DW
1055 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1056 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
66d3fe37
DW
1057
1058 $jsparams = array($feedbackplugin->plugin->get_subtype(),
1059 $feedbackplugin->plugin->get_type(),
1060 $feedbackplugin->grade->id);
1061 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1062
e5403f8c
DW
1063 $urlparams = array('id' => $feedbackplugin->coursemoduleid,
1064 'gid'=>$feedbackplugin->grade->id,
1065 'plugin'=>$feedbackplugin->plugin->get_type(),
1066 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
1067 'returnaction'=>$feedbackplugin->returnaction,
1068 'returnparams'=>http_build_query($feedbackplugin->returnparams));
1069 $url = new moodle_url('/mod/assign/view.php', $urlparams);
66d3fe37 1070 $link .= '<noscript>';
e5403f8c 1071 $link .= $this->output->action_link($url, $icon);
66d3fe37
DW
1072 $link .= '</noscript>';
1073
bbd0e548
DW
1074 $link .= $this->output->spacer(array('width'=>15));
1075 }
1076
1077 $o .= $link . $summary;
66d3fe37
DW
1078 $o .= $this->output->box_end();
1079 if ($showviewlink) {
1080 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
1081 $classes = 'expandsummaryicon contract_' . $classsuffix;
1082 $o .= $this->output->pix_icon('t/switch_minus',
1083 get_string('viewsummary', 'assign'),
1084 null,
1085 array('class'=>$classes));
1086 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1087 $o .= $this->output->box_end();
1088 }
bbd0e548
DW
1089 } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
1090 $o .= $this->output->box_start('boxaligncenter feedbackfull');
1091 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1092 $o .= $this->output->box_end();
1093 }
1094
1095 return $o;
1096 }
1097
64220210
DW
1098 /**
1099 * Render a course index summary
1100 *
1101 * @param assign_course_index_summary $indexsummary
1102 * @return string
1103 */
1104 public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
1105 $o = '';
1106
1107 $strplural = get_string('modulenameplural', 'assign');
1108 $strsectionname = $indexsummary->courseformatname;
1109 $strduedate = get_string('duedate', 'assign');
1110 $strsubmission = get_string('submission', 'assign');
1111 $strgrade = get_string('grade');
1112
1113 $table = new html_table();
1114 if ($indexsummary->usesections) {
1115 $table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
1116 $table->align = array ('left', 'left', 'center', 'right', 'right');
1117 } else {
1118 $table->head = array ($strplural, $strduedate, $strsubmission, $strgrade);
1119 $table->align = array ('left', 'left', 'center', 'right');
1120 }
1121 $table->data = array();
1122
1123 $currentsection = '';
1124 foreach ($indexsummary->assignments as $info) {
1125 $params = array('id' => $info['cmid']);
1126 $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
1127 $info['cmname']);
1128 $due = $info['timedue'] ? userdate($info['timedue']) : '-';
1129
1130 $printsection = '';
1131 if ($indexsummary->usesections) {
1132 if ($info['sectionname'] !== $currentsection) {
1133 if ($info['sectionname']) {
1134 $printsection = $info['sectionname'];
1135 }
1136 if ($currentsection !== '') {
1137 $table->data[] = 'hr';
1138 }
1139 $currentsection = $info['sectionname'];
1140 }
1141 }
1142
1143 if ($indexsummary->usesections) {
1144 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
1145 } else {
1146 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
1147 }
1148 $table->data[] = $row;
1149 }
1150
1151 $o .= html_writer::table($table);
1152
1153 return $o;
1154 }
1155
bbd0e548
DW
1156
1157
1158 /**
1159 * Internal function - creates htmls structure suitable for YUI tree.
1160 *
1161 * @param assign_files $tree
1162 * @param array $dir
1163 * @return string
1164 */
1165 protected function htmllize_tree(assign_files $tree, $dir) {
1166 global $CFG;
1167 $yuiconfig = array();
1168 $yuiconfig['type'] = 'html';
1169
1170 if (empty($dir['subdirs']) and empty($dir['files'])) {
1171 return '';
1172 }
1173
1174 $result = '<ul>';
1175 foreach ($dir['subdirs'] as $subdir) {
e5403f8c
DW
1176 $image = $this->output->pix_icon(file_folder_icon(),
1177 $subdir['dirname'],
1178 'moodle',
1179 array('class'=>'icon'));
1180 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1181 '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
1182 $this->htmllize_tree($tree, $subdir) .
1183 '</li>';
bbd0e548
DW
1184 }
1185
1186 foreach ($dir['files'] as $file) {
1187 $filename = $file->get_filename();
bbd0e548
DW
1188 if ($CFG->enableplagiarism) {
1189 require_once($CFG->libdir.'/plagiarismlib.php');
e5403f8c
DW
1190 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(),
1191 'file'=>$file,
1192 'cmid'=>$tree->cm->id,
1193 'course'=>$tree->course));
bbd0e548 1194 } else {
e5403f8c 1195 $plagiarismlinks = '';
bbd0e548 1196 }
e5403f8c
DW
1197 $image = $this->output->pix_icon(file_file_icon($file),
1198 $filename,
1199 'moodle',
1200 array('class'=>'icon'));
1201 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1202 '<div>' . $image . ' ' .
1203 $file->fileurl . ' ' .
1204 $plagiarismlinks .
1205 $file->portfoliobutton . '</div>' .
1206 '</li>';
bbd0e548
DW
1207 }
1208
1209 $result .= '</ul>';
1210
1211 return $result;
1212 }
1213
1214 /**
1215 * Helper method dealing with the fact we can not just fetch the output of flexible_table
1216 *
1217 * @param flexible_table $table The table to render
1218 * @param int $rowsperpage How many assignments to render in a page
e5403f8c
DW
1219 * @param bool $displaylinks - Whether to render links in the table
1220 * (e.g. downloads would not enable this)
bbd0e548
DW
1221 * @return string HTML
1222 */
1223 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
1224
1225 $o = '';
1226 ob_start();
1227 $table->out($rowsperpage, $displaylinks);
1228 $o = ob_get_contents();
1229 ob_end_clean();
1230
1231 return $o;
1232 }
1233
1234 /**
1235 * Helper method dealing with the fact we can not just fetch the output of moodleforms
1236 *
1237 * @param moodleform $mform
1238 * @return string HTML
1239 */
1240 protected function moodleform(moodleform $mform) {
1241
1242 $o = '';
1243 ob_start();
1244 $mform->display();
1245 $o = ob_get_contents();
1246 ob_end_clean();
1247
1248 return $o;
1249 }
1250
1251}
1252