MDL-60826 calendar: further performance improvements
[moodle.git] / mod / assign / renderer.php
blob6a1b81abb26e21069c639eeb3788202f91a5ae6a
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
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/>.
17 /**
18 * This file contains a renderer for the assignment class
20 * @package mod_assign
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->dirroot . '/mod/assign/locallib.php');
29 use \mod_assign\output\grading_app;
31 /**
32 * A custom renderer class that extends the plugin_renderer_base and is used by the assign module.
34 * @package mod_assign
35 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class mod_assign_renderer extends plugin_renderer_base {
40 /**
41 * Rendering assignment files
43 * @param context $context
44 * @param int $userid
45 * @param string $filearea
46 * @param string $component
47 * @return string
49 public function assign_files(context $context, $userid, $filearea, $component) {
50 return $this->render(new assign_files($context, $userid, $filearea, $component));
53 /**
54 * Rendering assignment files
56 * @param assign_files $tree
57 * @return string
59 public function render_assign_files(assign_files $tree) {
60 $this->htmlid = html_writer::random_id('assign_files_tree');
61 $this->page->requires->js_init_call('M.mod_assign.init_tree', array(true, $this->htmlid));
62 $html = '<div id="'.$this->htmlid.'">';
63 $html .= $this->htmllize_tree($tree, $tree->dir);
64 $html .= '</div>';
66 if ($tree->portfolioform) {
67 $html .= $tree->portfolioform;
69 return $html;
72 /**
73 * Utility function to add a row of data to a table with 2 columns. Modified
74 * the table param and does not return a value
76 * @param html_table $table The table to append the row of data to
77 * @param string $first The first column text
78 * @param string $second The second column text
79 * @return void
81 private function add_table_row_tuple(html_table $table, $first, $second) {
82 $row = new html_table_row();
83 $cell1 = new html_table_cell($first);
84 $cell2 = new html_table_cell($second);
85 $row->cells = array($cell1, $cell2);
86 $table->data[] = $row;
89 /**
90 * Render a grading message notification
91 * @param assign_gradingmessage $result The result to render
92 * @return string
94 public function render_assign_gradingmessage(assign_gradingmessage $result) {
95 $urlparams = array('id' => $result->coursemoduleid, 'action'=>'grading');
96 if (!empty($result->page)) {
97 $urlparams['page'] = $result->page;
99 $url = new moodle_url('/mod/assign/view.php', $urlparams);
100 $classes = $result->gradingerror ? 'notifyproblem' : 'notifysuccess';
102 $o = '';
103 $o .= $this->output->heading($result->heading, 4);
104 $o .= $this->output->notification($result->message, $classes);
105 $o .= $this->output->continue_button($url);
106 return $o;
110 * Render the generic form
111 * @param assign_form $form The form to render
112 * @return string
114 public function render_assign_form(assign_form $form) {
115 $o = '';
116 if ($form->jsinitfunction) {
117 $this->page->requires->js_init_call($form->jsinitfunction, array());
119 $o .= $this->output->box_start('boxaligncenter ' . $form->classname);
120 $o .= $this->moodleform($form->form);
121 $o .= $this->output->box_end();
122 return $o;
126 * Render the user summary
128 * @param assign_user_summary $summary The user summary to render
129 * @return string
131 public function render_assign_user_summary(assign_user_summary $summary) {
132 $o = '';
133 $supendedclass = '';
134 $suspendedicon = '';
136 if (!$summary->user) {
137 return;
140 if ($summary->suspendeduser) {
141 $supendedclass = ' usersuspended';
142 $suspendedstring = get_string('userenrolmentsuspended', 'grades');
143 $suspendedicon = ' ' . $this->pix_icon('i/enrolmentsuspended', $suspendedstring);
145 $o .= $this->output->container_start('usersummary');
146 $o .= $this->output->box_start('boxaligncenter usersummarysection'.$supendedclass);
147 if ($summary->blindmarking) {
148 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser.$suspendedicon;
149 } else {
150 $o .= $this->output->user_picture($summary->user);
151 $o .= $this->output->spacer(array('width'=>30));
152 $urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid);
153 $url = new moodle_url('/user/view.php', $urlparams);
154 $fullname = fullname($summary->user, $summary->viewfullnames);
155 $extrainfo = array();
156 foreach ($summary->extrauserfields as $extrafield) {
157 $extrainfo[] = $summary->user->$extrafield;
159 if (count($extrainfo)) {
160 $fullname .= ' (' . implode(', ', $extrainfo) . ')';
162 $fullname .= $suspendedicon;
163 $o .= $this->output->action_link($url, $fullname);
165 $o .= $this->output->box_end();
166 $o .= $this->output->container_end();
168 return $o;
172 * Render the submit for grading page
174 * @param assign_submit_for_grading_page $page
175 * @return string
177 public function render_assign_submit_for_grading_page($page) {
178 $o = '';
180 $o .= $this->output->container_start('submitforgrading');
181 $o .= $this->output->heading(get_string('confirmsubmissionheading', 'assign'), 3);
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);
194 } else {
195 // All submission plugins ready - show the confirmation form.
196 $o .= $this->moodleform($page->confirmform);
198 $o .= $this->output->container_end();
200 return $o;
204 * Page is done - render the footer.
206 * @return void
208 public function render_footer() {
209 return $this->output->footer();
213 * Render the header.
215 * @param assign_header $header
216 * @return string
218 public function render_assign_header(assign_header $header) {
219 $o = '';
221 if ($header->subpage) {
222 $this->page->navbar->add($header->subpage);
225 $this->page->set_title(get_string('pluginname', 'assign'));
226 $this->page->set_heading($this->page->course->fullname);
228 $o .= $this->output->header();
229 $heading = format_string($header->assign->name, false, array('context' => $header->context));
230 $o .= $this->output->heading($heading);
231 if ($header->preface) {
232 $o .= $header->preface;
235 if ($header->showintro) {
236 $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
237 $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
238 $o .= $header->postfix;
239 $o .= $this->output->box_end();
242 return $o;
246 * Render the header for an individual plugin.
248 * @param assign_plugin_header $header
249 * @return string
251 public function render_assign_plugin_header(assign_plugin_header $header) {
252 $o = $header->plugin->view_header();
253 return $o;
257 * Render a table containing the current status of the grading process.
259 * @param assign_grading_summary $summary
260 * @return string
262 public function render_assign_grading_summary(assign_grading_summary $summary) {
263 // Create a table for the data.
264 $o = '';
265 $o .= $this->output->container_start('gradingsummary');
266 $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
267 $o .= $this->output->box_start('boxaligncenter gradingsummarytable');
268 $t = new html_table();
270 // Visibility Status.
271 $this->add_table_row_tuple($t, get_string('hiddenfromstudents'),
272 (!$summary->isvisible) ? get_string('yes') : get_string('no'));
274 // Status.
275 if ($summary->teamsubmission) {
276 if ($summary->warnofungroupedusers) {
277 $o .= $this->output->notification(get_string('ungroupedusers', 'assign'));
280 $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
281 $summary->participantcount);
282 } else {
283 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
284 $summary->participantcount);
287 // Drafts count and dont show drafts count when using offline assignment.
288 if ($summary->submissiondraftsenabled && $summary->submissionsenabled) {
289 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
290 $summary->submissiondraftscount);
293 // Submitted for grading.
294 if ($summary->submissionsenabled) {
295 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
296 $summary->submissionssubmittedcount);
297 if (!$summary->teamsubmission) {
298 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
299 $summary->submissionsneedgradingcount);
303 $time = time();
304 if ($summary->duedate) {
305 // Due date.
306 $duedate = $summary->duedate;
307 $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
308 userdate($duedate));
310 // Time remaining.
311 $due = '';
312 if ($duedate - $time <= 0) {
313 $due = get_string('assignmentisdue', 'assign');
314 } else {
315 $due = format_time($duedate - $time);
317 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
319 if ($duedate < $time) {
320 $cutoffdate = $summary->cutoffdate;
321 if ($cutoffdate) {
322 if ($cutoffdate > $time) {
323 $late = get_string('latesubmissionsaccepted', 'assign', userdate($summary->cutoffdate));
324 } else {
325 $late = get_string('nomoresubmissionsaccepted', 'assign');
327 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
333 // All done - write the table.
334 $o .= html_writer::table($t);
335 $o .= $this->output->box_end();
337 // Link to the grading page.
338 $o .= '<center>';
339 $o .= $this->output->container_start('submissionlinks');
340 $urlparams = array('id' => $summary->coursemoduleid, 'action' => 'grading');
341 $url = new moodle_url('/mod/assign/view.php', $urlparams);
342 $o .= '<a href="' . $url . '" class="btn btn-secondary">' . get_string('viewgrading', 'mod_assign') . '</a> ';
343 if ($summary->cangrade) {
344 $urlparams = array('id' => $summary->coursemoduleid, 'action' => 'grader');
345 $url = new moodle_url('/mod/assign/view.php', $urlparams);
346 $o .= '<a href="' . $url . '" class="btn btn-primary">' . get_string('grade') . '</a>';
348 $o .= $this->output->container_end();
350 // Close the container and insert a spacer.
351 $o .= $this->output->container_end();
352 $o .= '</center>';
354 return $o;
358 * Render a table containing all the current grades and feedback.
360 * @param assign_feedback_status $status
361 * @return string
363 public function render_assign_feedback_status(assign_feedback_status $status) {
364 global $DB, $CFG;
365 $o = '';
367 $o .= $this->output->container_start('feedback');
368 $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
369 $o .= $this->output->box_start('boxaligncenter feedbacktable');
370 $t = new html_table();
372 // Grade.
373 if (isset($status->gradefordisplay)) {
374 $row = new html_table_row();
375 $cell1 = new html_table_cell(get_string('grade'));
376 $cell2 = new html_table_cell($status->gradefordisplay);
377 $row->cells = array($cell1, $cell2);
378 $t->data[] = $row;
380 // Grade date.
381 $row = new html_table_row();
382 $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
383 $cell2 = new html_table_cell(userdate($status->gradeddate));
384 $row->cells = array($cell1, $cell2);
385 $t->data[] = $row;
388 if ($status->grader) {
389 // Grader.
390 $row = new html_table_row();
391 $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
392 $userdescription = $this->output->user_picture($status->grader) .
393 $this->output->spacer(array('width'=>30)) .
394 fullname($status->grader, $status->canviewfullnames);
395 $cell2 = new html_table_cell($userdescription);
396 $row->cells = array($cell1, $cell2);
397 $t->data[] = $row;
400 foreach ($status->feedbackplugins as $plugin) {
401 if ($plugin->is_enabled() &&
402 $plugin->is_visible() &&
403 $plugin->has_user_summary() &&
404 !empty($status->grade) &&
405 !$plugin->is_empty($status->grade)) {
407 $row = new html_table_row();
408 $cell1 = new html_table_cell($plugin->get_name());
409 $displaymode = assign_feedback_plugin_feedback::SUMMARY;
410 $pluginfeedback = new assign_feedback_plugin_feedback($plugin,
411 $status->grade,
412 $displaymode,
413 $status->coursemoduleid,
414 $status->returnaction,
415 $status->returnparams);
416 $cell2 = new html_table_cell($this->render($pluginfeedback));
417 $row->cells = array($cell1, $cell2);
418 $t->data[] = $row;
422 $o .= html_writer::table($t);
423 $o .= $this->output->box_end();
425 $o .= $this->output->container_end();
426 return $o;
430 * Render a compact view of the current status of the submission.
432 * @param assign_submission_status_compact $status
433 * @return string
435 public function render_assign_submission_status_compact(assign_submission_status_compact $status) {
436 $o = '';
437 $o .= $this->output->container_start('submissionstatustable');
438 $o .= $this->output->heading(get_string('submission', 'assign'), 3);
439 $time = time();
441 if ($status->teamsubmissionenabled) {
442 $group = $status->submissiongroup;
443 if ($group) {
444 $team = format_string($group->name, false, $status->context);
445 } else if ($status->preventsubmissionnotingroup) {
446 if (count($status->usergroups) == 0) {
447 $team = '<span class="alert alert-error">' . get_string('noteam', 'assign') . '</span>';
448 } else if (count($status->usergroups) > 1) {
449 $team = '<span class="alert alert-error">' . get_string('multipleteams', 'assign') . '</span>';
451 } else {
452 $team = get_string('defaultteam', 'assign');
454 $o .= $this->output->container(get_string('teamname', 'assign', $team), 'teamname');
457 if (!$status->teamsubmissionenabled) {
458 if ($status->submission && $status->submission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
459 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign');
460 $o .= $this->output->container($statusstr, 'submissionstatus' . $status->submission->status);
461 } else {
462 if (!$status->submissionsenabled) {
463 $o .= $this->output->container(get_string('noonlinesubmissions', 'assign'), 'submissionstatus');
464 } else {
465 $o .= $this->output->container(get_string('noattempt', 'assign'), 'submissionstatus');
468 } else {
469 $group = $status->submissiongroup;
470 if (!$group && $status->preventsubmissionnotingroup) {
471 $o .= $this->output->container(get_string('nosubmission', 'assign'), 'submissionstatus');
472 } else if ($status->teamsubmission && $status->teamsubmission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
473 $teamstatus = $status->teamsubmission->status;
474 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
475 $groupid = 0;
476 if ($status->submissiongroup) {
477 $groupid = $status->submissiongroup->id;
480 $members = $status->submissiongroupmemberswhoneedtosubmit;
481 $userslist = array();
482 foreach ($members as $member) {
483 $urlparams = array('id' => $member->id, 'course' => $status->courseid);
484 $url = new moodle_url('/user/view.php', $urlparams);
485 if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
486 $userslist[] = $member->alias;
487 } else {
488 $fullname = fullname($member, $status->canviewfullnames);
489 $userslist[] = $this->output->action_link($url, $fullname);
492 if (count($userslist) > 0) {
493 $userstr = join(', ', $userslist);
494 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
495 $submissionsummary .= $this->output->container($formatteduserstr);
497 $o .= $this->output->container($submissionsummary, 'submissionstatus' . $status->teamsubmission->status);
498 } else {
499 if (!$status->submissionsenabled) {
500 $o .= $this->output->container(get_string('noonlinesubmissions', 'assign'), 'submissionstatus');
501 } else {
502 $o .= $this->output->container(get_string('nosubmission', 'assign'), 'submissionstatus');
507 // Is locked?
508 if ($status->locked) {
509 $o .= $this->output->container(get_string('submissionslocked', 'assign'), 'submissionlocked');
512 // Grading status.
513 $statusstr = '';
514 $classname = 'gradingstatus';
515 if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
516 $status->gradingstatus == ASSIGN_GRADING_STATUS_NOT_GRADED) {
517 $statusstr = get_string($status->gradingstatus, 'assign');
518 } else {
519 $gradingstatus = 'markingworkflowstate' . $status->gradingstatus;
520 $statusstr = get_string($gradingstatus, 'assign');
522 if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
523 $status->gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
524 $classname = 'submissiongraded';
525 } else {
526 $classname = 'submissionnotgraded';
528 $o .= $this->output->container($statusstr, $classname);
530 $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
531 $duedate = $status->duedate;
532 if ($duedate > 0) {
534 if ($status->extensionduedate) {
535 // Extension date.
536 $duedate = $status->extensionduedate;
539 // Time remaining.
540 $classname = 'timeremaining';
541 if ($duedate - $time <= 0) {
542 if (!$submission ||
543 $submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
544 if ($status->submissionsenabled) {
545 $remaining = get_string('overdue', 'assign', format_time($time - $duedate));
546 $classname = 'overdue';
547 } else {
548 $remaining = get_string('duedatereached', 'assign');
550 } else {
551 if ($submission->timemodified > $duedate) {
552 $remaining = get_string('submittedlate',
553 'assign',
554 format_time($submission->timemodified - $duedate));
555 $classname = 'latesubmission';
556 } else {
557 $remaining = get_string('submittedearly',
558 'assign',
559 format_time($submission->timemodified - $duedate));
560 $classname = 'earlysubmission';
563 } else {
564 $remaining = get_string('paramtimeremaining', 'assign', format_time($duedate - $time));
566 $o .= $this->output->container($remaining, $classname);
569 // Show graders whether this submission is editable by students.
570 if ($status->view == assign_submission_status::GRADER_VIEW) {
571 if ($status->canedit) {
572 $o .= $this->output->container(get_string('submissioneditable', 'assign'), 'submissioneditable');
573 } else {
574 $o .= $this->output->container(get_string('submissionnoteditable', 'assign'), 'submissionnoteditable');
578 // Grading criteria preview.
579 if (!empty($status->gradingcontrollerpreview)) {
580 $o .= $this->output->container($status->gradingcontrollerpreview, 'gradingmethodpreview');
583 if ($submission) {
585 if (!$status->teamsubmission || $status->submissiongroup != false || !$status->preventsubmissionnotingroup) {
586 foreach ($status->submissionplugins as $plugin) {
587 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
588 if ($plugin->is_enabled() &&
589 $plugin->is_visible() &&
590 $plugin->has_user_summary() &&
591 $pluginshowsummary
594 $displaymode = assign_submission_plugin_submission::SUMMARY;
595 $pluginsubmission = new assign_submission_plugin_submission($plugin,
596 $submission,
597 $displaymode,
598 $status->coursemoduleid,
599 $status->returnaction,
600 $status->returnparams);
601 $plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
602 $o .= $this->output->container($this->render($pluginsubmission), 'assignsubmission ' . $plugincomponent);
608 $o .= $this->output->container_end();
609 return $o;
613 * Render a table containing the current status of the submission.
615 * @param assign_submission_status $status
616 * @return string
618 public function render_assign_submission_status(assign_submission_status $status) {
619 $o = '';
620 $o .= $this->output->container_start('submissionstatustable');
621 $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
622 $time = time();
624 if ($status->allowsubmissionsfromdate &&
625 $time <= $status->allowsubmissionsfromdate) {
626 $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
627 if ($status->alwaysshowdescription) {
628 $date = userdate($status->allowsubmissionsfromdate);
629 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
630 } else {
631 $date = userdate($status->allowsubmissionsfromdate);
632 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
634 $o .= $this->output->box_end();
636 $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
638 $t = new html_table();
640 $warningmsg = '';
641 if ($status->teamsubmissionenabled) {
642 $row = new html_table_row();
643 $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
644 $group = $status->submissiongroup;
645 if ($group) {
646 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
647 } else if ($status->preventsubmissionnotingroup) {
648 if (count($status->usergroups) == 0) {
649 $notification = new \core\output\notification(get_string('noteam', 'assign'), 'error');
650 $notification->set_show_closebutton(false);
651 $cell2 = new html_table_cell(
652 $this->output->render($notification)
654 $warningmsg = $this->output->notification(get_string('noteam_desc', 'assign'), 'error');
655 } else if (count($status->usergroups) > 1) {
656 $notification = new \core\output\notification(get_string('multipleteams', 'assign'), 'error');
657 $notification->set_show_closebutton(false);
658 $cell2 = new html_table_cell(
659 $this->output->render($notification)
661 $warningmsg = $this->output->notification(get_string('multipleteams_desc', 'assign'), 'error');
663 } else {
664 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
666 $row->cells = array($cell1, $cell2);
667 $t->data[] = $row;
670 if ($status->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
671 $currentattempt = 1;
672 if (!$status->teamsubmissionenabled) {
673 if ($status->submission) {
674 $currentattempt = $status->submission->attemptnumber + 1;
676 } else {
677 if ($status->teamsubmission) {
678 $currentattempt = $status->teamsubmission->attemptnumber + 1;
682 $row = new html_table_row();
683 $cell1 = new html_table_cell(get_string('attemptnumber', 'assign'));
684 $maxattempts = $status->maxattempts;
685 if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) {
686 $message = get_string('currentattempt', 'assign', $currentattempt);
687 } else {
688 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt,
689 'maxattempts'=>$maxattempts));
691 $cell2 = new html_table_cell($message);
692 $row->cells = array($cell1, $cell2);
693 $t->data[] = $row;
696 $row = new html_table_row();
697 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
698 if (!$status->teamsubmissionenabled) {
699 if ($status->submission && $status->submission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
700 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign');
701 $cell2 = new html_table_cell($statusstr);
702 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
703 } else {
704 if (!$status->submissionsenabled) {
705 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
706 } else {
707 $cell2 = new html_table_cell(get_string('noattempt', 'assign'));
710 $row->cells = array($cell1, $cell2);
711 $t->data[] = $row;
712 } else {
713 $row = new html_table_row();
714 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
715 $group = $status->submissiongroup;
716 if (!$group && $status->preventsubmissionnotingroup) {
717 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
718 } else if ($status->teamsubmission && $status->teamsubmission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
719 $teamstatus = $status->teamsubmission->status;
720 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
721 $groupid = 0;
722 if ($status->submissiongroup) {
723 $groupid = $status->submissiongroup->id;
726 $members = $status->submissiongroupmemberswhoneedtosubmit;
727 $userslist = array();
728 foreach ($members as $member) {
729 $urlparams = array('id' => $member->id, 'course'=>$status->courseid);
730 $url = new moodle_url('/user/view.php', $urlparams);
731 if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
732 $userslist[] = $member->alias;
733 } else {
734 $fullname = fullname($member, $status->canviewfullnames);
735 $userslist[] = $this->output->action_link($url, $fullname);
738 if (count($userslist) > 0) {
739 $userstr = join(', ', $userslist);
740 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
741 $submissionsummary .= $this->output->container($formatteduserstr);
744 $cell2 = new html_table_cell($submissionsummary);
745 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
746 } else {
747 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
748 if (!$status->submissionsenabled) {
749 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
750 } else {
751 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
754 $row->cells = array($cell1, $cell2);
755 $t->data[] = $row;
758 // Is locked?
759 if ($status->locked) {
760 $row = new html_table_row();
761 $cell1 = new html_table_cell();
762 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
763 $cell2->attributes = array('class'=>'submissionlocked');
764 $row->cells = array($cell1, $cell2);
765 $t->data[] = $row;
768 // Grading status.
769 $row = new html_table_row();
770 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
772 if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
773 $status->gradingstatus == ASSIGN_GRADING_STATUS_NOT_GRADED) {
774 $cell2 = new html_table_cell(get_string($status->gradingstatus, 'assign'));
775 } else {
776 $gradingstatus = 'markingworkflowstate' . $status->gradingstatus;
777 $cell2 = new html_table_cell(get_string($gradingstatus, 'assign'));
779 if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
780 $status->gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
781 $cell2->attributes = array('class' => 'submissiongraded');
782 } else {
783 $cell2->attributes = array('class' => 'submissionnotgraded');
785 $row->cells = array($cell1, $cell2);
786 $t->data[] = $row;
788 $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
789 $duedate = $status->duedate;
790 if ($duedate > 0) {
791 // Due date.
792 $row = new html_table_row();
793 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
794 $cell2 = new html_table_cell(userdate($duedate));
795 $row->cells = array($cell1, $cell2);
796 $t->data[] = $row;
798 if ($status->view == assign_submission_status::GRADER_VIEW) {
799 if ($status->cutoffdate) {
800 // Cut off date.
801 $row = new html_table_row();
802 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
803 $cell2 = new html_table_cell(userdate($status->cutoffdate));
804 $row->cells = array($cell1, $cell2);
805 $t->data[] = $row;
809 if ($status->extensionduedate) {
810 // Extension date.
811 $row = new html_table_row();
812 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
813 $cell2 = new html_table_cell(userdate($status->extensionduedate));
814 $row->cells = array($cell1, $cell2);
815 $t->data[] = $row;
816 $duedate = $status->extensionduedate;
819 // Time remaining.
820 $row = new html_table_row();
821 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
822 if ($duedate - $time <= 0) {
823 if (!$submission ||
824 $submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
825 if ($status->submissionsenabled) {
826 $overduestr = get_string('overdue', 'assign', format_time($time - $duedate));
827 $cell2 = new html_table_cell($overduestr);
828 $cell2->attributes = array('class'=>'overdue');
829 } else {
830 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
832 } else {
833 if ($submission->timemodified > $duedate) {
834 $latestr = get_string('submittedlate',
835 'assign',
836 format_time($submission->timemodified - $duedate));
837 $cell2 = new html_table_cell($latestr);
838 $cell2->attributes = array('class'=>'latesubmission');
839 } else {
840 $earlystr = get_string('submittedearly',
841 'assign',
842 format_time($submission->timemodified - $duedate));
843 $cell2 = new html_table_cell($earlystr);
844 $cell2->attributes = array('class'=>'earlysubmission');
847 } else {
848 $cell2 = new html_table_cell(format_time($duedate - $time));
850 $row->cells = array($cell1, $cell2);
851 $t->data[] = $row;
854 // Show graders whether this submission is editable by students.
855 if ($status->view == assign_submission_status::GRADER_VIEW) {
856 $row = new html_table_row();
857 $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
858 if ($status->canedit) {
859 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
860 $cell2->attributes = array('class'=>'submissioneditable');
861 } else {
862 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
863 $cell2->attributes = array('class'=>'submissionnoteditable');
865 $row->cells = array($cell1, $cell2);
866 $t->data[] = $row;
869 // Grading criteria preview.
870 if (!empty($status->gradingcontrollerpreview)) {
871 $row = new html_table_row();
872 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
873 $cell2 = new html_table_cell($status->gradingcontrollerpreview);
874 $row->cells = array($cell1, $cell2);
875 $t->data[] = $row;
878 // Last modified.
879 if ($submission) {
880 $row = new html_table_row();
881 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
883 if ($submission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
884 $cell2 = new html_table_cell(userdate($submission->timemodified));
885 } else {
886 $cell2 = new html_table_cell('-');
889 $row->cells = array($cell1, $cell2);
890 $t->data[] = $row;
892 if (!$status->teamsubmission || $status->submissiongroup != false || !$status->preventsubmissionnotingroup) {
893 foreach ($status->submissionplugins as $plugin) {
894 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
895 if ($plugin->is_enabled() &&
896 $plugin->is_visible() &&
897 $plugin->has_user_summary() &&
898 $pluginshowsummary
901 $row = new html_table_row();
902 $cell1 = new html_table_cell($plugin->get_name());
903 $displaymode = assign_submission_plugin_submission::SUMMARY;
904 $pluginsubmission = new assign_submission_plugin_submission($plugin,
905 $submission,
906 $displaymode,
907 $status->coursemoduleid,
908 $status->returnaction,
909 $status->returnparams);
910 $cell2 = new html_table_cell($this->render($pluginsubmission));
911 $row->cells = array($cell1, $cell2);
912 $t->data[] = $row;
918 $o .= $warningmsg;
919 $o .= html_writer::table($t);
920 $o .= $this->output->box_end();
922 // Links.
923 if ($status->view == assign_submission_status::STUDENT_VIEW) {
924 if ($status->canedit) {
925 if (!$submission || $submission->status == ASSIGN_SUBMISSION_STATUS_NEW) {
926 $o .= $this->output->box_start('generalbox submissionaction');
927 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
928 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
929 get_string('addsubmission', 'assign'), 'get');
930 $o .= $this->output->box_start('boxaligncenter submithelp');
931 $o .= get_string('addsubmission_help', 'assign');
932 $o .= $this->output->box_end();
933 $o .= $this->output->box_end();
934 } else if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
935 $o .= $this->output->box_start('generalbox submissionaction');
936 $urlparams = array('id' => $status->coursemoduleid,
937 'action' => 'editprevioussubmission',
938 'sesskey'=>sesskey());
939 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
940 get_string('addnewattemptfromprevious', 'assign'), 'get');
941 $o .= $this->output->box_start('boxaligncenter submithelp');
942 $o .= get_string('addnewattemptfromprevious_help', 'assign');
943 $o .= $this->output->box_end();
944 $o .= $this->output->box_end();
945 $o .= $this->output->box_start('generalbox submissionaction');
946 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
947 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
948 get_string('addnewattempt', 'assign'), 'get');
949 $o .= $this->output->box_start('boxaligncenter submithelp');
950 $o .= get_string('addnewattempt_help', 'assign');
951 $o .= $this->output->box_end();
952 $o .= $this->output->box_end();
953 } else {
954 $o .= $this->output->box_start('generalbox submissionaction');
955 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
956 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
957 get_string('editsubmission', 'assign'), 'get');
958 $o .= $this->output->box_start('boxaligncenter submithelp');
959 $o .= get_string('editsubmission_help', 'assign');
960 $o .= $this->output->box_end();
961 $o .= $this->output->box_end();
965 if ($status->cansubmit) {
966 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
967 $o .= $this->output->box_start('generalbox submissionaction');
968 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
969 get_string('submitassignment', 'assign'), 'get');
970 $o .= $this->output->box_start('boxaligncenter submithelp');
971 $o .= get_string('submitassignment_help', 'assign');
972 $o .= $this->output->box_end();
973 $o .= $this->output->box_end();
977 $o .= $this->output->container_end();
978 return $o;
982 * Output the attempt history chooser for this assignment
984 * @param assign_attempt_history_chooser $history
985 * @return string
987 public function render_assign_attempt_history_chooser(assign_attempt_history_chooser $history) {
988 $o = '';
990 $context = $history->export_for_template($this);
991 $o .= $this->render_from_template('mod_assign/attempt_history_chooser', $context);
993 return $o;
997 * Output the attempt history for this assignment
999 * @param assign_attempt_history $history
1000 * @return string
1002 public function render_assign_attempt_history(assign_attempt_history $history) {
1003 $o = '';
1005 $submittedstr = get_string('submitted', 'assign');
1006 $gradestr = get_string('grade');
1007 $gradedonstr = get_string('gradedon', 'assign');
1008 $gradedbystr = get_string('gradedby', 'assign');
1010 // Don't show the last one because it is the current submission.
1011 array_pop($history->submissions);
1013 // Show newest to oldest.
1014 $history->submissions = array_reverse($history->submissions);
1016 if (empty($history->submissions)) {
1017 return '';
1020 $containerid = 'attempthistory' . uniqid();
1021 $o .= $this->output->heading(get_string('attempthistory', 'assign'), 3);
1022 $o .= $this->box_start('attempthistory', $containerid);
1024 foreach ($history->submissions as $i => $submission) {
1025 $grade = null;
1026 foreach ($history->grades as $onegrade) {
1027 if ($onegrade->attemptnumber == $submission->attemptnumber) {
1028 $grade = $onegrade;
1029 break;
1033 $editbtn = '';
1035 if ($submission) {
1036 $submissionsummary = userdate($submission->timemodified);
1037 } else {
1038 $submissionsummary = get_string('nosubmission', 'assign');
1041 $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+1,
1042 'submissionsummary'=>$submissionsummary);
1043 $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4);
1045 $t = new html_table();
1047 if ($submission) {
1048 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
1049 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status, 'assign'));
1050 $t->data[] = new html_table_row(array($cell1, $cell2));
1052 foreach ($history->submissionplugins as $plugin) {
1053 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
1054 if ($plugin->is_enabled() &&
1055 $plugin->is_visible() &&
1056 $plugin->has_user_summary() &&
1057 $pluginshowsummary) {
1059 $cell1 = new html_table_cell($plugin->get_name());
1060 $pluginsubmission = new assign_submission_plugin_submission($plugin,
1061 $submission,
1062 assign_submission_plugin_submission::SUMMARY,
1063 $history->coursemoduleid,
1064 $history->returnaction,
1065 $history->returnparams);
1066 $cell2 = new html_table_cell($this->render($pluginsubmission));
1068 $t->data[] = new html_table_row(array($cell1, $cell2));
1073 if ($grade) {
1074 // Heading 'feedback'.
1075 $title = get_string('feedback', 'assign', $i);
1076 $title .= $this->output->spacer(array('width'=>10));
1077 if ($history->cangrade) {
1078 // Edit previous feedback.
1079 $returnparams = http_build_query($history->returnparams);
1080 $urlparams = array('id' => $history->coursemoduleid,
1081 'rownum'=>$history->rownum,
1082 'useridlistid'=>$history->useridlistid,
1083 'attemptnumber'=>$grade->attemptnumber,
1084 'action'=>'grade',
1085 'returnaction'=>$history->returnaction,
1086 'returnparams'=>$returnparams);
1087 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1088 $icon = new pix_icon('gradefeedback',
1089 get_string('editattemptfeedback', 'assign', $grade->attemptnumber+1),
1090 'mod_assign');
1091 $title .= $this->output->action_icon($url, $icon);
1093 $cell = new html_table_cell($title);
1094 $cell->attributes['class'] = 'feedbacktitle';
1095 $cell->colspan = 2;
1096 $t->data[] = new html_table_row(array($cell));
1098 // Grade.
1099 $cell1 = new html_table_cell($gradestr);
1100 $cell2 = $grade->gradefordisplay;
1101 $t->data[] = new html_table_row(array($cell1, $cell2));
1103 // Graded on.
1104 $cell1 = new html_table_cell($gradedonstr);
1105 $cell2 = new html_table_cell(userdate($grade->timemodified));
1106 $t->data[] = new html_table_row(array($cell1, $cell2));
1108 // Graded by.
1109 $cell1 = new html_table_cell($gradedbystr);
1110 $cell2 = new html_table_cell($this->output->user_picture($grade->grader) .
1111 $this->output->spacer(array('width'=>30)) . fullname($grade->grader));
1112 $t->data[] = new html_table_row(array($cell1, $cell2));
1114 // Feedback from plugins.
1115 foreach ($history->feedbackplugins as $plugin) {
1116 if ($plugin->is_enabled() &&
1117 $plugin->is_visible() &&
1118 $plugin->has_user_summary() &&
1119 !$plugin->is_empty($grade)) {
1121 $cell1 = new html_table_cell($plugin->get_name());
1122 $pluginfeedback = new assign_feedback_plugin_feedback(
1123 $plugin, $grade, assign_feedback_plugin_feedback::SUMMARY, $history->coursemoduleid,
1124 $history->returnaction, $history->returnparams
1126 $cell2 = new html_table_cell($this->render($pluginfeedback));
1127 $t->data[] = new html_table_row(array($cell1, $cell2));
1134 $o .= html_writer::table($t);
1136 $o .= $this->box_end();
1137 $jsparams = array($containerid);
1139 $this->page->requires->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history');
1141 return $o;
1145 * Render a submission plugin submission
1147 * @param assign_submission_plugin_submission $submissionplugin
1148 * @return string
1150 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
1151 $o = '';
1153 if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
1154 $showviewlink = false;
1155 $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission,
1156 $showviewlink);
1158 $classsuffix = $submissionplugin->plugin->get_subtype() .
1159 '_' .
1160 $submissionplugin->plugin->get_type() .
1161 '_' .
1162 $submissionplugin->submission->id;
1164 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1166 $link = '';
1167 if ($showviewlink) {
1168 $previewstr = get_string('viewsubmission', 'assign');
1169 $icon = $this->output->pix_icon('t/preview', $previewstr);
1171 $expandstr = get_string('viewfull', 'assign');
1172 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1173 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
1175 $jsparams = array($submissionplugin->plugin->get_subtype(),
1176 $submissionplugin->plugin->get_type(),
1177 $submissionplugin->submission->id);
1179 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1181 $action = 'viewplugin' . $submissionplugin->plugin->get_subtype();
1182 $returnparams = http_build_query($submissionplugin->returnparams);
1183 $link .= '<noscript>';
1184 $urlparams = array('id' => $submissionplugin->coursemoduleid,
1185 'sid'=>$submissionplugin->submission->id,
1186 'plugin'=>$submissionplugin->plugin->get_type(),
1187 'action'=>$action,
1188 'returnaction'=>$submissionplugin->returnaction,
1189 'returnparams'=>$returnparams);
1190 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1191 $link .= $this->output->action_link($url, $icon);
1192 $link .= '</noscript>';
1194 $link .= $this->output->spacer(array('width'=>15));
1197 $o .= $link . $summary;
1198 $o .= $this->output->box_end();
1199 if ($showviewlink) {
1200 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
1201 $classes = 'expandsummaryicon contract_' . $classsuffix;
1202 $o .= $this->output->pix_icon('t/switch_minus',
1203 get_string('viewsummary', 'assign'),
1204 null,
1205 array('class'=>$classes));
1206 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
1207 $o .= $this->output->box_end();
1209 } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
1210 $o .= $this->output->box_start('boxaligncenter submissionfull');
1211 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
1212 $o .= $this->output->box_end();
1215 return $o;
1219 * Render the grading table.
1221 * @param assign_grading_table $table
1222 * @return string
1224 public function render_assign_grading_table(assign_grading_table $table) {
1225 $o = '';
1226 $o .= $this->output->box_start('boxaligncenter gradingtable');
1228 $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
1229 $this->page->requires->string_for_js('nousersselected', 'assign');
1230 $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
1231 $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
1232 $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
1233 $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
1234 $this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign');
1235 $this->page->requires->string_for_js('batchoperationconfirmdownloadselected', 'assign');
1236 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
1237 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
1238 $this->page->requires->string_for_js('editaction', 'assign');
1239 foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
1240 foreach ($operations as $operation => $description) {
1241 $this->page->requires->string_for_js('batchoperationconfirm' . $operation,
1242 'assignfeedback_' . $plugin);
1245 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
1246 $o .= $this->output->box_end();
1248 return $o;
1252 * Render a feedback plugin feedback
1254 * @param assign_feedback_plugin_feedback $feedbackplugin
1255 * @return string
1257 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
1258 $o = '';
1260 if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
1261 $showviewlink = false;
1262 $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
1264 $classsuffix = $feedbackplugin->plugin->get_subtype() .
1265 '_' .
1266 $feedbackplugin->plugin->get_type() .
1267 '_' .
1268 $feedbackplugin->grade->id;
1269 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1271 $link = '';
1272 if ($showviewlink) {
1273 $previewstr = get_string('viewfeedback', 'assign');
1274 $icon = $this->output->pix_icon('t/preview', $previewstr);
1276 $expandstr = get_string('viewfull', 'assign');
1277 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1278 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
1280 $jsparams = array($feedbackplugin->plugin->get_subtype(),
1281 $feedbackplugin->plugin->get_type(),
1282 $feedbackplugin->grade->id);
1283 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1285 $urlparams = array('id' => $feedbackplugin->coursemoduleid,
1286 'gid'=>$feedbackplugin->grade->id,
1287 'plugin'=>$feedbackplugin->plugin->get_type(),
1288 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
1289 'returnaction'=>$feedbackplugin->returnaction,
1290 'returnparams'=>http_build_query($feedbackplugin->returnparams));
1291 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1292 $link .= '<noscript>';
1293 $link .= $this->output->action_link($url, $icon);
1294 $link .= '</noscript>';
1296 $link .= $this->output->spacer(array('width'=>15));
1299 $o .= $link . $summary;
1300 $o .= $this->output->box_end();
1301 if ($showviewlink) {
1302 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
1303 $classes = 'expandsummaryicon contract_' . $classsuffix;
1304 $o .= $this->output->pix_icon('t/switch_minus',
1305 get_string('viewsummary', 'assign'),
1306 null,
1307 array('class'=>$classes));
1308 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1309 $o .= $this->output->box_end();
1311 } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
1312 $o .= $this->output->box_start('boxaligncenter feedbackfull');
1313 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1314 $o .= $this->output->box_end();
1317 return $o;
1321 * Render a course index summary
1323 * @param assign_course_index_summary $indexsummary
1324 * @return string
1326 public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
1327 $o = '';
1329 $strplural = get_string('modulenameplural', 'assign');
1330 $strsectionname = $indexsummary->courseformatname;
1331 $strduedate = get_string('duedate', 'assign');
1332 $strsubmission = get_string('submission', 'assign');
1333 $strgrade = get_string('grade');
1335 $table = new html_table();
1336 if ($indexsummary->usesections) {
1337 $table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
1338 $table->align = array ('left', 'left', 'center', 'right', 'right');
1339 } else {
1340 $table->head = array ($strplural, $strduedate, $strsubmission, $strgrade);
1341 $table->align = array ('left', 'left', 'center', 'right');
1343 $table->data = array();
1345 $currentsection = '';
1346 foreach ($indexsummary->assignments as $info) {
1347 $params = array('id' => $info['cmid']);
1348 $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
1349 $info['cmname']);
1350 $due = $info['timedue'] ? userdate($info['timedue']) : '-';
1352 $printsection = '';
1353 if ($indexsummary->usesections) {
1354 if ($info['sectionname'] !== $currentsection) {
1355 if ($info['sectionname']) {
1356 $printsection = $info['sectionname'];
1358 if ($currentsection !== '') {
1359 $table->data[] = 'hr';
1361 $currentsection = $info['sectionname'];
1365 if ($indexsummary->usesections) {
1366 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
1367 } else {
1368 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
1370 $table->data[] = $row;
1373 $o .= html_writer::table($table);
1375 return $o;
1381 * Internal function - creates htmls structure suitable for YUI tree.
1383 * @param assign_files $tree
1384 * @param array $dir
1385 * @return string
1387 protected function htmllize_tree(assign_files $tree, $dir) {
1388 global $CFG;
1389 $yuiconfig = array();
1390 $yuiconfig['type'] = 'html';
1392 if (empty($dir['subdirs']) and empty($dir['files'])) {
1393 return '';
1396 $result = '<ul>';
1397 foreach ($dir['subdirs'] as $subdir) {
1398 $image = $this->output->pix_icon(file_folder_icon(),
1399 $subdir['dirname'],
1400 'moodle',
1401 array('class'=>'icon'));
1402 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1403 '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
1404 $this->htmllize_tree($tree, $subdir) .
1405 '</li>';
1408 foreach ($dir['files'] as $file) {
1409 $filename = $file->get_filename();
1410 if ($CFG->enableplagiarism) {
1411 require_once($CFG->libdir.'/plagiarismlib.php');
1412 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(),
1413 'file'=>$file,
1414 'cmid'=>$tree->cm->id,
1415 'course'=>$tree->course));
1416 } else {
1417 $plagiarismlinks = '';
1419 $image = $this->output->pix_icon(file_file_icon($file),
1420 $filename,
1421 'moodle',
1422 array('class'=>'icon'));
1423 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1424 '<div>' .
1425 '<div class="fileuploadsubmission">' . $image . ' ' .
1426 $file->fileurl . ' ' .
1427 $plagiarismlinks . ' ' .
1428 $file->portfoliobutton . ' ' .
1429 '</div>' .
1430 '<div class="fileuploadsubmissiontime">' . $file->timemodified . '</div>' .
1431 '</div>' .
1432 '</li>';
1435 $result .= '</ul>';
1437 return $result;
1441 * Helper method dealing with the fact we can not just fetch the output of flexible_table
1443 * @param flexible_table $table The table to render
1444 * @param int $rowsperpage How many assignments to render in a page
1445 * @param bool $displaylinks - Whether to render links in the table
1446 * (e.g. downloads would not enable this)
1447 * @return string HTML
1449 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
1451 $o = '';
1452 ob_start();
1453 $table->out($rowsperpage, $displaylinks);
1454 $o = ob_get_contents();
1455 ob_end_clean();
1457 return $o;
1461 * Helper method dealing with the fact we can not just fetch the output of moodleforms
1463 * @param moodleform $mform
1464 * @return string HTML
1466 protected function moodleform(moodleform $mform) {
1468 $o = '';
1469 ob_start();
1470 $mform->display();
1471 $o = ob_get_contents();
1472 ob_end_clean();
1474 return $o;
1478 * Defer to template..
1480 * @param grading_app $app - All the data to render the grading app.
1482 public function render_grading_app(grading_app $app) {
1483 $context = $app->export_for_template($this);
1484 return $this->render_from_template('mod_assign/grading_app', $context);