2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file contains a renderer for the assignment class
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->dirroot . '/mod/assign/locallib.php');
30 * A custom renderer class that extends the plugin_renderer_base and is used by the assign module.
33 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class mod_assign_renderer extends plugin_renderer_base {
39 * Rendering assignment files
41 * @param context $context
43 * @param string $filearea
44 * @param string $component
47 public function assign_files(context $context, $userid, $filearea, $component) {
48 return $this->render(new assign_files($context, $userid, $filearea, $component));
52 * Rendering assignment files
54 * @param assign_files $tree
57 public function render_assign_files(assign_files $tree) {
58 $this->htmlid = html_writer::random_id('assign_files_tree');
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);
64 if ($tree->portfolioform) {
65 $html .= $tree->portfolioform;
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
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
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;
88 * Render a grading message notification
89 * @param assign_gradingmessage $result The result to render
92 public function render_assign_gradingmessage(assign_gradingmessage $result) {
93 $urlparams = array('id' => $result->coursemoduleid, 'action'=>'grading');
94 if (!empty($result->page)) {
95 $urlparams['page'] = $result->page;
97 $url = new moodle_url('/mod/assign/view.php', $urlparams);
98 $classes = $result->gradingerror ? 'notifyproblem' : 'notifysuccess';
101 $o .= $this->output->heading($result->heading, 4);
102 $o .= $this->output->notification($result->message, $classes);
103 $o .= $this->output->continue_button($url);
108 * Render the generic form
109 * @param assign_form $form The form to render
112 public function render_assign_form(assign_form $form) {
114 if ($form->jsinitfunction) {
115 $this->page->requires->js_init_call($form->jsinitfunction, array());
117 $o .= $this->output->box_start('boxaligncenter ' . $form->classname);
118 $o .= $this->moodleform($form->form);
119 $o .= $this->output->box_end();
124 * Render the user summary
126 * @param assign_user_summary $summary The user summary to render
129 public function render_assign_user_summary(assign_user_summary $summary) {
134 if (!$summary->user) {
138 if ($summary->suspendeduser) {
139 $supendedclass = ' usersuspended';
140 $suspendedstring = get_string('userenrolmentsuspended', 'grades');
141 $suspendedicon = ' ' . html_writer::empty_tag('img', array('src' => $this->pix_url('i/enrolmentsuspended'),
142 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
144 $o .= $this->output->container_start('usersummary');
145 $o .= $this->output->box_start('boxaligncenter usersummarysection'.$supendedclass);
146 if ($summary->blindmarking) {
147 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser.$suspendedicon;
149 $o .= $this->output->user_picture($summary->user);
150 $o .= $this->output->spacer(array('width'=>30));
151 $urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid);
152 $url = new moodle_url('/user/view.php', $urlparams);
153 $fullname = fullname($summary->user, $summary->viewfullnames);
154 $extrainfo = array();
155 foreach ($summary->extrauserfields as $extrafield) {
156 $extrainfo[] = $summary->user->$extrafield;
158 if (count($extrainfo)) {
159 $fullname .= ' (' . implode(', ', $extrainfo) . ')';
161 $fullname .= $suspendedicon;
162 $o .= $this->output->action_link($url, $fullname);
164 $o .= $this->output->box_end();
165 $o .= $this->output->container_end();
171 * Render the submit for grading page
173 * @param assign_submit_for_grading_page $page
176 public function render_assign_submit_for_grading_page($page) {
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));
183 $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
184 if (count($page->notifications)) {
185 // At least one of the submission plugins is not ready for submission.
187 $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
189 foreach ($page->notifications as $notification) {
190 $o .= $this->output->notification($notification);
193 $o .= $this->output->continue_button($cancelurl);
195 // All submission plugins ready - show the confirmation form.
196 $o .= $this->output->box_start('generalbox submitconfirm');
197 $o .= $this->moodleform($page->confirmform);
198 $o .= $this->output->box_end();
200 $o .= $this->output->container_end();
206 * Page is done - render the footer.
210 public function render_footer() {
211 return $this->output->footer();
217 * @param assign_header $header
220 public function render_assign_header(assign_header $header) {
223 if ($header->subpage) {
224 $this->page->navbar->add($header->subpage);
227 $this->page->set_title(get_string('pluginname', 'assign'));
228 $this->page->set_heading($this->page->course->fullname);
230 $o .= $this->output->header();
231 $heading = format_string($header->assign->name, false, array('context' => $header->context));
232 $o .= $this->output->heading($heading);
233 if ($header->preface) {
234 $o .= $header->preface;
237 if ($header->showintro) {
238 $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
239 $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
240 $o .= $header->postfix;
241 $o .= $this->output->box_end();
248 * Render the header for an individual plugin.
250 * @param assign_plugin_header $header
253 public function render_assign_plugin_header(assign_plugin_header $header) {
254 $o = $header->plugin->view_header();
259 * Render a table containing the current status of the grading process.
261 * @param assign_grading_summary $summary
264 public function render_assign_grading_summary(assign_grading_summary $summary) {
265 // Create a table for the data.
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();
273 if ($summary->teamsubmission) {
274 if ($summary->warnofungroupedusers) {
275 $o .= $this->output->notification(get_string('ungroupedusers', 'assign'));
278 $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
279 $summary->participantcount);
281 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
282 $summary->participantcount);
285 // Drafts count and dont show drafts count when using offline assignment.
286 if ($summary->submissiondraftsenabled && $summary->submissionsenabled) {
287 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
288 $summary->submissiondraftscount);
291 // Submitted for grading.
292 if ($summary->submissionsenabled) {
293 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
294 $summary->submissionssubmittedcount);
295 if (!$summary->teamsubmission) {
296 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
297 $summary->submissionsneedgradingcount);
302 if ($summary->duedate) {
304 $duedate = $summary->duedate;
305 $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
310 if ($duedate - $time <= 0) {
311 $due = get_string('assignmentisdue', 'assign');
313 $due = format_time($duedate - $time);
315 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
317 if ($duedate < $time) {
318 $cutoffdate = $summary->cutoffdate;
320 if ($cutoffdate > $time) {
321 $late = get_string('latesubmissionsaccepted', 'assign', userdate($summary->cutoffdate));
323 $late = get_string('nomoresubmissionsaccepted', 'assign');
325 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
331 // All done - write the table.
332 $o .= html_writer::table($t);
333 $o .= $this->output->box_end();
335 // Link to the grading page.
336 $o .= $this->output->container_start('submissionlinks');
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'));
340 $o .= $this->output->container_end();
342 // Close the container and insert a spacer.
343 $o .= $this->output->container_end();
349 * Render a table containing all the current grades and feedback.
351 * @param assign_feedback_status $status
354 public function render_assign_feedback_status(assign_feedback_status $status) {
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();
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);
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);
379 if ($status->grader) {
381 $row = new html_table_row();
382 $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
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);
387 $row->cells = array($cell1, $cell2);
391 foreach ($status->feedbackplugins as $plugin) {
392 if ($plugin->is_enabled() &&
393 $plugin->is_visible() &&
394 $plugin->has_user_summary() &&
395 !empty($status->grade) &&
396 !$plugin->is_empty($status->grade)) {
398 $row = new html_table_row();
399 $cell1 = new html_table_cell($plugin->get_name());
400 $displaymode = assign_feedback_plugin_feedback::SUMMARY;
401 $pluginfeedback = new assign_feedback_plugin_feedback($plugin,
404 $status->coursemoduleid,
405 $status->returnaction,
406 $status->returnparams);
407 $cell2 = new html_table_cell($this->render($pluginfeedback));
408 $row->cells = array($cell1, $cell2);
413 $o .= html_writer::table($t);
414 $o .= $this->output->box_end();
416 $o .= $this->output->container_end();
421 * Render a table containing the current status of the submission.
423 * @param assign_submission_status $status
426 public function render_assign_submission_status(assign_submission_status $status) {
428 $o .= $this->output->container_start('submissionstatustable');
429 $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
432 if ($status->allowsubmissionsfromdate &&
433 $time <= $status->allowsubmissionsfromdate) {
434 $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
435 if ($status->alwaysshowdescription) {
436 $date = userdate($status->allowsubmissionsfromdate);
437 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
439 $date = userdate($status->allowsubmissionsfromdate);
440 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
442 $o .= $this->output->box_end();
444 $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
446 $t = new html_table();
448 if ($status->teamsubmissionenabled) {
449 $row = new html_table_row();
450 $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
451 $group = $status->submissiongroup;
453 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
454 } else if ($status->preventsubmissionnotingroup) {
455 if (count($status->usergroups) == 0) {
456 $cell2 = new html_table_cell(get_string('noteam', 'assign'));
457 } else if (count($status->usergroups) > 1) {
458 $cell2 = new html_table_cell(get_string('multipleteams', 'assign'));
461 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
463 $row->cells = array($cell1, $cell2);
467 if ($status->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
469 if (!$status->teamsubmissionenabled) {
470 if ($status->submission) {
471 $currentattempt = $status->submission->attemptnumber + 1;
474 if ($status->teamsubmission) {
475 $currentattempt = $status->teamsubmission->attemptnumber + 1;
479 $row = new html_table_row();
480 $cell1 = new html_table_cell(get_string('attemptnumber', 'assign'));
481 $maxattempts = $status->maxattempts;
482 if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) {
483 $message = get_string('currentattempt', 'assign', $currentattempt);
485 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt,
486 'maxattempts'=>$maxattempts));
488 $cell2 = new html_table_cell($message);
489 $row->cells = array($cell1, $cell2);
493 $row = new html_table_row();
494 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
495 if (!$status->teamsubmissionenabled) {
496 if ($status->submission && $status->submission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
497 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign');
498 $cell2 = new html_table_cell($statusstr);
499 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
501 if (!$status->submissionsenabled) {
502 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
504 $cell2 = new html_table_cell(get_string('noattempt', 'assign'));
507 $row->cells = array($cell1, $cell2);
510 $row = new html_table_row();
511 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
512 $group = $status->submissiongroup;
513 if (!$group && $status->preventsubmissionnotingroup) {
514 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
515 } else if ($status->teamsubmission && $status->teamsubmission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
516 $teamstatus = $status->teamsubmission->status;
517 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
519 if ($status->submissiongroup) {
520 $groupid = $status->submissiongroup->id;
523 $members = $status->submissiongroupmemberswhoneedtosubmit;
524 $userslist = array();
525 foreach ($members as $member) {
526 $urlparams = array('id' => $member->id, 'course'=>$status->courseid);
527 $url = new moodle_url('/user/view.php', $urlparams);
528 if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
529 $userslist[] = $member->alias;
531 $fullname = fullname($member, $status->canviewfullnames);
532 $userslist[] = $this->output->action_link($url, $fullname);
535 if (count($userslist) > 0) {
536 $userstr = join(', ', $userslist);
537 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
538 $submissionsummary .= $this->output->container($formatteduserstr);
541 $cell2 = new html_table_cell($submissionsummary);
542 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
544 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
545 if (!$status->submissionsenabled) {
546 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
548 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
551 $row->cells = array($cell1, $cell2);
556 if ($status->locked) {
557 $row = new html_table_row();
558 $cell1 = new html_table_cell();
559 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
560 $cell2->attributes = array('class'=>'submissionlocked');
561 $row->cells = array($cell1, $cell2);
566 $row = new html_table_row();
567 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
569 if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
570 $status->gradingstatus == ASSIGN_GRADING_STATUS_NOT_GRADED) {
571 $cell2 = new html_table_cell(get_string($status->gradingstatus, 'assign'));
573 $gradingstatus = 'markingworkflowstate' . $status->gradingstatus;
574 $cell2 = new html_table_cell(get_string($gradingstatus, 'assign'));
576 if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
577 $status->gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
578 $cell2->attributes = array('class' => 'submissiongraded');
580 $cell2->attributes = array('class' => 'submissionnotgraded');
582 $row->cells = array($cell1, $cell2);
585 $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
586 $duedate = $status->duedate;
589 $row = new html_table_row();
590 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
591 $cell2 = new html_table_cell(userdate($duedate));
592 $row->cells = array($cell1, $cell2);
595 if ($status->view == assign_submission_status::GRADER_VIEW) {
596 if ($status->cutoffdate) {
598 $row = new html_table_row();
599 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
600 $cell2 = new html_table_cell(userdate($status->cutoffdate));
601 $row->cells = array($cell1, $cell2);
606 if ($status->extensionduedate) {
608 $row = new html_table_row();
609 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
610 $cell2 = new html_table_cell(userdate($status->extensionduedate));
611 $row->cells = array($cell1, $cell2);
613 $duedate = $status->extensionduedate;
617 $row = new html_table_row();
618 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
619 if ($duedate - $time <= 0) {
621 $submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
622 if ($status->submissionsenabled) {
623 $overduestr = get_string('overdue', 'assign', format_time($time - $duedate));
624 $cell2 = new html_table_cell($overduestr);
625 $cell2->attributes = array('class'=>'overdue');
627 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
630 if ($submission->timemodified > $duedate) {
631 $latestr = get_string('submittedlate',
633 format_time($submission->timemodified - $duedate));
634 $cell2 = new html_table_cell($latestr);
635 $cell2->attributes = array('class'=>'latesubmission');
637 $earlystr = get_string('submittedearly',
639 format_time($submission->timemodified - $duedate));
640 $cell2 = new html_table_cell($earlystr);
641 $cell2->attributes = array('class'=>'earlysubmission');
645 $cell2 = new html_table_cell(format_time($duedate - $time));
647 $row->cells = array($cell1, $cell2);
651 // Show graders whether this submission is editable by students.
652 if ($status->view == assign_submission_status::GRADER_VIEW) {
653 $row = new html_table_row();
654 $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
655 if ($status->canedit) {
656 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
657 $cell2->attributes = array('class'=>'submissioneditable');
659 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
660 $cell2->attributes = array('class'=>'submissionnoteditable');
662 $row->cells = array($cell1, $cell2);
666 // Grading criteria preview.
667 if (!empty($status->gradingcontrollerpreview)) {
668 $row = new html_table_row();
669 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
670 $cell2 = new html_table_cell($status->gradingcontrollerpreview);
671 $row->cells = array($cell1, $cell2);
677 $row = new html_table_row();
678 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
679 $cell2 = new html_table_cell(userdate($submission->timemodified));
680 $row->cells = array($cell1, $cell2);
683 if (!$status->teamsubmission || $status->submissiongroup != false || !$status->preventsubmissionnotingroup) {
684 foreach ($status->submissionplugins as $plugin) {
685 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
686 if ($plugin->is_enabled() &&
687 $plugin->is_visible() &&
688 $plugin->has_user_summary() &&
692 $row = new html_table_row();
693 $cell1 = new html_table_cell($plugin->get_name());
694 $displaymode = assign_submission_plugin_submission::SUMMARY;
695 $pluginsubmission = new assign_submission_plugin_submission($plugin,
698 $status->coursemoduleid,
699 $status->returnaction,
700 $status->returnparams);
701 $cell2 = new html_table_cell($this->render($pluginsubmission));
702 $row->cells = array($cell1, $cell2);
709 $o .= html_writer::table($t);
710 $o .= $this->output->box_end();
713 if ($status->view == assign_submission_status::STUDENT_VIEW) {
714 if ($status->canedit) {
715 if (!$submission || $submission->status == ASSIGN_SUBMISSION_STATUS_NEW) {
716 $o .= $this->output->box_start('generalbox submissionaction');
717 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
718 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
719 get_string('addsubmission', 'assign'), 'get');
720 $o .= $this->output->box_start('boxaligncenter submithelp');
721 $o .= get_string('editsubmission_help', 'assign');
722 $o .= $this->output->box_end();
723 $o .= $this->output->box_end();
724 } else if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
725 $o .= $this->output->box_start('generalbox submissionaction');
726 $urlparams = array('id' => $status->coursemoduleid,
727 'action' => 'editprevioussubmission',
728 'sesskey'=>sesskey());
729 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
730 get_string('addnewattemptfromprevious', 'assign'), 'get');
731 $o .= $this->output->box_start('boxaligncenter submithelp');
732 $o .= get_string('addnewattemptfromprevious_help', 'assign');
733 $o .= $this->output->box_end();
734 $o .= $this->output->box_end();
735 $o .= $this->output->box_start('generalbox submissionaction');
736 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
737 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
738 get_string('addnewattempt', 'assign'), 'get');
739 $o .= $this->output->box_start('boxaligncenter submithelp');
740 $o .= get_string('addnewattempt_help', 'assign');
741 $o .= $this->output->box_end();
742 $o .= $this->output->box_end();
744 $o .= $this->output->box_start('generalbox submissionaction');
745 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
746 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
747 get_string('editsubmission', 'assign'), 'get');
748 $o .= $this->output->box_start('boxaligncenter submithelp');
749 $o .= get_string('editsubmission_help', 'assign');
750 $o .= $this->output->box_end();
751 $o .= $this->output->box_end();
755 if ($status->cansubmit) {
756 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
757 $o .= $this->output->box_start('generalbox submissionaction');
758 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
759 get_string('submitassignment', 'assign'), 'get');
760 $o .= $this->output->box_start('boxaligncenter submithelp');
761 $o .= get_string('submitassignment_help', 'assign');
762 $o .= $this->output->box_end();
763 $o .= $this->output->box_end();
767 $o .= $this->output->container_end();
772 * Output the attempt history for this assignment
774 * @param assign_attempt_history $history
777 public function render_assign_attempt_history(assign_attempt_history $history) {
780 $submittedstr = get_string('submitted', 'assign');
781 $gradestr = get_string('grade');
782 $gradedonstr = get_string('gradedon', 'assign');
783 $gradedbystr = get_string('gradedby', 'assign');
785 // Don't show the last one because it is the current submission.
786 array_pop($history->submissions);
788 // Show newest to oldest.
789 $history->submissions = array_reverse($history->submissions);
791 if (empty($history->submissions)) {
795 $containerid = 'attempthistory' . uniqid();
796 $o .= $this->heading(get_string('attempthistory', 'assign'), 3);
797 $o .= $this->box_start('attempthistory', $containerid);
799 foreach ($history->submissions as $i => $submission) {
801 foreach ($history->grades as $onegrade) {
802 if ($onegrade->attemptnumber == $submission->attemptnumber) {
811 $submissionsummary = userdate($submission->timemodified);
813 $submissionsummary = get_string('nosubmission', 'assign');
816 $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+1,
817 'submissionsummary'=>$submissionsummary);
818 $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4);
820 $t = new html_table();
823 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
824 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status, 'assign'));
825 $t->data[] = new html_table_row(array($cell1, $cell2));
827 foreach ($history->submissionplugins as $plugin) {
828 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
829 if ($plugin->is_enabled() &&
830 $plugin->is_visible() &&
831 $plugin->has_user_summary() &&
832 $pluginshowsummary) {
834 $cell1 = new html_table_cell($plugin->get_name());
835 $pluginsubmission = new assign_submission_plugin_submission($plugin,
837 assign_submission_plugin_submission::SUMMARY,
838 $history->coursemoduleid,
839 $history->returnaction,
840 $history->returnparams);
841 $cell2 = new html_table_cell($this->render($pluginsubmission));
843 $t->data[] = new html_table_row(array($cell1, $cell2));
849 // Heading 'feedback'.
850 $title = get_string('feedback', 'assign', $i);
851 $title .= $this->output->spacer(array('width'=>10));
852 if ($history->cangrade) {
853 // Edit previous feedback.
854 $returnparams = http_build_query($history->returnparams);
855 $urlparams = array('id' => $history->coursemoduleid,
856 'rownum'=>$history->rownum,
857 'useridlistid'=>$history->useridlistid,
858 'attemptnumber'=>$grade->attemptnumber,
860 'returnaction'=>$history->returnaction,
861 'returnparams'=>$returnparams);
862 $url = new moodle_url('/mod/assign/view.php', $urlparams);
863 $icon = new pix_icon('gradefeedback',
864 get_string('editattemptfeedback', 'assign', $grade->attemptnumber+1),
866 $title .= $this->output->action_icon($url, $icon);
868 $cell = new html_table_cell($title);
869 $cell->attributes['class'] = 'feedbacktitle';
871 $t->data[] = new html_table_row(array($cell));
874 $cell1 = new html_table_cell($gradestr);
875 $cell2 = $grade->gradefordisplay;
876 $t->data[] = new html_table_row(array($cell1, $cell2));
879 $cell1 = new html_table_cell($gradedonstr);
880 $cell2 = new html_table_cell(userdate($grade->timemodified));
881 $t->data[] = new html_table_row(array($cell1, $cell2));
884 $cell1 = new html_table_cell($gradedbystr);
885 $cell2 = new html_table_cell($this->output->user_picture($grade->grader) .
886 $this->output->spacer(array('width'=>30)) . fullname($grade->grader));
887 $t->data[] = new html_table_row(array($cell1, $cell2));
889 // Feedback from plugins.
890 foreach ($history->feedbackplugins as $plugin) {
891 if ($plugin->is_enabled() &&
892 $plugin->is_visible() &&
893 $plugin->has_user_summary() &&
894 !$plugin->is_empty($grade)) {
896 $cell1 = new html_table_cell($plugin->get_name());
897 $pluginfeedback = new assign_feedback_plugin_feedback(
898 $plugin, $grade, assign_feedback_plugin_feedback::SUMMARY, $history->coursemoduleid,
899 $history->returnaction, $history->returnparams
901 $cell2 = new html_table_cell($this->render($pluginfeedback));
902 $t->data[] = new html_table_row(array($cell1, $cell2));
909 $o .= html_writer::table($t);
911 $o .= $this->box_end();
912 $jsparams = array($containerid);
914 $this->page->requires->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history');
920 * Render a submission plugin submission
922 * @param assign_submission_plugin_submission $submissionplugin
925 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
928 if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
929 $showviewlink = false;
930 $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission,
933 $classsuffix = $submissionplugin->plugin->get_subtype() .
935 $submissionplugin->plugin->get_type() .
937 $submissionplugin->submission->id;
939 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
943 $previewstr = get_string('viewsubmission', 'assign');
944 $icon = $this->output->pix_icon('t/preview', $previewstr);
946 $expandstr = get_string('viewfull', 'assign');
947 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
948 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
950 $jsparams = array($submissionplugin->plugin->get_subtype(),
951 $submissionplugin->plugin->get_type(),
952 $submissionplugin->submission->id);
954 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
956 $action = 'viewplugin' . $submissionplugin->plugin->get_subtype();
957 $returnparams = http_build_query($submissionplugin->returnparams);
958 $link .= '<noscript>';
959 $urlparams = array('id' => $submissionplugin->coursemoduleid,
960 'sid'=>$submissionplugin->submission->id,
961 'plugin'=>$submissionplugin->plugin->get_type(),
963 'returnaction'=>$submissionplugin->returnaction,
964 'returnparams'=>$returnparams);
965 $url = new moodle_url('/mod/assign/view.php', $urlparams);
966 $link .= $this->output->action_link($url, $icon);
967 $link .= '</noscript>';
969 $link .= $this->output->spacer(array('width'=>15));
972 $o .= $link . $summary;
973 $o .= $this->output->box_end();
975 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
976 $classes = 'expandsummaryicon contract_' . $classsuffix;
977 $o .= $this->output->pix_icon('t/switch_minus',
978 get_string('viewsummary', 'assign'),
980 array('class'=>$classes));
981 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
982 $o .= $this->output->box_end();
984 } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
985 $o .= $this->output->box_start('boxaligncenter submissionfull');
986 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
987 $o .= $this->output->box_end();
994 * Render the grading table.
996 * @param assign_grading_table $table
999 public function render_assign_grading_table(assign_grading_table $table) {
1001 $o .= $this->output->box_start('boxaligncenter gradingtable');
1003 $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
1004 $this->page->requires->string_for_js('nousersselected', 'assign');
1005 $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
1006 $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
1007 $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
1008 $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
1009 $this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign');
1010 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
1011 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
1012 $this->page->requires->string_for_js('editaction', 'assign');
1013 foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
1014 foreach ($operations as $operation => $description) {
1015 $this->page->requires->string_for_js('batchoperationconfirm' . $operation,
1016 'assignfeedback_' . $plugin);
1019 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
1020 $o .= $this->output->box_end();
1026 * Render a feedback plugin feedback
1028 * @param assign_feedback_plugin_feedback $feedbackplugin
1031 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
1034 if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
1035 $showviewlink = false;
1036 $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
1038 $classsuffix = $feedbackplugin->plugin->get_subtype() .
1040 $feedbackplugin->plugin->get_type() .
1042 $feedbackplugin->grade->id;
1043 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1046 if ($showviewlink) {
1047 $previewstr = get_string('viewfeedback', 'assign');
1048 $icon = $this->output->pix_icon('t/preview', $previewstr);
1050 $expandstr = get_string('viewfull', 'assign');
1051 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1052 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
1054 $jsparams = array($feedbackplugin->plugin->get_subtype(),
1055 $feedbackplugin->plugin->get_type(),
1056 $feedbackplugin->grade->id);
1057 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1059 $urlparams = array('id' => $feedbackplugin->coursemoduleid,
1060 'gid'=>$feedbackplugin->grade->id,
1061 'plugin'=>$feedbackplugin->plugin->get_type(),
1062 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
1063 'returnaction'=>$feedbackplugin->returnaction,
1064 'returnparams'=>http_build_query($feedbackplugin->returnparams));
1065 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1066 $link .= '<noscript>';
1067 $link .= $this->output->action_link($url, $icon);
1068 $link .= '</noscript>';
1070 $link .= $this->output->spacer(array('width'=>15));
1073 $o .= $link . $summary;
1074 $o .= $this->output->box_end();
1075 if ($showviewlink) {
1076 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
1077 $classes = 'expandsummaryicon contract_' . $classsuffix;
1078 $o .= $this->output->pix_icon('t/switch_minus',
1079 get_string('viewsummary', 'assign'),
1081 array('class'=>$classes));
1082 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1083 $o .= $this->output->box_end();
1085 } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
1086 $o .= $this->output->box_start('boxaligncenter feedbackfull');
1087 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1088 $o .= $this->output->box_end();
1095 * Render a course index summary
1097 * @param assign_course_index_summary $indexsummary
1100 public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
1103 $strplural = get_string('modulenameplural', 'assign');
1104 $strsectionname = $indexsummary->courseformatname;
1105 $strduedate = get_string('duedate', 'assign');
1106 $strsubmission = get_string('submission', 'assign');
1107 $strgrade = get_string('grade');
1109 $table = new html_table();
1110 if ($indexsummary->usesections) {
1111 $table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
1112 $table->align = array ('left', 'left', 'center', 'right', 'right');
1114 $table->head = array ($strplural, $strduedate, $strsubmission, $strgrade);
1115 $table->align = array ('left', 'left', 'center', 'right');
1117 $table->data = array();
1119 $currentsection = '';
1120 foreach ($indexsummary->assignments as $info) {
1121 $params = array('id' => $info['cmid']);
1122 $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
1124 $due = $info['timedue'] ? userdate($info['timedue']) : '-';
1127 if ($indexsummary->usesections) {
1128 if ($info['sectionname'] !== $currentsection) {
1129 if ($info['sectionname']) {
1130 $printsection = $info['sectionname'];
1132 if ($currentsection !== '') {
1133 $table->data[] = 'hr';
1135 $currentsection = $info['sectionname'];
1139 if ($indexsummary->usesections) {
1140 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
1142 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
1144 $table->data[] = $row;
1147 $o .= html_writer::table($table);
1155 * Internal function - creates htmls structure suitable for YUI tree.
1157 * @param assign_files $tree
1161 protected function htmllize_tree(assign_files $tree, $dir) {
1163 $yuiconfig = array();
1164 $yuiconfig['type'] = 'html';
1166 if (empty($dir['subdirs']) and empty($dir['files'])) {
1171 foreach ($dir['subdirs'] as $subdir) {
1172 $image = $this->output->pix_icon(file_folder_icon(),
1175 array('class'=>'icon'));
1176 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1177 '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
1178 $this->htmllize_tree($tree, $subdir) .
1182 foreach ($dir['files'] as $file) {
1183 $filename = $file->get_filename();
1184 if ($CFG->enableplagiarism) {
1185 require_once($CFG->libdir.'/plagiarismlib.php');
1186 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(),
1188 'cmid'=>$tree->cm->id,
1189 'course'=>$tree->course));
1191 $plagiarismlinks = '';
1193 $image = $this->output->pix_icon(file_file_icon($file),
1196 array('class'=>'icon'));
1197 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1198 '<div>' . $image . ' ' .
1199 $file->fileurl . ' ' .
1201 $file->portfoliobutton . '</div>' .
1211 * Helper method dealing with the fact we can not just fetch the output of flexible_table
1213 * @param flexible_table $table The table to render
1214 * @param int $rowsperpage How many assignments to render in a page
1215 * @param bool $displaylinks - Whether to render links in the table
1216 * (e.g. downloads would not enable this)
1217 * @return string HTML
1219 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
1223 $table->out($rowsperpage, $displaylinks);
1224 $o = ob_get_contents();
1231 * Helper method dealing with the fact we can not just fetch the output of moodleforms
1233 * @param moodleform $mform
1234 * @return string HTML
1236 protected function moodleform(moodleform $mform) {
1241 $o = ob_get_contents();