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