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);
95 $classes = $result->gradingerror ? 'notifyproblem' : 'notifysuccess';
98 $o .= $this->output->heading($result->heading, 4);
99 $o .= $this->output->notification($result->message, $classes);
100 $o .= $this->output->continue_button($url);
105 * Render the generic form
106 * @param assign_form $form The form to render
109 public function render_assign_form(assign_form $form) {
111 if ($form->jsinitfunction) {
112 $this->page->requires->js_init_call($form->jsinitfunction, array());
114 $o .= $this->output->box_start('boxaligncenter ' . $form->classname);
115 $o .= $this->moodleform($form->form);
116 $o .= $this->output->box_end();
121 * Render the user summary
123 * @param assign_user_summary $summary The user summary to render
126 public function render_assign_user_summary(assign_user_summary $summary) {
131 if (!$summary->user) {
135 if ($summary->suspendeduser) {
136 $supendedclass = ' usersuspended';
137 $suspendedstring = get_string('userenrolmentsuspended', 'grades');
138 $suspendedicon = ' ' . html_writer::empty_tag('img', array('src' => $this->pix_url('i/enrolmentsuspended'),
139 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
141 $o .= $this->output->container_start('usersummary');
142 $o .= $this->output->box_start('boxaligncenter usersummarysection'.$supendedclass);
143 if ($summary->blindmarking) {
144 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser.$suspendedicon;
146 $o .= $this->output->user_picture($summary->user);
147 $o .= $this->output->spacer(array('width'=>30));
148 $urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid);
149 $url = new moodle_url('/user/view.php', $urlparams);
150 $fullname = fullname($summary->user, $summary->viewfullnames);
151 $extrainfo = array();
152 foreach ($summary->extrauserfields as $extrafield) {
153 $extrainfo[] = $summary->user->$extrafield;
155 if (count($extrainfo)) {
156 $fullname .= ' (' . implode(', ', $extrainfo) . ')';
158 $fullname .= $suspendedicon;
159 $o .= $this->output->action_link($url, $fullname);
161 $o .= $this->output->box_end();
162 $o .= $this->output->container_end();
168 * Render the submit for grading page
170 * @param assign_submit_for_grading_page $page
173 public function render_assign_submit_for_grading_page($page) {
176 $o .= $this->output->container_start('submitforgrading');
177 $o .= $this->output->heading(get_string('submitassignment', 'assign'), 3);
178 $o .= $this->output->spacer(array('height'=>30));
180 $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
181 if (count($page->notifications)) {
182 // At least one of the submission plugins is not ready for submission.
184 $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
186 foreach ($page->notifications as $notification) {
187 $o .= $this->output->notification($notification);
190 $o .= $this->output->continue_button($cancelurl);
192 // All submission plugins ready - show the confirmation form.
193 $o .= $this->output->box_start('generalbox submitconfirm');
194 $o .= $this->moodleform($page->confirmform);
195 $o .= $this->output->box_end();
197 $o .= $this->output->container_end();
203 * Page is done - render the footer.
207 public function render_footer() {
208 return $this->output->footer();
214 * @param assign_header $header
217 public function render_assign_header(assign_header $header) {
220 if ($header->subpage) {
221 $this->page->navbar->add($header->subpage);
224 $this->page->set_title(get_string('pluginname', 'assign'));
225 $this->page->set_heading($this->page->course->fullname);
227 $o .= $this->output->header();
228 $heading = format_string($header->assign->name, false, array('context' => $header->context));
229 $o .= $this->output->heading($heading);
230 if ($header->preface) {
231 $o .= $header->preface;
234 if ($header->showintro) {
235 $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
236 $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
237 $o .= $this->output->box_end();
244 * Render the header for an individual plugin.
246 * @param assign_plugin_header $header
249 public function render_assign_plugin_header(assign_plugin_header $header) {
250 $o = $header->plugin->view_header();
255 * Render a table containing the current status of the grading process.
257 * @param assign_grading_summary $summary
260 public function render_assign_grading_summary(assign_grading_summary $summary) {
261 // Create a table for the data.
263 $o .= $this->output->container_start('gradingsummary');
264 $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
265 $o .= $this->output->box_start('boxaligncenter gradingsummarytable');
266 $t = new html_table();
269 if ($summary->teamsubmission) {
270 $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
271 $summary->participantcount);
273 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
274 $summary->participantcount);
277 // Drafts count and dont show drafts count when using offline assignment.
278 if ($summary->submissiondraftsenabled && $summary->submissionsenabled) {
279 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
280 $summary->submissiondraftscount);
283 // Submitted for grading.
284 if ($summary->submissionsenabled) {
285 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
286 $summary->submissionssubmittedcount);
287 if (!$summary->teamsubmission) {
288 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
289 $summary->submissionsneedgradingcount);
294 if ($summary->duedate) {
296 $duedate = $summary->duedate;
297 $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
302 if ($duedate - $time <= 0) {
303 $due = get_string('assignmentisdue', 'assign');
305 $due = format_time($duedate - $time);
307 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
309 if ($duedate < $time) {
310 $cutoffdate = $summary->cutoffdate;
312 if ($cutoffdate > $time) {
313 $late = get_string('latesubmissionsaccepted', 'assign');
315 $late = get_string('nomoresubmissionsaccepted', 'assign');
317 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
323 // All done - write the table.
324 $o .= html_writer::table($t);
325 $o .= $this->output->box_end();
327 // Link to the grading page.
328 $o .= $this->output->container_start('submissionlinks');
329 $urlparams = array('id' => $summary->coursemoduleid, 'action'=>'grading');
330 $url = new moodle_url('/mod/assign/view.php', $urlparams);
331 $o .= $this->output->action_link($url, get_string('viewgrading', 'assign'));
332 $o .= $this->output->container_end();
334 // Close the container and insert a spacer.
335 $o .= $this->output->container_end();
341 * Render a table containing all the current grades and feedback.
343 * @param assign_feedback_status $status
346 public function render_assign_feedback_status(assign_feedback_status $status) {
350 $o .= $this->output->container_start('feedback');
351 $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
352 $o .= $this->output->box_start('boxaligncenter feedbacktable');
353 $t = new html_table();
356 if (isset($status->gradefordisplay)) {
357 $row = new html_table_row();
358 $cell1 = new html_table_cell(get_string('grade'));
359 $cell2 = new html_table_cell($status->gradefordisplay);
360 $row->cells = array($cell1, $cell2);
364 $row = new html_table_row();
365 $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
366 $cell2 = new html_table_cell(userdate($status->gradeddate));
367 $row->cells = array($cell1, $cell2);
371 if ($status->grader) {
373 $row = new html_table_row();
374 $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
375 $userdescription = $this->output->user_picture($status->grader) .
376 $this->output->spacer(array('width'=>30)) .
377 fullname($status->grader);
378 $cell2 = new html_table_cell($userdescription);
379 $row->cells = array($cell1, $cell2);
383 foreach ($status->feedbackplugins as $plugin) {
384 if ($plugin->is_enabled() &&
385 $plugin->is_visible() &&
386 $plugin->has_user_summary() &&
387 !empty($status->grade) &&
388 !$plugin->is_empty($status->grade)) {
390 $row = new html_table_row();
391 $cell1 = new html_table_cell($plugin->get_name());
392 $displaymode = assign_feedback_plugin_feedback::SUMMARY;
393 $pluginfeedback = new assign_feedback_plugin_feedback($plugin,
396 $status->coursemoduleid,
397 $status->returnaction,
398 $status->returnparams);
399 $cell2 = new html_table_cell($this->render($pluginfeedback));
400 $row->cells = array($cell1, $cell2);
405 $o .= html_writer::table($t);
406 $o .= $this->output->box_end();
408 $o .= $this->output->container_end();
413 * Render a table containing the current status of the submission.
415 * @param assign_submission_status $status
418 public function render_assign_submission_status(assign_submission_status $status) {
420 $o .= $this->output->container_start('submissionstatustable');
421 $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
424 if ($status->allowsubmissionsfromdate &&
425 $time <= $status->allowsubmissionsfromdate) {
426 $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
427 if ($status->alwaysshowdescription) {
428 $date = userdate($status->allowsubmissionsfromdate);
429 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
431 $date = userdate($status->allowsubmissionsfromdate);
432 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
434 $o .= $this->output->box_end();
436 $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
438 $t = new html_table();
440 if ($status->teamsubmissionenabled) {
441 $row = new html_table_row();
442 $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
443 $group = $status->submissiongroup;
445 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
447 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
449 $row->cells = array($cell1, $cell2);
453 if ($status->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
455 if (!$status->teamsubmissionenabled) {
456 if ($status->submission) {
457 $currentattempt = $status->submission->attemptnumber + 1;
460 if ($status->teamsubmission) {
461 $currentattempt = $status->teamsubmission->attemptnumber + 1;
465 $row = new html_table_row();
466 $cell1 = new html_table_cell(get_string('attemptnumber', 'assign'));
467 $maxattempts = $status->maxattempts;
468 if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) {
469 $message = get_string('currentattempt', 'assign', $currentattempt);
471 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt,
472 'maxattempts'=>$maxattempts));
474 $cell2 = new html_table_cell($message);
475 $row->cells = array($cell1, $cell2);
479 $row = new html_table_row();
480 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
481 if (!$status->teamsubmissionenabled) {
482 if ($status->submission) {
483 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign');
484 $cell2 = new html_table_cell($statusstr);
485 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
487 if (!$status->submissionsenabled) {
488 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
490 $cell2 = new html_table_cell(get_string('noattempt', 'assign'));
493 $row->cells = array($cell1, $cell2);
496 $row = new html_table_row();
497 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
498 if ($status->teamsubmission) {
499 $teamstatus = $status->teamsubmission->status;
500 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
502 if ($status->submissiongroup) {
503 $groupid = $status->submissiongroup->id;
506 $members = $status->submissiongroupmemberswhoneedtosubmit;
507 $userslist = array();
508 foreach ($members as $member) {
509 $urlparams = array('id' => $member->id, 'course'=>$status->courseid);
510 $url = new moodle_url('/user/view.php', $urlparams);
511 if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
512 $userslist[] = $member->alias;
514 $fullname = fullname($member, $status->canviewfullnames);
515 $userslist[] = $this->output->action_link($url, $fullname);
518 if (count($userslist) > 0) {
519 $userstr = join(', ', $userslist);
520 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
521 $submissionsummary .= $this->output->container($formatteduserstr);
524 $cell2 = new html_table_cell($submissionsummary);
525 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
527 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
528 if (!$status->submissionsenabled) {
529 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
531 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
534 $row->cells = array($cell1, $cell2);
539 if ($status->locked) {
540 $row = new html_table_row();
541 $cell1 = new html_table_cell();
542 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
543 $cell2->attributes = array('class'=>'submissionlocked');
544 $row->cells = array($cell1, $cell2);
549 $row = new html_table_row();
550 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
552 if ($status->graded) {
553 $cell2 = new html_table_cell(get_string('graded', 'assign'));
554 $cell2->attributes = array('class'=>'submissiongraded');
556 $cell2 = new html_table_cell(get_string('notgraded', 'assign'));
557 $cell2->attributes = array('class'=>'submissionnotgraded');
559 $row->cells = array($cell1, $cell2);
562 $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
563 $duedate = $status->duedate;
566 $row = new html_table_row();
567 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
568 $cell2 = new html_table_cell(userdate($duedate));
569 $row->cells = array($cell1, $cell2);
572 if ($status->view == assign_submission_status::GRADER_VIEW) {
573 if ($status->cutoffdate) {
575 $row = new html_table_row();
576 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
577 $cell2 = new html_table_cell(userdate($status->cutoffdate));
578 $row->cells = array($cell1, $cell2);
583 if ($status->extensionduedate) {
585 $row = new html_table_row();
586 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
587 $cell2 = new html_table_cell(userdate($status->extensionduedate));
588 $row->cells = array($cell1, $cell2);
590 $duedate = $status->extensionduedate;
594 $row = new html_table_row();
595 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
596 if ($duedate - $time <= 0) {
598 $submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
599 if ($status->submissionsenabled) {
600 $overduestr = get_string('overdue', 'assign', format_time($time - $duedate));
601 $cell2 = new html_table_cell($overduestr);
602 $cell2->attributes = array('class'=>'overdue');
604 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
607 if ($submission->timemodified > $duedate) {
608 $latestr = get_string('submittedlate',
610 format_time($submission->timemodified - $duedate));
611 $cell2 = new html_table_cell($latestr);
612 $cell2->attributes = array('class'=>'latesubmission');
614 $earlystr = get_string('submittedearly',
616 format_time($submission->timemodified - $duedate));
617 $cell2 = new html_table_cell($earlystr);
618 $cell2->attributes = array('class'=>'earlysubmission');
622 $cell2 = new html_table_cell(format_time($duedate - $time));
624 $row->cells = array($cell1, $cell2);
628 // Show graders whether this submission is editable by students.
629 if ($status->view == assign_submission_status::GRADER_VIEW) {
630 $row = new html_table_row();
631 $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
632 if ($status->canedit) {
633 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
634 $cell2->attributes = array('class'=>'submissioneditable');
636 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
637 $cell2->attributes = array('class'=>'submissionnoteditable');
639 $row->cells = array($cell1, $cell2);
643 // Grading criteria preview.
644 if (!empty($status->gradingcontrollerpreview)) {
645 $row = new html_table_row();
646 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
647 $cell2 = new html_table_cell($status->gradingcontrollerpreview);
648 $row->cells = array($cell1, $cell2);
654 $row = new html_table_row();
655 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
656 $cell2 = new html_table_cell(userdate($submission->timemodified));
657 $row->cells = array($cell1, $cell2);
660 foreach ($status->submissionplugins as $plugin) {
661 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
662 if ($plugin->is_enabled() &&
663 $plugin->is_visible() &&
664 $plugin->has_user_summary() &&
665 $pluginshowsummary) {
667 $row = new html_table_row();
668 $cell1 = new html_table_cell($plugin->get_name());
669 $displaymode = assign_submission_plugin_submission::SUMMARY;
670 $pluginsubmission = new assign_submission_plugin_submission($plugin,
673 $status->coursemoduleid,
674 $status->returnaction,
675 $status->returnparams);
676 $cell2 = new html_table_cell($this->render($pluginsubmission));
677 $row->cells = array($cell1, $cell2);
683 $o .= html_writer::table($t);
684 $o .= $this->output->box_end();
687 if ($status->view == assign_submission_status::STUDENT_VIEW) {
688 if ($status->canedit) {
690 $o .= $this->output->box_start('generalbox submissionaction');
691 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
692 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
693 get_string('addsubmission', 'assign'), 'get');
694 $o .= $this->output->box_start('boxaligncenter submithelp');
695 $o .= get_string('editsubmission_help', 'assign');
696 $o .= $this->output->box_end();
697 $o .= $this->output->box_end();
698 } else if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
699 $o .= $this->output->box_start('generalbox submissionaction');
700 $urlparams = array('id' => $status->coursemoduleid,
701 'action' => 'editprevioussubmission',
702 'sesskey'=>sesskey());
703 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
704 get_string('addnewattemptfromprevious', 'assign'), 'get');
705 $o .= $this->output->box_start('boxaligncenter submithelp');
706 $o .= get_string('addnewattemptfromprevious_help', 'assign');
707 $o .= $this->output->box_end();
708 $o .= $this->output->box_end();
709 $o .= $this->output->box_start('generalbox submissionaction');
710 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
711 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
712 get_string('addnewattempt', 'assign'), 'get');
713 $o .= $this->output->box_start('boxaligncenter submithelp');
714 $o .= get_string('addnewattempt_help', 'assign');
715 $o .= $this->output->box_end();
716 $o .= $this->output->box_end();
718 $o .= $this->output->box_start('generalbox submissionaction');
719 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
720 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
721 get_string('editsubmission', 'assign'), 'get');
722 $o .= $this->output->box_start('boxaligncenter submithelp');
723 $o .= get_string('editsubmission_help', 'assign');
724 $o .= $this->output->box_end();
725 $o .= $this->output->box_end();
729 if ($status->cansubmit) {
730 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
731 $o .= $this->output->box_start('generalbox submissionaction');
732 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
733 get_string('submitassignment', 'assign'), 'get');
734 $o .= $this->output->box_start('boxaligncenter submithelp');
735 $o .= get_string('submitassignment_help', 'assign');
736 $o .= $this->output->box_end();
737 $o .= $this->output->box_end();
741 $o .= $this->output->container_end();
746 * Output the attempt history for this assignment
748 * @param assign_attempt_history $history
751 public function render_assign_attempt_history(assign_attempt_history $history) {
754 $submittedstr = get_string('submitted', 'assign');
755 $gradestr = get_string('grade');
756 $gradedonstr = get_string('gradedon', 'assign');
757 $gradedbystr = get_string('gradedby', 'assign');
759 // Don't show the last one because it is the current submission.
760 array_pop($history->submissions);
762 // Show newest to oldest.
763 $history->submissions = array_reverse($history->submissions);
765 if (empty($history->submissions)) {
769 $containerid = 'attempthistory' . uniqid();
770 $o .= $this->heading(get_string('attempthistory', 'assign'), 3);
771 $o .= $this->box_start('attempthistory', $containerid);
773 foreach ($history->submissions as $i => $submission) {
775 foreach ($history->grades as $onegrade) {
776 if ($onegrade->attemptnumber == $submission->attemptnumber) {
785 $submissionsummary = userdate($submission->timemodified);
787 $submissionsummary = get_string('nosubmission', 'assign');
790 $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+1,
791 'submissionsummary'=>$submissionsummary);
792 $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4);
794 $t = new html_table();
797 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
798 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status, 'assign'));
799 $t->data[] = new html_table_row(array($cell1, $cell2));
801 foreach ($history->submissionplugins as $plugin) {
802 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
803 if ($plugin->is_enabled() &&
804 $plugin->is_visible() &&
805 $plugin->has_user_summary() &&
806 $pluginshowsummary) {
808 $cell1 = new html_table_cell($plugin->get_name());
809 $pluginsubmission = new assign_submission_plugin_submission($plugin,
811 assign_submission_plugin_submission::SUMMARY,
812 $history->coursemoduleid,
813 $history->returnaction,
814 $history->returnparams);
815 $cell2 = new html_table_cell($this->render($pluginsubmission));
817 $t->data[] = new html_table_row(array($cell1, $cell2));
823 // Heading 'feedback'.
824 $title = get_string('feedback', 'assign', $i);
825 $title .= $this->output->spacer(array('width'=>10));
826 if ($history->cangrade) {
827 // Edit previous feedback.
828 $returnparams = http_build_query($history->returnparams);
829 $urlparams = array('id' => $history->coursemoduleid,
830 'rownum'=>$history->rownum,
831 'useridlistid'=>$history->useridlistid,
832 'attemptnumber'=>$grade->attemptnumber,
834 'returnaction'=>$history->returnaction,
835 'returnparams'=>$returnparams);
836 $url = new moodle_url('/mod/assign/view.php', $urlparams);
837 $icon = new pix_icon('gradefeedback',
838 get_string('editattemptfeedback', 'assign', $grade->attemptnumber+1),
840 $title .= $this->output->action_icon($url, $icon);
842 $cell = new html_table_cell($title);
843 $cell->attributes['class'] = 'feedbacktitle';
845 $t->data[] = new html_table_row(array($cell));
848 $cell1 = new html_table_cell($gradestr);
849 $cell2 = $grade->gradefordisplay;
850 $t->data[] = new html_table_row(array($cell1, $cell2));
853 $cell1 = new html_table_cell($gradedonstr);
854 $cell2 = new html_table_cell(userdate($grade->timemodified));
855 $t->data[] = new html_table_row(array($cell1, $cell2));
858 $cell1 = new html_table_cell($gradedbystr);
859 $cell2 = new html_table_cell($this->output->user_picture($grade->grader) .
860 $this->output->spacer(array('width'=>30)) . fullname($grade->grader));
861 $t->data[] = new html_table_row(array($cell1, $cell2));
863 // Feedback from plugins.
864 foreach ($history->feedbackplugins as $plugin) {
865 if ($plugin->is_enabled() &&
866 $plugin->is_visible() &&
867 $plugin->has_user_summary() &&
868 !$plugin->is_empty($grade)) {
870 $cell1 = new html_table_cell($plugin->get_name());
871 $pluginfeedback = new assign_feedback_plugin_feedback(
872 $plugin, $grade, assign_feedback_plugin_feedback::SUMMARY, $history->coursemoduleid,
873 $history->returnaction, $history->returnparams
875 $cell2 = new html_table_cell($this->render($pluginfeedback));
876 $t->data[] = new html_table_row(array($cell1, $cell2));
883 $o .= html_writer::table($t);
885 $o .= $this->box_end();
886 $jsparams = array($containerid);
888 $this->page->requires->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history');
894 * Render a submission plugin submission
896 * @param assign_submission_plugin_submission $submissionplugin
899 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
902 if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
903 $showviewlink = false;
904 $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission,
907 $classsuffix = $submissionplugin->plugin->get_subtype() .
909 $submissionplugin->plugin->get_type() .
911 $submissionplugin->submission->id;
913 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
917 $previewstr = get_string('viewsubmission', 'assign');
918 $icon = $this->output->pix_icon('t/preview', $previewstr);
920 $expandstr = get_string('viewfull', 'assign');
921 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
922 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
924 $jsparams = array($submissionplugin->plugin->get_subtype(),
925 $submissionplugin->plugin->get_type(),
926 $submissionplugin->submission->id);
928 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
930 $action = 'viewplugin' . $submissionplugin->plugin->get_subtype();
931 $returnparams = http_build_query($submissionplugin->returnparams);
932 $link .= '<noscript>';
933 $urlparams = array('id' => $submissionplugin->coursemoduleid,
934 'sid'=>$submissionplugin->submission->id,
935 'plugin'=>$submissionplugin->plugin->get_type(),
937 'returnaction'=>$submissionplugin->returnaction,
938 'returnparams'=>$returnparams);
939 $url = new moodle_url('/mod/assign/view.php', $urlparams);
940 $link .= $this->output->action_link($url, $icon);
941 $link .= '</noscript>';
943 $link .= $this->output->spacer(array('width'=>15));
946 $o .= $link . $summary;
947 $o .= $this->output->box_end();
949 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
950 $classes = 'expandsummaryicon contract_' . $classsuffix;
951 $o .= $this->output->pix_icon('t/switch_minus',
952 get_string('viewsummary', 'assign'),
954 array('class'=>$classes));
955 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
956 $o .= $this->output->box_end();
958 } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
959 $o .= $this->output->box_start('boxaligncenter submissionfull');
960 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
961 $o .= $this->output->box_end();
968 * Render the grading table.
970 * @param assign_grading_table $table
973 public function render_assign_grading_table(assign_grading_table $table) {
975 $o .= $this->output->box_start('boxaligncenter gradingtable');
977 $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
978 $this->page->requires->string_for_js('nousersselected', 'assign');
979 $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
980 $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
981 $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
982 $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
983 $this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign');
984 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
985 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
986 $this->page->requires->string_for_js('editaction', 'assign');
987 foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
988 foreach ($operations as $operation => $description) {
989 $this->page->requires->string_for_js('batchoperationconfirm' . $operation,
990 'assignfeedback_' . $plugin);
993 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
994 $o .= $this->output->box_end();
1000 * Render a feedback plugin feedback
1002 * @param assign_feedback_plugin_feedback $feedbackplugin
1005 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
1008 if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
1009 $showviewlink = false;
1010 $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
1012 $classsuffix = $feedbackplugin->plugin->get_subtype() .
1014 $feedbackplugin->plugin->get_type() .
1016 $feedbackplugin->grade->id;
1017 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1020 if ($showviewlink) {
1021 $previewstr = get_string('viewfeedback', 'assign');
1022 $icon = $this->output->pix_icon('t/preview', $previewstr);
1024 $expandstr = get_string('viewfull', 'assign');
1025 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1026 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
1028 $jsparams = array($feedbackplugin->plugin->get_subtype(),
1029 $feedbackplugin->plugin->get_type(),
1030 $feedbackplugin->grade->id);
1031 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1033 $urlparams = array('id' => $feedbackplugin->coursemoduleid,
1034 'gid'=>$feedbackplugin->grade->id,
1035 'plugin'=>$feedbackplugin->plugin->get_type(),
1036 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
1037 'returnaction'=>$feedbackplugin->returnaction,
1038 'returnparams'=>http_build_query($feedbackplugin->returnparams));
1039 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1040 $link .= '<noscript>';
1041 $link .= $this->output->action_link($url, $icon);
1042 $link .= '</noscript>';
1044 $link .= $this->output->spacer(array('width'=>15));
1047 $o .= $link . $summary;
1048 $o .= $this->output->box_end();
1049 if ($showviewlink) {
1050 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
1051 $classes = 'expandsummaryicon contract_' . $classsuffix;
1052 $o .= $this->output->pix_icon('t/switch_minus',
1053 get_string('viewsummary', 'assign'),
1055 array('class'=>$classes));
1056 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1057 $o .= $this->output->box_end();
1059 } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
1060 $o .= $this->output->box_start('boxaligncenter feedbackfull');
1061 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1062 $o .= $this->output->box_end();
1069 * Render a course index summary
1071 * @param assign_course_index_summary $indexsummary
1074 public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
1077 $strplural = get_string('modulenameplural', 'assign');
1078 $strsectionname = $indexsummary->courseformatname;
1079 $strduedate = get_string('duedate', 'assign');
1080 $strsubmission = get_string('submission', 'assign');
1081 $strgrade = get_string('grade');
1083 $table = new html_table();
1084 if ($indexsummary->usesections) {
1085 $table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
1086 $table->align = array ('left', 'left', 'center', 'right', 'right');
1088 $table->head = array ($strplural, $strduedate, $strsubmission, $strgrade);
1089 $table->align = array ('left', 'left', 'center', 'right');
1091 $table->data = array();
1093 $currentsection = '';
1094 foreach ($indexsummary->assignments as $info) {
1095 $params = array('id' => $info['cmid']);
1096 $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
1098 $due = $info['timedue'] ? userdate($info['timedue']) : '-';
1101 if ($indexsummary->usesections) {
1102 if ($info['sectionname'] !== $currentsection) {
1103 if ($info['sectionname']) {
1104 $printsection = $info['sectionname'];
1106 if ($currentsection !== '') {
1107 $table->data[] = 'hr';
1109 $currentsection = $info['sectionname'];
1113 if ($indexsummary->usesections) {
1114 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
1116 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
1118 $table->data[] = $row;
1121 $o .= html_writer::table($table);
1129 * Internal function - creates htmls structure suitable for YUI tree.
1131 * @param assign_files $tree
1135 protected function htmllize_tree(assign_files $tree, $dir) {
1137 $yuiconfig = array();
1138 $yuiconfig['type'] = 'html';
1140 if (empty($dir['subdirs']) and empty($dir['files'])) {
1145 foreach ($dir['subdirs'] as $subdir) {
1146 $image = $this->output->pix_icon(file_folder_icon(),
1149 array('class'=>'icon'));
1150 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1151 '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
1152 $this->htmllize_tree($tree, $subdir) .
1156 foreach ($dir['files'] as $file) {
1157 $filename = $file->get_filename();
1158 if ($CFG->enableplagiarism) {
1159 require_once($CFG->libdir.'/plagiarismlib.php');
1160 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(),
1162 'cmid'=>$tree->cm->id,
1163 'course'=>$tree->course));
1165 $plagiarismlinks = '';
1167 $image = $this->output->pix_icon(file_file_icon($file),
1170 array('class'=>'icon'));
1171 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1172 '<div>' . $image . ' ' .
1173 $file->fileurl . ' ' .
1175 $file->portfoliobutton . '</div>' .
1185 * Helper method dealing with the fact we can not just fetch the output of flexible_table
1187 * @param flexible_table $table The table to render
1188 * @param int $rowsperpage How many assignments to render in a page
1189 * @param bool $displaylinks - Whether to render links in the table
1190 * (e.g. downloads would not enable this)
1191 * @return string HTML
1193 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
1197 $table->out($rowsperpage, $displaylinks);
1198 $o = ob_get_contents();
1205 * Helper method dealing with the fact we can not just fetch the output of moodleforms
1207 * @param moodleform $mform
1208 * @return string HTML
1210 protected function moodleform(moodleform $mform) {
1215 $o = ob_get_contents();