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 $url = new moodle_url('/mod/assign/view.php', $urlparams);
97 $o .= $this->output->heading($result->heading, 4);
98 $o .= $this->output->notification($result->message);
99 $o .= $this->output->continue_button($url);
104 * Render the generic form
105 * @param assign_form $form The form to render
108 public function render_assign_form(assign_form $form) {
110 if ($form->jsinitfunction) {
111 $this->page->requires->js_init_call($form->jsinitfunction, array());
113 $o .= $this->output->box_start('boxaligncenter ' . $form->classname);
114 $o .= $this->moodleform($form->form);
115 $o .= $this->output->box_end();
120 * Render the user summary
122 * @param assign_user_summary $summary The user summary to render
125 public function render_assign_user_summary(assign_user_summary $summary) {
130 if (!$summary->user) {
134 if ($summary->suspendeduser) {
135 $supendedclass = ' usersuspended';
136 $suspendedstring = get_string('userenrolmentsuspended', 'grades');
137 $suspendedicon = ' ' . html_writer::empty_tag('img', array('src' => $this->pix_url('i/enrolmentsuspended'),
138 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
140 $o .= $this->output->container_start('usersummary');
141 $o .= $this->output->box_start('boxaligncenter usersummarysection'.$supendedclass);
142 if ($summary->blindmarking) {
143 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser.$suspendedicon;
145 $o .= $this->output->user_picture($summary->user);
146 $o .= $this->output->spacer(array('width'=>30));
147 $urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid);
148 $url = new moodle_url('/user/view.php', $urlparams);
149 $fullname = fullname($summary->user, $summary->viewfullnames);
150 $extrainfo = array();
151 foreach ($summary->extrauserfields as $extrafield) {
152 $extrainfo[] = $summary->user->$extrafield;
154 if (count($extrainfo)) {
155 $fullname .= ' (' . implode(', ', $extrainfo) . ')';
157 $fullname .= $suspendedicon;
158 $o .= $this->output->action_link($url, $fullname);
160 $o .= $this->output->box_end();
161 $o .= $this->output->container_end();
167 * Render the submit for grading page
169 * @param assign_submit_for_grading_page $page
172 public function render_assign_submit_for_grading_page($page) {
175 $o .= $this->output->container_start('submitforgrading');
176 $o .= $this->output->heading(get_string('submitassignment', 'assign'), 3);
177 $o .= $this->output->spacer(array('height'=>30));
179 $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
180 if (count($page->notifications)) {
181 // At least one of the submission plugins is not ready for submission.
183 $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
185 foreach ($page->notifications as $notification) {
186 $o .= $this->output->notification($notification);
189 $o .= $this->output->continue_button($cancelurl);
191 // All submission plugins ready - show the confirmation form.
192 $o .= $this->output->box_start('generalbox submitconfirm');
193 $o .= $this->moodleform($page->confirmform);
194 $o .= $this->output->box_end();
196 $o .= $this->output->container_end();
202 * Page is done - render the footer.
206 public function render_footer() {
207 return $this->output->footer();
213 * @param assign_header $header
216 public function render_assign_header(assign_header $header) {
219 if ($header->subpage) {
220 $this->page->navbar->add($header->subpage);
223 $this->page->set_title(get_string('pluginname', 'assign'));
224 $this->page->set_heading($this->page->course->fullname);
226 $o .= $this->output->header();
227 $heading = format_string($header->assign->name, false, array('context' => $header->context));
228 $o .= $this->output->heading($heading);
229 if ($header->preface) {
230 $o .= $header->preface;
233 if ($header->showintro) {
234 $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
235 $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
236 $o .= $this->output->box_end();
243 * Render the header for an individual plugin.
245 * @param assign_plugin_header $header
248 public function render_assign_plugin_header(assign_plugin_header $header) {
249 $o = $header->plugin->view_header();
254 * Render a table containing the current status of the grading process.
256 * @param assign_grading_summary $summary
259 public function render_assign_grading_summary(assign_grading_summary $summary) {
260 // Create a table for the data.
262 $o .= $this->output->container_start('gradingsummary');
263 $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
264 $o .= $this->output->box_start('boxaligncenter gradingsummarytable');
265 $t = new html_table();
268 if ($summary->teamsubmission) {
269 $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
270 $summary->participantcount);
272 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
273 $summary->participantcount);
276 // Drafts count and dont show drafts count when using offline assignment.
277 if ($summary->submissiondraftsenabled && $summary->submissionsenabled) {
278 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
279 $summary->submissiondraftscount);
282 // Submitted for grading.
283 if ($summary->submissionsenabled) {
284 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
285 $summary->submissionssubmittedcount);
286 if (!$summary->teamsubmission) {
287 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
288 $summary->submissionsneedgradingcount);
293 if ($summary->duedate) {
295 $duedate = $summary->duedate;
296 $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
301 if ($duedate - $time <= 0) {
302 $due = get_string('assignmentisdue', 'assign');
304 $due = format_time($duedate - $time);
306 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
308 if ($duedate < $time) {
309 $cutoffdate = $summary->cutoffdate;
311 if ($cutoffdate > $time) {
312 $late = get_string('latesubmissionsaccepted', 'assign');
314 $late = get_string('nomoresubmissionsaccepted', 'assign');
316 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
322 // All done - write the table.
323 $o .= html_writer::table($t);
324 $o .= $this->output->box_end();
326 // Link to the grading page.
327 $o .= $this->output->container_start('submissionlinks');
328 $urlparams = array('id' => $summary->coursemoduleid, 'action'=>'grading');
329 $url = new moodle_url('/mod/assign/view.php', $urlparams);
330 $o .= $this->output->action_link($url, get_string('viewgrading', 'assign'));
331 $o .= $this->output->container_end();
333 // Close the container and insert a spacer.
334 $o .= $this->output->container_end();
340 * Render a table containing all the current grades and feedback.
342 * @param assign_feedback_status $status
345 public function render_assign_feedback_status(assign_feedback_status $status) {
349 $o .= $this->output->container_start('feedback');
350 $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
351 $o .= $this->output->box_start('boxaligncenter feedbacktable');
352 $t = new html_table();
355 if (isset($status->gradefordisplay)) {
356 $row = new html_table_row();
357 $cell1 = new html_table_cell(get_string('grade'));
358 $cell2 = new html_table_cell($status->gradefordisplay);
359 $row->cells = array($cell1, $cell2);
363 $row = new html_table_row();
364 $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
365 $cell2 = new html_table_cell(userdate($status->gradeddate));
366 $row->cells = array($cell1, $cell2);
370 if ($status->grader) {
372 $row = new html_table_row();
373 $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
374 $userdescription = $this->output->user_picture($status->grader) .
375 $this->output->spacer(array('width'=>30)) .
376 fullname($status->grader);
377 $cell2 = new html_table_cell($userdescription);
378 $row->cells = array($cell1, $cell2);
382 foreach ($status->feedbackplugins as $plugin) {
383 if ($plugin->is_enabled() &&
384 $plugin->is_visible() &&
385 $plugin->has_user_summary() &&
386 !empty($status->grade) &&
387 !$plugin->is_empty($status->grade)) {
389 $row = new html_table_row();
390 $cell1 = new html_table_cell($plugin->get_name());
391 $displaymode = assign_feedback_plugin_feedback::SUMMARY;
392 $pluginfeedback = new assign_feedback_plugin_feedback($plugin,
395 $status->coursemoduleid,
396 $status->returnaction,
397 $status->returnparams);
398 $cell2 = new html_table_cell($this->render($pluginfeedback));
399 $row->cells = array($cell1, $cell2);
404 $o .= html_writer::table($t);
405 $o .= $this->output->box_end();
407 $o .= $this->output->container_end();
412 * Render a table containing the current status of the submission.
414 * @param assign_submission_status $status
417 public function render_assign_submission_status(assign_submission_status $status) {
419 $o .= $this->output->container_start('submissionstatustable');
420 $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
423 if ($status->allowsubmissionsfromdate &&
424 $time <= $status->allowsubmissionsfromdate) {
425 $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
426 if ($status->alwaysshowdescription) {
427 $date = userdate($status->allowsubmissionsfromdate);
428 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
430 $date = userdate($status->allowsubmissionsfromdate);
431 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
433 $o .= $this->output->box_end();
435 $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
437 $t = new html_table();
439 if ($status->teamsubmissionenabled) {
440 $row = new html_table_row();
441 $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
442 $group = $status->submissiongroup;
444 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
446 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
448 $row->cells = array($cell1, $cell2);
452 if ($status->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
454 if (!$status->teamsubmissionenabled) {
455 if ($status->submission) {
456 $currentattempt = $status->submission->attemptnumber + 1;
459 if ($status->teamsubmission) {
460 $currentattempt = $status->teamsubmission->attemptnumber + 1;
464 $row = new html_table_row();
465 $cell1 = new html_table_cell(get_string('attemptnumber', 'assign'));
466 $maxattempts = $status->maxattempts;
467 if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) {
468 $message = get_string('currentattempt', 'assign', $currentattempt);
470 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt,
471 'maxattempts'=>$maxattempts));
473 $cell2 = new html_table_cell($message);
474 $row->cells = array($cell1, $cell2);
478 $row = new html_table_row();
479 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
480 if (!$status->teamsubmissionenabled) {
481 if ($status->submission) {
482 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign');
483 $cell2 = new html_table_cell($statusstr);
484 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
486 if (!$status->submissionsenabled) {
487 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
489 $cell2 = new html_table_cell(get_string('noattempt', 'assign'));
492 $row->cells = array($cell1, $cell2);
495 $row = new html_table_row();
496 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
497 if ($status->teamsubmission) {
498 $teamstatus = $status->teamsubmission->status;
499 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
501 if ($status->submissiongroup) {
502 $groupid = $status->submissiongroup->id;
505 $members = $status->submissiongroupmemberswhoneedtosubmit;
506 $userslist = array();
507 foreach ($members as $member) {
508 $urlparams = array('id' => $member->id, 'course'=>$status->courseid);
509 $url = new moodle_url('/user/view.php', $urlparams);
510 if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
511 $userslist[] = $member->alias;
513 $fullname = fullname($member, $status->canviewfullnames);
514 $userslist[] = $this->output->action_link($url, $fullname);
517 if (count($userslist) > 0) {
518 $userstr = join(', ', $userslist);
519 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
520 $submissionsummary .= $this->output->container($formatteduserstr);
523 $cell2 = new html_table_cell($submissionsummary);
524 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
526 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
527 if (!$status->submissionsenabled) {
528 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
530 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
533 $row->cells = array($cell1, $cell2);
538 if ($status->locked) {
539 $row = new html_table_row();
540 $cell1 = new html_table_cell();
541 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
542 $cell2->attributes = array('class'=>'submissionlocked');
543 $row->cells = array($cell1, $cell2);
548 $row = new html_table_row();
549 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
551 if ($status->graded) {
552 $cell2 = new html_table_cell(get_string('graded', 'assign'));
553 $cell2->attributes = array('class'=>'submissiongraded');
555 $cell2 = new html_table_cell(get_string('notgraded', 'assign'));
556 $cell2->attributes = array('class'=>'submissionnotgraded');
558 $row->cells = array($cell1, $cell2);
561 $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
562 $duedate = $status->duedate;
565 $row = new html_table_row();
566 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
567 $cell2 = new html_table_cell(userdate($duedate));
568 $row->cells = array($cell1, $cell2);
571 if ($status->view == assign_submission_status::GRADER_VIEW) {
572 if ($status->cutoffdate) {
574 $row = new html_table_row();
575 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
576 $cell2 = new html_table_cell(userdate($status->cutoffdate));
577 $row->cells = array($cell1, $cell2);
582 if ($status->extensionduedate) {
584 $row = new html_table_row();
585 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
586 $cell2 = new html_table_cell(userdate($status->extensionduedate));
587 $row->cells = array($cell1, $cell2);
589 $duedate = $status->extensionduedate;
593 $row = new html_table_row();
594 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
595 if ($duedate - $time <= 0) {
597 $submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
598 if ($status->submissionsenabled) {
599 $overduestr = get_string('overdue', 'assign', format_time($time - $duedate));
600 $cell2 = new html_table_cell($overduestr);
601 $cell2->attributes = array('class'=>'overdue');
603 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
606 if ($submission->timemodified > $duedate) {
607 $latestr = get_string('submittedlate',
609 format_time($submission->timemodified - $duedate));
610 $cell2 = new html_table_cell($latestr);
611 $cell2->attributes = array('class'=>'latesubmission');
613 $earlystr = get_string('submittedearly',
615 format_time($submission->timemodified - $duedate));
616 $cell2 = new html_table_cell($earlystr);
617 $cell2->attributes = array('class'=>'earlysubmission');
621 $cell2 = new html_table_cell(format_time($duedate - $time));
623 $row->cells = array($cell1, $cell2);
627 // Show graders whether this submission is editable by students.
628 if ($status->view == assign_submission_status::GRADER_VIEW) {
629 $row = new html_table_row();
630 $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
631 if ($status->canedit) {
632 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
633 $cell2->attributes = array('class'=>'submissioneditable');
635 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
636 $cell2->attributes = array('class'=>'submissionnoteditable');
638 $row->cells = array($cell1, $cell2);
642 // Grading criteria preview.
643 if (!empty($status->gradingcontrollerpreview)) {
644 $row = new html_table_row();
645 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
646 $cell2 = new html_table_cell($status->gradingcontrollerpreview);
647 $row->cells = array($cell1, $cell2);
653 $row = new html_table_row();
654 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
655 $cell2 = new html_table_cell(userdate($submission->timemodified));
656 $row->cells = array($cell1, $cell2);
659 foreach ($status->submissionplugins as $plugin) {
660 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
661 if ($plugin->is_enabled() &&
662 $plugin->is_visible() &&
663 $plugin->has_user_summary() &&
664 $pluginshowsummary) {
666 $row = new html_table_row();
667 $cell1 = new html_table_cell($plugin->get_name());
668 $displaymode = assign_submission_plugin_submission::SUMMARY;
669 $pluginsubmission = new assign_submission_plugin_submission($plugin,
672 $status->coursemoduleid,
673 $status->returnaction,
674 $status->returnparams);
675 $cell2 = new html_table_cell($this->render($pluginsubmission));
676 $row->cells = array($cell1, $cell2);
682 $o .= html_writer::table($t);
683 $o .= $this->output->box_end();
686 if ($status->view == assign_submission_status::STUDENT_VIEW) {
687 if ($status->canedit) {
689 $o .= $this->output->box_start('generalbox submissionaction');
690 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
691 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
692 get_string('addsubmission', 'assign'), 'get');
693 $o .= $this->output->box_start('boxaligncenter submithelp');
694 $o .= get_string('editsubmission_help', 'assign');
695 $o .= $this->output->box_end();
696 $o .= $this->output->box_end();
697 } else if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
698 $o .= $this->output->box_start('generalbox submissionaction');
699 $urlparams = array('id' => $status->coursemoduleid,
700 'action' => 'editprevioussubmission',
701 'sesskey'=>sesskey());
702 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
703 get_string('addnewattemptfromprevious', 'assign'), 'get');
704 $o .= $this->output->box_start('boxaligncenter submithelp');
705 $o .= get_string('addnewattemptfromprevious_help', 'assign');
706 $o .= $this->output->box_end();
707 $o .= $this->output->box_end();
708 $o .= $this->output->box_start('generalbox submissionaction');
709 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
710 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
711 get_string('addnewattempt', 'assign'), 'get');
712 $o .= $this->output->box_start('boxaligncenter submithelp');
713 $o .= get_string('addnewattempt_help', 'assign');
714 $o .= $this->output->box_end();
715 $o .= $this->output->box_end();
717 $o .= $this->output->box_start('generalbox submissionaction');
718 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
719 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
720 get_string('editsubmission', 'assign'), 'get');
721 $o .= $this->output->box_start('boxaligncenter submithelp');
722 $o .= get_string('editsubmission_help', 'assign');
723 $o .= $this->output->box_end();
724 $o .= $this->output->box_end();
728 if ($status->cansubmit) {
729 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
730 $o .= $this->output->box_start('generalbox submissionaction');
731 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
732 get_string('submitassignment', 'assign'), 'get');
733 $o .= $this->output->box_start('boxaligncenter submithelp');
734 $o .= get_string('submitassignment_help', 'assign');
735 $o .= $this->output->box_end();
736 $o .= $this->output->box_end();
740 $o .= $this->output->container_end();
745 * Output the attempt history for this assignment
747 * @param assign_attempt_history $history
750 public function render_assign_attempt_history(assign_attempt_history $history) {
753 $submittedstr = get_string('submitted', 'assign');
754 $gradestr = get_string('grade');
755 $gradedonstr = get_string('gradedon', 'assign');
756 $gradedbystr = get_string('gradedby', 'assign');
758 // Don't show the last one because it is the current submission.
759 array_pop($history->submissions);
761 // Show newest to oldest.
762 $history->submissions = array_reverse($history->submissions);
764 if (empty($history->submissions)) {
768 $containerid = 'attempthistory' . uniqid();
769 $o .= $this->heading(get_string('attempthistory', 'assign'), 3);
770 $o .= $this->box_start('attempthistory', $containerid);
772 foreach ($history->submissions as $i => $submission) {
774 foreach ($history->grades as $onegrade) {
775 if ($onegrade->attemptnumber == $submission->attemptnumber) {
784 $submissionsummary = userdate($submission->timemodified);
786 $submissionsummary = get_string('nosubmission', 'assign');
789 $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+1,
790 'submissionsummary'=>$submissionsummary);
791 $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4);
793 $t = new html_table();
796 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
797 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status, 'assign'));
798 $t->data[] = new html_table_row(array($cell1, $cell2));
800 foreach ($history->submissionplugins as $plugin) {
801 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
802 if ($plugin->is_enabled() &&
803 $plugin->is_visible() &&
804 $plugin->has_user_summary() &&
805 $pluginshowsummary) {
807 $cell1 = new html_table_cell($plugin->get_name());
808 $pluginsubmission = new assign_submission_plugin_submission($plugin,
810 assign_submission_plugin_submission::SUMMARY,
811 $history->coursemoduleid,
812 $history->returnaction,
813 $history->returnparams);
814 $cell2 = new html_table_cell($this->render($pluginsubmission));
816 $t->data[] = new html_table_row(array($cell1, $cell2));
822 // Heading 'feedback'.
823 $title = get_string('feedback', 'assign', $i);
824 $title .= $this->output->spacer(array('width'=>10));
825 if ($history->cangrade) {
826 // Edit previous feedback.
827 $returnparams = http_build_query($history->returnparams);
828 $urlparams = array('id' => $history->coursemoduleid,
829 'rownum'=>$history->rownum,
830 'useridlistid'=>$history->useridlistid,
831 'attemptnumber'=>$grade->attemptnumber,
833 'returnaction'=>$history->returnaction,
834 'returnparams'=>$returnparams);
835 $url = new moodle_url('/mod/assign/view.php', $urlparams);
836 $icon = new pix_icon('gradefeedback',
837 get_string('editattemptfeedback', 'assign', $grade->attemptnumber+1),
839 $title .= $this->output->action_icon($url, $icon);
841 $cell = new html_table_cell($title);
842 $cell->attributes['class'] = 'feedbacktitle';
844 $t->data[] = new html_table_row(array($cell));
847 $cell1 = new html_table_cell($gradestr);
848 $cell2 = $grade->gradefordisplay;
849 $t->data[] = new html_table_row(array($cell1, $cell2));
852 $cell1 = new html_table_cell($gradedonstr);
853 $cell2 = new html_table_cell(userdate($grade->timemodified));
854 $t->data[] = new html_table_row(array($cell1, $cell2));
857 $cell1 = new html_table_cell($gradedbystr);
858 $cell2 = new html_table_cell($this->output->user_picture($grade->grader) .
859 $this->output->spacer(array('width'=>30)) . fullname($grade->grader));
860 $t->data[] = new html_table_row(array($cell1, $cell2));
862 // Feedback from plugins.
863 foreach ($history->feedbackplugins as $plugin) {
864 if ($plugin->is_enabled() &&
865 $plugin->is_visible() &&
866 $plugin->has_user_summary() &&
867 !$plugin->is_empty($grade)) {
869 $cell1 = new html_table_cell($plugin->get_name());
870 $pluginfeedback = new assign_feedback_plugin_feedback(
871 $plugin, $grade, assign_feedback_plugin_feedback::SUMMARY, $history->coursemoduleid,
872 $history->returnaction, $history->returnparams
874 $cell2 = new html_table_cell($this->render($pluginfeedback));
875 $t->data[] = new html_table_row(array($cell1, $cell2));
882 $o .= html_writer::table($t);
884 $o .= $this->box_end();
885 $jsparams = array($containerid);
887 $this->page->requires->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history');
893 * Render a submission plugin submission
895 * @param assign_submission_plugin_submission $submissionplugin
898 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
901 if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
902 $showviewlink = false;
903 $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission,
906 $classsuffix = $submissionplugin->plugin->get_subtype() .
908 $submissionplugin->plugin->get_type() .
910 $submissionplugin->submission->id;
912 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
916 $previewstr = get_string('viewsubmission', 'assign');
917 $icon = $this->output->pix_icon('t/preview', $previewstr);
919 $expandstr = get_string('viewfull', 'assign');
920 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
921 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
923 $jsparams = array($submissionplugin->plugin->get_subtype(),
924 $submissionplugin->plugin->get_type(),
925 $submissionplugin->submission->id);
927 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
929 $action = 'viewplugin' . $submissionplugin->plugin->get_subtype();
930 $returnparams = http_build_query($submissionplugin->returnparams);
931 $link .= '<noscript>';
932 $urlparams = array('id' => $submissionplugin->coursemoduleid,
933 'sid'=>$submissionplugin->submission->id,
934 'plugin'=>$submissionplugin->plugin->get_type(),
936 'returnaction'=>$submissionplugin->returnaction,
937 'returnparams'=>$returnparams);
938 $url = new moodle_url('/mod/assign/view.php', $urlparams);
939 $link .= $this->output->action_link($url, $icon);
940 $link .= '</noscript>';
942 $link .= $this->output->spacer(array('width'=>15));
945 $o .= $link . $summary;
946 $o .= $this->output->box_end();
948 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
949 $classes = 'expandsummaryicon contract_' . $classsuffix;
950 $o .= $this->output->pix_icon('t/switch_minus',
951 get_string('viewsummary', 'assign'),
953 array('class'=>$classes));
954 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
955 $o .= $this->output->box_end();
957 } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
958 $o .= $this->output->box_start('boxaligncenter submissionfull');
959 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
960 $o .= $this->output->box_end();
967 * Render the grading table.
969 * @param assign_grading_table $table
972 public function render_assign_grading_table(assign_grading_table $table) {
974 $o .= $this->output->box_start('boxaligncenter gradingtable');
976 $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
977 $this->page->requires->string_for_js('nousersselected', 'assign');
978 $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
979 $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
980 $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
981 $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
982 $this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign');
983 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
984 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
985 $this->page->requires->string_for_js('editaction', 'assign');
986 foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
987 foreach ($operations as $operation => $description) {
988 $this->page->requires->string_for_js('batchoperationconfirm' . $operation,
989 'assignfeedback_' . $plugin);
992 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
993 $o .= $this->output->box_end();
999 * Render a feedback plugin feedback
1001 * @param assign_feedback_plugin_feedback $feedbackplugin
1004 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
1007 if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
1008 $showviewlink = false;
1009 $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
1011 $classsuffix = $feedbackplugin->plugin->get_subtype() .
1013 $feedbackplugin->plugin->get_type() .
1015 $feedbackplugin->grade->id;
1016 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1019 if ($showviewlink) {
1020 $previewstr = get_string('viewfeedback', 'assign');
1021 $icon = $this->output->pix_icon('t/preview', $previewstr);
1023 $expandstr = get_string('viewfull', 'assign');
1024 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1025 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
1027 $jsparams = array($feedbackplugin->plugin->get_subtype(),
1028 $feedbackplugin->plugin->get_type(),
1029 $feedbackplugin->grade->id);
1030 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1032 $urlparams = array('id' => $feedbackplugin->coursemoduleid,
1033 'gid'=>$feedbackplugin->grade->id,
1034 'plugin'=>$feedbackplugin->plugin->get_type(),
1035 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
1036 'returnaction'=>$feedbackplugin->returnaction,
1037 'returnparams'=>http_build_query($feedbackplugin->returnparams));
1038 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1039 $link .= '<noscript>';
1040 $link .= $this->output->action_link($url, $icon);
1041 $link .= '</noscript>';
1043 $link .= $this->output->spacer(array('width'=>15));
1046 $o .= $link . $summary;
1047 $o .= $this->output->box_end();
1048 if ($showviewlink) {
1049 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
1050 $classes = 'expandsummaryicon contract_' . $classsuffix;
1051 $o .= $this->output->pix_icon('t/switch_minus',
1052 get_string('viewsummary', 'assign'),
1054 array('class'=>$classes));
1055 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1056 $o .= $this->output->box_end();
1058 } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
1059 $o .= $this->output->box_start('boxaligncenter feedbackfull');
1060 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1061 $o .= $this->output->box_end();
1068 * Render a course index summary
1070 * @param assign_course_index_summary $indexsummary
1073 public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
1076 $strplural = get_string('modulenameplural', 'assign');
1077 $strsectionname = $indexsummary->courseformatname;
1078 $strduedate = get_string('duedate', 'assign');
1079 $strsubmission = get_string('submission', 'assign');
1080 $strgrade = get_string('grade');
1082 $table = new html_table();
1083 if ($indexsummary->usesections) {
1084 $table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
1085 $table->align = array ('left', 'left', 'center', 'right', 'right');
1087 $table->head = array ($strplural, $strduedate, $strsubmission, $strgrade);
1088 $table->align = array ('left', 'left', 'center', 'right');
1090 $table->data = array();
1092 $currentsection = '';
1093 foreach ($indexsummary->assignments as $info) {
1094 $params = array('id' => $info['cmid']);
1095 $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
1097 $due = $info['timedue'] ? userdate($info['timedue']) : '-';
1100 if ($indexsummary->usesections) {
1101 if ($info['sectionname'] !== $currentsection) {
1102 if ($info['sectionname']) {
1103 $printsection = $info['sectionname'];
1105 if ($currentsection !== '') {
1106 $table->data[] = 'hr';
1108 $currentsection = $info['sectionname'];
1112 if ($indexsummary->usesections) {
1113 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
1115 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
1117 $table->data[] = $row;
1120 $o .= html_writer::table($table);
1128 * Internal function - creates htmls structure suitable for YUI tree.
1130 * @param assign_files $tree
1134 protected function htmllize_tree(assign_files $tree, $dir) {
1136 $yuiconfig = array();
1137 $yuiconfig['type'] = 'html';
1139 if (empty($dir['subdirs']) and empty($dir['files'])) {
1144 foreach ($dir['subdirs'] as $subdir) {
1145 $image = $this->output->pix_icon(file_folder_icon(),
1148 array('class'=>'icon'));
1149 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1150 '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
1151 $this->htmllize_tree($tree, $subdir) .
1155 foreach ($dir['files'] as $file) {
1156 $filename = $file->get_filename();
1157 if ($CFG->enableplagiarism) {
1158 require_once($CFG->libdir.'/plagiarismlib.php');
1159 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(),
1161 'cmid'=>$tree->cm->id,
1162 'course'=>$tree->course));
1164 $plagiarismlinks = '';
1166 $image = $this->output->pix_icon(file_file_icon($file),
1169 array('class'=>'icon'));
1170 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1171 '<div>' . $image . ' ' .
1172 $file->fileurl . ' ' .
1174 $file->portfoliobutton . '</div>' .
1184 * Helper method dealing with the fact we can not just fetch the output of flexible_table
1186 * @param flexible_table $table The table to render
1187 * @param int $rowsperpage How many assignments to render in a page
1188 * @param bool $displaylinks - Whether to render links in the table
1189 * (e.g. downloads would not enable this)
1190 * @return string HTML
1192 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
1196 $table->out($rowsperpage, $displaylinks);
1197 $o = ob_get_contents();
1204 * Helper method dealing with the fact we can not just fetch the output of moodleforms
1206 * @param moodleform $mform
1207 * @return string HTML
1209 protected function moodleform(moodleform $mform) {
1214 $o = ob_get_contents();