2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file contains a renderer for the assignment class
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 require_once($CFG->dirroot
. '/mod/assign/locallib.php');
30 * A custom renderer class that extends the plugin_renderer_base and is used by the assign module.
33 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class mod_assign_renderer
extends plugin_renderer_base
{
39 * Rendering assignment files
41 * @param context $context
43 * @param string $filearea
44 * @param string $component
47 public function assign_files(context
$context, $userid, $filearea, $component) {
48 return $this->render(new assign_files($context, $userid, $filearea, $component));
52 * Rendering assignment files
54 * @param assign_files $tree
57 public function render_assign_files(assign_files
$tree) {
58 $this->htmlid
= html_writer
::random_id('assign_files_tree');
59 $this->page
->requires
->js_init_call('M.mod_assign.init_tree', array(true, $this->htmlid
));
60 $html = '<div id="'.$this->htmlid
.'">';
61 $html .= $this->htmllize_tree($tree, $tree->dir
);
64 if ($tree->portfolioform
) {
65 $html .= $tree->portfolioform
;
71 * Utility function to add a row of data to a table with 2 columns. Modified
72 * the table param and does not return a value
74 * @param html_table $table The table to append the row of data to
75 * @param string $first The first column text
76 * @param string $second The second column text
79 private function add_table_row_tuple(html_table
$table, $first, $second) {
80 $row = new html_table_row();
81 $cell1 = new html_table_cell($first);
82 $cell2 = new html_table_cell($second);
83 $row->cells
= array($cell1, $cell2);
84 $table->data
[] = $row;
88 * Render a grading message notification
89 * @param assign_gradingmessage $result The result to render
92 public function render_assign_gradingmessage(assign_gradingmessage
$result) {
93 $urlparams = array('id' => $result->coursemoduleid
, 'action'=>'grading');
94 if (!empty($result->page
)) {
95 $urlparams['page'] = $result->page
;
97 $url = new moodle_url('/mod/assign/view.php', $urlparams);
98 $classes = $result->gradingerror ?
'notifyproblem' : 'notifysuccess';
101 $o .= $this->output
->heading($result->heading
, 4);
102 $o .= $this->output
->notification($result->message
, $classes);
103 $o .= $this->output
->continue_button($url);
108 * Render the generic form
109 * @param assign_form $form The form to render
112 public function render_assign_form(assign_form
$form) {
114 if ($form->jsinitfunction
) {
115 $this->page
->requires
->js_init_call($form->jsinitfunction
, array());
117 $o .= $this->output
->box_start('boxaligncenter ' . $form->classname
);
118 $o .= $this->moodleform($form->form
);
119 $o .= $this->output
->box_end();
124 * Render the user summary
126 * @param assign_user_summary $summary The user summary to render
129 public function render_assign_user_summary(assign_user_summary
$summary) {
134 if (!$summary->user
) {
138 if ($summary->suspendeduser
) {
139 $supendedclass = ' usersuspended';
140 $suspendedstring = get_string('userenrolmentsuspended', 'grades');
141 $suspendedicon = ' ' . html_writer
::empty_tag('img', array('src' => $this->pix_url('i/enrolmentsuspended'),
142 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
144 $o .= $this->output
->container_start('usersummary');
145 $o .= $this->output
->box_start('boxaligncenter usersummarysection'.$supendedclass);
146 if ($summary->blindmarking
) {
147 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser
.$suspendedicon;
149 $o .= $this->output
->user_picture($summary->user
);
150 $o .= $this->output
->spacer(array('width'=>30));
151 $urlparams = array('id' => $summary->user
->id
, 'course'=>$summary->courseid
);
152 $url = new moodle_url('/user/view.php', $urlparams);
153 $fullname = fullname($summary->user
, $summary->viewfullnames
);
154 $extrainfo = array();
155 foreach ($summary->extrauserfields
as $extrafield) {
156 $extrainfo[] = $summary->user
->$extrafield;
158 if (count($extrainfo)) {
159 $fullname .= ' (' . implode(', ', $extrainfo) . ')';
161 $fullname .= $suspendedicon;
162 $o .= $this->output
->action_link($url, $fullname);
164 $o .= $this->output
->box_end();
165 $o .= $this->output
->container_end();
171 * Render the submit for grading page
173 * @param assign_submit_for_grading_page $page
176 public function render_assign_submit_for_grading_page($page) {
179 $o .= $this->output
->container_start('submitforgrading');
180 $o .= $this->output
->heading(get_string('submitassignment', 'assign'), 3);
181 $o .= $this->output
->spacer(array('height'=>30));
183 $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid
));
184 if (count($page->notifications
)) {
185 // At least one of the submission plugins is not ready for submission.
187 $o .= $this->output
->heading(get_string('submissionnotready', 'assign'), 4);
189 foreach ($page->notifications
as $notification) {
190 $o .= $this->output
->notification($notification);
193 $o .= $this->output
->continue_button($cancelurl);
195 // All submission plugins ready - show the confirmation form.
196 $o .= $this->output
->box_start('generalbox submitconfirm');
197 $o .= $this->moodleform($page->confirmform
);
198 $o .= $this->output
->box_end();
200 $o .= $this->output
->container_end();
206 * Page is done - render the footer.
210 public function render_footer() {
211 return $this->output
->footer();
217 * @param assign_header $header
220 public function render_assign_header(assign_header
$header) {
223 if ($header->subpage
) {
224 $this->page
->navbar
->add($header->subpage
);
227 $this->page
->set_title(get_string('pluginname', 'assign'));
228 $this->page
->set_heading($this->page
->course
->fullname
);
230 $o .= $this->output
->header();
231 $heading = format_string($header->assign
->name
, false, array('context' => $header->context
));
232 $o .= $this->output
->heading($heading);
233 if ($header->preface
) {
234 $o .= $header->preface
;
237 if ($header->showintro
) {
238 $o .= $this->output
->box_start('generalbox boxaligncenter', 'intro');
239 $o .= format_module_intro('assign', $header->assign
, $header->coursemoduleid
);
240 $o .= $header->postfix
;
241 $o .= $this->output
->box_end();
248 * Render the header for an individual plugin.
250 * @param assign_plugin_header $header
253 public function render_assign_plugin_header(assign_plugin_header
$header) {
254 $o = $header->plugin
->view_header();
259 * Render a table containing the current status of the grading process.
261 * @param assign_grading_summary $summary
264 public function render_assign_grading_summary(assign_grading_summary
$summary) {
265 // Create a table for the data.
267 $o .= $this->output
->container_start('gradingsummary');
268 $o .= $this->output
->heading(get_string('gradingsummary', 'assign'), 3);
269 $o .= $this->output
->box_start('boxaligncenter gradingsummarytable');
270 $t = new html_table();
273 if ($summary->teamsubmission
) {
274 if ($summary->warnofungroupedusers
) {
275 $o .= $this->output
->notification(get_string('ungroupedusers', 'assign'));
278 $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
279 $summary->participantcount
);
281 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
282 $summary->participantcount
);
285 // Drafts count and dont show drafts count when using offline assignment.
286 if ($summary->submissiondraftsenabled
&& $summary->submissionsenabled
) {
287 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
288 $summary->submissiondraftscount
);
291 // Submitted for grading.
292 if ($summary->submissionsenabled
) {
293 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
294 $summary->submissionssubmittedcount
);
295 if (!$summary->teamsubmission
) {
296 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
297 $summary->submissionsneedgradingcount
);
302 if ($summary->duedate
) {
304 $duedate = $summary->duedate
;
305 $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
310 if ($duedate - $time <= 0) {
311 $due = get_string('assignmentisdue', 'assign');
313 $due = format_time($duedate - $time);
315 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
317 if ($duedate < $time) {
318 $cutoffdate = $summary->cutoffdate
;
320 if ($cutoffdate > $time) {
321 $late = get_string('latesubmissionsaccepted', 'assign', userdate($summary->cutoffdate
));
323 $late = get_string('nomoresubmissionsaccepted', 'assign');
325 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
331 // All done - write the table.
332 $o .= html_writer
::table($t);
333 $o .= $this->output
->box_end();
335 // Link to the grading page.
336 $o .= $this->output
->container_start('submissionlinks');
337 $urlparams = array('id' => $summary->coursemoduleid
, 'action'=>'grading');
338 $url = new moodle_url('/mod/assign/view.php', $urlparams);
339 $o .= $this->output
->action_link($url, get_string('viewgrading', 'assign'));
340 $o .= $this->output
->container_end();
342 // Close the container and insert a spacer.
343 $o .= $this->output
->container_end();
349 * Render a table containing all the current grades and feedback.
351 * @param assign_feedback_status $status
354 public function render_assign_feedback_status(assign_feedback_status
$status) {
358 $o .= $this->output
->container_start('feedback');
359 $o .= $this->output
->heading(get_string('feedback', 'assign'), 3);
360 $o .= $this->output
->box_start('boxaligncenter feedbacktable');
361 $t = new html_table();
364 if (isset($status->gradefordisplay
)) {
365 $row = new html_table_row();
366 $cell1 = new html_table_cell(get_string('grade'));
367 $cell2 = new html_table_cell($status->gradefordisplay
);
368 $row->cells
= array($cell1, $cell2);
372 $row = new html_table_row();
373 $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
374 $cell2 = new html_table_cell(userdate($status->gradeddate
));
375 $row->cells
= array($cell1, $cell2);
379 if ($status->grader
) {
381 $row = new html_table_row();
382 $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
383 $userdescription = $this->output
->user_picture($status->grader
) .
384 $this->output
->spacer(array('width'=>30)) .
385 fullname($status->grader
);
386 $cell2 = new html_table_cell($userdescription);
387 $row->cells
= array($cell1, $cell2);
391 foreach ($status->feedbackplugins
as $plugin) {
392 if ($plugin->is_enabled() &&
393 $plugin->is_visible() &&
394 $plugin->has_user_summary() &&
395 !empty($status->grade
) &&
396 !$plugin->is_empty($status->grade
)) {
398 $row = new html_table_row();
399 $cell1 = new html_table_cell($plugin->get_name());
400 $displaymode = assign_feedback_plugin_feedback
::SUMMARY
;
401 $pluginfeedback = new assign_feedback_plugin_feedback($plugin,
404 $status->coursemoduleid
,
405 $status->returnaction
,
406 $status->returnparams
);
407 $cell2 = new html_table_cell($this->render($pluginfeedback));
408 $row->cells
= array($cell1, $cell2);
413 $o .= html_writer
::table($t);
414 $o .= $this->output
->box_end();
416 $o .= $this->output
->container_end();
421 * Render a table containing the current status of the submission.
423 * @param assign_submission_status $status
426 public function render_assign_submission_status(assign_submission_status
$status) {
428 $o .= $this->output
->container_start('submissionstatustable');
429 $o .= $this->output
->heading(get_string('submissionstatusheading', 'assign'), 3);
432 if ($status->allowsubmissionsfromdate
&&
433 $time <= $status->allowsubmissionsfromdate
) {
434 $o .= $this->output
->box_start('generalbox boxaligncenter submissionsalloweddates');
435 if ($status->alwaysshowdescription
) {
436 $date = userdate($status->allowsubmissionsfromdate
);
437 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
439 $date = userdate($status->allowsubmissionsfromdate
);
440 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
442 $o .= $this->output
->box_end();
444 $o .= $this->output
->box_start('boxaligncenter submissionsummarytable');
446 $t = new html_table();
448 if ($status->teamsubmissionenabled
) {
449 $row = new html_table_row();
450 $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
451 $group = $status->submissiongroup
;
453 $cell2 = new html_table_cell(format_string($group->name
, false, $status->context
));
454 } else if ($status->preventsubmissionnotingroup
) {
455 if (count($status->usergroups
) == 0) {
456 $cell2 = new html_table_cell(
457 html_writer
::span(get_string('noteam', 'assign'), 'alert alert-error')
459 } else if (count($status->usergroups
) > 1) {
460 $cell2 = new html_table_cell(
461 html_writer
::span(get_string('multipleteams', 'assign'), 'alert alert-error')
465 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
467 $row->cells
= array($cell1, $cell2);
471 if ($status->attemptreopenmethod
!= ASSIGN_ATTEMPT_REOPEN_METHOD_NONE
) {
473 if (!$status->teamsubmissionenabled
) {
474 if ($status->submission
) {
475 $currentattempt = $status->submission
->attemptnumber +
1;
478 if ($status->teamsubmission
) {
479 $currentattempt = $status->teamsubmission
->attemptnumber +
1;
483 $row = new html_table_row();
484 $cell1 = new html_table_cell(get_string('attemptnumber', 'assign'));
485 $maxattempts = $status->maxattempts
;
486 if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS
) {
487 $message = get_string('currentattempt', 'assign', $currentattempt);
489 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt,
490 'maxattempts'=>$maxattempts));
492 $cell2 = new html_table_cell($message);
493 $row->cells
= array($cell1, $cell2);
497 $row = new html_table_row();
498 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
499 if (!$status->teamsubmissionenabled
) {
500 if ($status->submission
&& $status->submission
->status
!= ASSIGN_SUBMISSION_STATUS_NEW
) {
501 $statusstr = get_string('submissionstatus_' . $status->submission
->status
, 'assign');
502 $cell2 = new html_table_cell($statusstr);
503 $cell2->attributes
= array('class'=>'submissionstatus' . $status->submission
->status
);
505 if (!$status->submissionsenabled
) {
506 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
508 $cell2 = new html_table_cell(get_string('noattempt', 'assign'));
511 $row->cells
= array($cell1, $cell2);
514 $row = new html_table_row();
515 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
516 $group = $status->submissiongroup
;
517 if (!$group && $status->preventsubmissionnotingroup
) {
518 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
519 } else if ($status->teamsubmission
&& $status->teamsubmission
->status
!= ASSIGN_SUBMISSION_STATUS_NEW
) {
520 $teamstatus = $status->teamsubmission
->status
;
521 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
523 if ($status->submissiongroup
) {
524 $groupid = $status->submissiongroup
->id
;
527 $members = $status->submissiongroupmemberswhoneedtosubmit
;
528 $userslist = array();
529 foreach ($members as $member) {
530 $urlparams = array('id' => $member->id
, 'course'=>$status->courseid
);
531 $url = new moodle_url('/user/view.php', $urlparams);
532 if ($status->view
== assign_submission_status
::GRADER_VIEW
&& $status->blindmarking
) {
533 $userslist[] = $member->alias
;
535 $fullname = fullname($member, $status->canviewfullnames
);
536 $userslist[] = $this->output
->action_link($url, $fullname);
539 if (count($userslist) > 0) {
540 $userstr = join(', ', $userslist);
541 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
542 $submissionsummary .= $this->output
->container($formatteduserstr);
545 $cell2 = new html_table_cell($submissionsummary);
546 $cell2->attributes
= array('class'=>'submissionstatus' . $status->teamsubmission
->status
);
548 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
549 if (!$status->submissionsenabled
) {
550 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
552 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
555 $row->cells
= array($cell1, $cell2);
560 if ($status->locked
) {
561 $row = new html_table_row();
562 $cell1 = new html_table_cell();
563 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
564 $cell2->attributes
= array('class'=>'submissionlocked');
565 $row->cells
= array($cell1, $cell2);
570 $row = new html_table_row();
571 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
573 if ($status->gradingstatus
== ASSIGN_GRADING_STATUS_GRADED ||
574 $status->gradingstatus
== ASSIGN_GRADING_STATUS_NOT_GRADED
) {
575 $cell2 = new html_table_cell(get_string($status->gradingstatus
, 'assign'));
577 $gradingstatus = 'markingworkflowstate' . $status->gradingstatus
;
578 $cell2 = new html_table_cell(get_string($gradingstatus, 'assign'));
580 if ($status->gradingstatus
== ASSIGN_GRADING_STATUS_GRADED ||
581 $status->gradingstatus
== ASSIGN_MARKING_WORKFLOW_STATE_RELEASED
) {
582 $cell2->attributes
= array('class' => 'submissiongraded');
584 $cell2->attributes
= array('class' => 'submissionnotgraded');
586 $row->cells
= array($cell1, $cell2);
589 $submission = $status->teamsubmission ?
$status->teamsubmission
: $status->submission
;
590 $duedate = $status->duedate
;
593 $row = new html_table_row();
594 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
595 $cell2 = new html_table_cell(userdate($duedate));
596 $row->cells
= array($cell1, $cell2);
599 if ($status->view
== assign_submission_status
::GRADER_VIEW
) {
600 if ($status->cutoffdate
) {
602 $row = new html_table_row();
603 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
604 $cell2 = new html_table_cell(userdate($status->cutoffdate
));
605 $row->cells
= array($cell1, $cell2);
610 if ($status->extensionduedate
) {
612 $row = new html_table_row();
613 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
614 $cell2 = new html_table_cell(userdate($status->extensionduedate
));
615 $row->cells
= array($cell1, $cell2);
617 $duedate = $status->extensionduedate
;
621 $row = new html_table_row();
622 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
623 if ($duedate - $time <= 0) {
625 $submission->status
!= ASSIGN_SUBMISSION_STATUS_SUBMITTED
) {
626 if ($status->submissionsenabled
) {
627 $overduestr = get_string('overdue', 'assign', format_time($time - $duedate));
628 $cell2 = new html_table_cell($overduestr);
629 $cell2->attributes
= array('class'=>'overdue');
631 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
634 if ($submission->timemodified
> $duedate) {
635 $latestr = get_string('submittedlate',
637 format_time($submission->timemodified
- $duedate));
638 $cell2 = new html_table_cell($latestr);
639 $cell2->attributes
= array('class'=>'latesubmission');
641 $earlystr = get_string('submittedearly',
643 format_time($submission->timemodified
- $duedate));
644 $cell2 = new html_table_cell($earlystr);
645 $cell2->attributes
= array('class'=>'earlysubmission');
649 $cell2 = new html_table_cell(format_time($duedate - $time));
651 $row->cells
= array($cell1, $cell2);
655 // Show graders whether this submission is editable by students.
656 if ($status->view
== assign_submission_status
::GRADER_VIEW
) {
657 $row = new html_table_row();
658 $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
659 if ($status->canedit
) {
660 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
661 $cell2->attributes
= array('class'=>'submissioneditable');
663 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
664 $cell2->attributes
= array('class'=>'submissionnoteditable');
666 $row->cells
= array($cell1, $cell2);
670 // Grading criteria preview.
671 if (!empty($status->gradingcontrollerpreview
)) {
672 $row = new html_table_row();
673 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
674 $cell2 = new html_table_cell($status->gradingcontrollerpreview
);
675 $row->cells
= array($cell1, $cell2);
681 $row = new html_table_row();
682 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
683 $cell2 = new html_table_cell(userdate($submission->timemodified
));
684 $row->cells
= array($cell1, $cell2);
687 if (!$status->teamsubmission ||
$status->submissiongroup
!= false ||
!$status->preventsubmissionnotingroup
) {
688 foreach ($status->submissionplugins
as $plugin) {
689 $pluginshowsummary = !$plugin->is_empty($submission) ||
!$plugin->allow_submissions();
690 if ($plugin->is_enabled() &&
691 $plugin->is_visible() &&
692 $plugin->has_user_summary() &&
696 $row = new html_table_row();
697 $cell1 = new html_table_cell($plugin->get_name());
698 $displaymode = assign_submission_plugin_submission
::SUMMARY
;
699 $pluginsubmission = new assign_submission_plugin_submission($plugin,
702 $status->coursemoduleid
,
703 $status->returnaction
,
704 $status->returnparams
);
705 $cell2 = new html_table_cell($this->render($pluginsubmission));
706 $row->cells
= array($cell1, $cell2);
713 $o .= html_writer
::table($t);
714 $o .= $this->output
->box_end();
717 if ($status->view
== assign_submission_status
::STUDENT_VIEW
) {
718 if ($status->canedit
) {
719 if (!$submission ||
$submission->status
== ASSIGN_SUBMISSION_STATUS_NEW
) {
720 $o .= $this->output
->box_start('generalbox submissionaction');
721 $urlparams = array('id' => $status->coursemoduleid
, 'action' => 'editsubmission');
722 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
723 get_string('addsubmission', 'assign'), 'get');
724 $o .= $this->output
->box_start('boxaligncenter submithelp');
725 $o .= get_string('editsubmission_help', 'assign');
726 $o .= $this->output
->box_end();
727 $o .= $this->output
->box_end();
728 } else if ($submission->status
== ASSIGN_SUBMISSION_STATUS_REOPENED
) {
729 $o .= $this->output
->box_start('generalbox submissionaction');
730 $urlparams = array('id' => $status->coursemoduleid
,
731 'action' => 'editprevioussubmission',
732 'sesskey'=>sesskey());
733 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
734 get_string('addnewattemptfromprevious', 'assign'), 'get');
735 $o .= $this->output
->box_start('boxaligncenter submithelp');
736 $o .= get_string('addnewattemptfromprevious_help', 'assign');
737 $o .= $this->output
->box_end();
738 $o .= $this->output
->box_end();
739 $o .= $this->output
->box_start('generalbox submissionaction');
740 $urlparams = array('id' => $status->coursemoduleid
, 'action' => 'editsubmission');
741 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
742 get_string('addnewattempt', 'assign'), 'get');
743 $o .= $this->output
->box_start('boxaligncenter submithelp');
744 $o .= get_string('addnewattempt_help', 'assign');
745 $o .= $this->output
->box_end();
746 $o .= $this->output
->box_end();
748 $o .= $this->output
->box_start('generalbox submissionaction');
749 $urlparams = array('id' => $status->coursemoduleid
, 'action' => 'editsubmission');
750 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
751 get_string('editsubmission', 'assign'), 'get');
752 $o .= $this->output
->box_start('boxaligncenter submithelp');
753 $o .= get_string('editsubmission_help', 'assign');
754 $o .= $this->output
->box_end();
755 $o .= $this->output
->box_end();
759 if ($status->cansubmit
) {
760 $urlparams = array('id' => $status->coursemoduleid
, 'action'=>'submit');
761 $o .= $this->output
->box_start('generalbox submissionaction');
762 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
763 get_string('submitassignment', 'assign'), 'get');
764 $o .= $this->output
->box_start('boxaligncenter submithelp');
765 $o .= get_string('submitassignment_help', 'assign');
766 $o .= $this->output
->box_end();
767 $o .= $this->output
->box_end();
771 $o .= $this->output
->container_end();
776 * Output the attempt history for this assignment
778 * @param assign_attempt_history $history
781 public function render_assign_attempt_history(assign_attempt_history
$history) {
784 $submittedstr = get_string('submitted', 'assign');
785 $gradestr = get_string('grade');
786 $gradedonstr = get_string('gradedon', 'assign');
787 $gradedbystr = get_string('gradedby', 'assign');
789 // Don't show the last one because it is the current submission.
790 array_pop($history->submissions
);
792 // Show newest to oldest.
793 $history->submissions
= array_reverse($history->submissions
);
795 if (empty($history->submissions
)) {
799 $containerid = 'attempthistory' . uniqid();
800 $o .= $this->heading(get_string('attempthistory', 'assign'), 3);
801 $o .= $this->box_start('attempthistory', $containerid);
803 foreach ($history->submissions
as $i => $submission) {
805 foreach ($history->grades
as $onegrade) {
806 if ($onegrade->attemptnumber
== $submission->attemptnumber
) {
815 $submissionsummary = userdate($submission->timemodified
);
817 $submissionsummary = get_string('nosubmission', 'assign');
820 $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+
1,
821 'submissionsummary'=>$submissionsummary);
822 $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4);
824 $t = new html_table();
827 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
828 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status
, 'assign'));
829 $t->data
[] = new html_table_row(array($cell1, $cell2));
831 foreach ($history->submissionplugins
as $plugin) {
832 $pluginshowsummary = !$plugin->is_empty($submission) ||
!$plugin->allow_submissions();
833 if ($plugin->is_enabled() &&
834 $plugin->is_visible() &&
835 $plugin->has_user_summary() &&
836 $pluginshowsummary) {
838 $cell1 = new html_table_cell($plugin->get_name());
839 $pluginsubmission = new assign_submission_plugin_submission($plugin,
841 assign_submission_plugin_submission
::SUMMARY
,
842 $history->coursemoduleid
,
843 $history->returnaction
,
844 $history->returnparams
);
845 $cell2 = new html_table_cell($this->render($pluginsubmission));
847 $t->data
[] = new html_table_row(array($cell1, $cell2));
853 // Heading 'feedback'.
854 $title = get_string('feedback', 'assign', $i);
855 $title .= $this->output
->spacer(array('width'=>10));
856 if ($history->cangrade
) {
857 // Edit previous feedback.
858 $returnparams = http_build_query($history->returnparams
);
859 $urlparams = array('id' => $history->coursemoduleid
,
860 'rownum'=>$history->rownum
,
861 'useridlistid'=>$history->useridlistid
,
862 'attemptnumber'=>$grade->attemptnumber
,
864 'returnaction'=>$history->returnaction
,
865 'returnparams'=>$returnparams);
866 $url = new moodle_url('/mod/assign/view.php', $urlparams);
867 $icon = new pix_icon('gradefeedback',
868 get_string('editattemptfeedback', 'assign', $grade->attemptnumber+
1),
870 $title .= $this->output
->action_icon($url, $icon);
872 $cell = new html_table_cell($title);
873 $cell->attributes
['class'] = 'feedbacktitle';
875 $t->data
[] = new html_table_row(array($cell));
878 $cell1 = new html_table_cell($gradestr);
879 $cell2 = $grade->gradefordisplay
;
880 $t->data
[] = new html_table_row(array($cell1, $cell2));
883 $cell1 = new html_table_cell($gradedonstr);
884 $cell2 = new html_table_cell(userdate($grade->timemodified
));
885 $t->data
[] = new html_table_row(array($cell1, $cell2));
888 $cell1 = new html_table_cell($gradedbystr);
889 $cell2 = new html_table_cell($this->output
->user_picture($grade->grader
) .
890 $this->output
->spacer(array('width'=>30)) . fullname($grade->grader
));
891 $t->data
[] = new html_table_row(array($cell1, $cell2));
893 // Feedback from plugins.
894 foreach ($history->feedbackplugins
as $plugin) {
895 if ($plugin->is_enabled() &&
896 $plugin->is_visible() &&
897 $plugin->has_user_summary() &&
898 !$plugin->is_empty($grade)) {
900 $cell1 = new html_table_cell($plugin->get_name());
901 $pluginfeedback = new assign_feedback_plugin_feedback(
902 $plugin, $grade, assign_feedback_plugin_feedback
::SUMMARY
, $history->coursemoduleid
,
903 $history->returnaction
, $history->returnparams
905 $cell2 = new html_table_cell($this->render($pluginfeedback));
906 $t->data
[] = new html_table_row(array($cell1, $cell2));
913 $o .= html_writer
::table($t);
915 $o .= $this->box_end();
916 $jsparams = array($containerid);
918 $this->page
->requires
->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history');
924 * Render a submission plugin submission
926 * @param assign_submission_plugin_submission $submissionplugin
929 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission
$submissionplugin) {
932 if ($submissionplugin->view
== assign_submission_plugin_submission
::SUMMARY
) {
933 $showviewlink = false;
934 $summary = $submissionplugin->plugin
->view_summary($submissionplugin->submission
,
937 $classsuffix = $submissionplugin->plugin
->get_subtype() .
939 $submissionplugin->plugin
->get_type() .
941 $submissionplugin->submission
->id
;
943 $o .= $this->output
->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
947 $previewstr = get_string('viewsubmission', 'assign');
948 $icon = $this->output
->pix_icon('t/preview', $previewstr);
950 $expandstr = get_string('viewfull', 'assign');
951 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
952 $o .= $this->output
->pix_icon('t/switch_plus', $expandstr, null, $options);
954 $jsparams = array($submissionplugin->plugin
->get_subtype(),
955 $submissionplugin->plugin
->get_type(),
956 $submissionplugin->submission
->id
);
958 $this->page
->requires
->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
960 $action = 'viewplugin' . $submissionplugin->plugin
->get_subtype();
961 $returnparams = http_build_query($submissionplugin->returnparams
);
962 $link .= '<noscript>';
963 $urlparams = array('id' => $submissionplugin->coursemoduleid
,
964 'sid'=>$submissionplugin->submission
->id
,
965 'plugin'=>$submissionplugin->plugin
->get_type(),
967 'returnaction'=>$submissionplugin->returnaction
,
968 'returnparams'=>$returnparams);
969 $url = new moodle_url('/mod/assign/view.php', $urlparams);
970 $link .= $this->output
->action_link($url, $icon);
971 $link .= '</noscript>';
973 $link .= $this->output
->spacer(array('width'=>15));
976 $o .= $link . $summary;
977 $o .= $this->output
->box_end();
979 $o .= $this->output
->box_start('boxaligncenter hidefull full_' . $classsuffix);
980 $classes = 'expandsummaryicon contract_' . $classsuffix;
981 $o .= $this->output
->pix_icon('t/switch_minus',
982 get_string('viewsummary', 'assign'),
984 array('class'=>$classes));
985 $o .= $submissionplugin->plugin
->view($submissionplugin->submission
);
986 $o .= $this->output
->box_end();
988 } else if ($submissionplugin->view
== assign_submission_plugin_submission
::FULL
) {
989 $o .= $this->output
->box_start('boxaligncenter submissionfull');
990 $o .= $submissionplugin->plugin
->view($submissionplugin->submission
);
991 $o .= $this->output
->box_end();
998 * Render the grading table.
1000 * @param assign_grading_table $table
1003 public function render_assign_grading_table(assign_grading_table
$table) {
1005 $o .= $this->output
->box_start('boxaligncenter gradingtable');
1007 $this->page
->requires
->js_init_call('M.mod_assign.init_grading_table', array());
1008 $this->page
->requires
->string_for_js('nousersselected', 'assign');
1009 $this->page
->requires
->string_for_js('batchoperationconfirmgrantextension', 'assign');
1010 $this->page
->requires
->string_for_js('batchoperationconfirmlock', 'assign');
1011 $this->page
->requires
->string_for_js('batchoperationconfirmreverttodraft', 'assign');
1012 $this->page
->requires
->string_for_js('batchoperationconfirmunlock', 'assign');
1013 $this->page
->requires
->string_for_js('batchoperationconfirmaddattempt', 'assign');
1014 $this->page
->requires
->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
1015 $this->page
->requires
->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
1016 $this->page
->requires
->string_for_js('editaction', 'assign');
1017 foreach ($table->plugingradingbatchoperations
as $plugin => $operations) {
1018 foreach ($operations as $operation => $description) {
1019 $this->page
->requires
->string_for_js('batchoperationconfirm' . $operation,
1020 'assignfeedback_' . $plugin);
1023 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
1024 $o .= $this->output
->box_end();
1030 * Render a feedback plugin feedback
1032 * @param assign_feedback_plugin_feedback $feedbackplugin
1035 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback
$feedbackplugin) {
1038 if ($feedbackplugin->view
== assign_feedback_plugin_feedback
::SUMMARY
) {
1039 $showviewlink = false;
1040 $summary = $feedbackplugin->plugin
->view_summary($feedbackplugin->grade
, $showviewlink);
1042 $classsuffix = $feedbackplugin->plugin
->get_subtype() .
1044 $feedbackplugin->plugin
->get_type() .
1046 $feedbackplugin->grade
->id
;
1047 $o .= $this->output
->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1050 if ($showviewlink) {
1051 $previewstr = get_string('viewfeedback', 'assign');
1052 $icon = $this->output
->pix_icon('t/preview', $previewstr);
1054 $expandstr = get_string('viewfull', 'assign');
1055 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1056 $o .= $this->output
->pix_icon('t/switch_plus', $expandstr, null, $options);
1058 $jsparams = array($feedbackplugin->plugin
->get_subtype(),
1059 $feedbackplugin->plugin
->get_type(),
1060 $feedbackplugin->grade
->id
);
1061 $this->page
->requires
->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1063 $urlparams = array('id' => $feedbackplugin->coursemoduleid
,
1064 'gid'=>$feedbackplugin->grade
->id
,
1065 'plugin'=>$feedbackplugin->plugin
->get_type(),
1066 'action'=>'viewplugin' . $feedbackplugin->plugin
->get_subtype(),
1067 'returnaction'=>$feedbackplugin->returnaction
,
1068 'returnparams'=>http_build_query($feedbackplugin->returnparams
));
1069 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1070 $link .= '<noscript>';
1071 $link .= $this->output
->action_link($url, $icon);
1072 $link .= '</noscript>';
1074 $link .= $this->output
->spacer(array('width'=>15));
1077 $o .= $link . $summary;
1078 $o .= $this->output
->box_end();
1079 if ($showviewlink) {
1080 $o .= $this->output
->box_start('boxaligncenter hidefull full_' . $classsuffix);
1081 $classes = 'expandsummaryicon contract_' . $classsuffix;
1082 $o .= $this->output
->pix_icon('t/switch_minus',
1083 get_string('viewsummary', 'assign'),
1085 array('class'=>$classes));
1086 $o .= $feedbackplugin->plugin
->view($feedbackplugin->grade
);
1087 $o .= $this->output
->box_end();
1089 } else if ($feedbackplugin->view
== assign_feedback_plugin_feedback
::FULL
) {
1090 $o .= $this->output
->box_start('boxaligncenter feedbackfull');
1091 $o .= $feedbackplugin->plugin
->view($feedbackplugin->grade
);
1092 $o .= $this->output
->box_end();
1099 * Render a course index summary
1101 * @param assign_course_index_summary $indexsummary
1104 public function render_assign_course_index_summary(assign_course_index_summary
$indexsummary) {
1107 $strplural = get_string('modulenameplural', 'assign');
1108 $strsectionname = $indexsummary->courseformatname
;
1109 $strduedate = get_string('duedate', 'assign');
1110 $strsubmission = get_string('submission', 'assign');
1111 $strgrade = get_string('grade');
1113 $table = new html_table();
1114 if ($indexsummary->usesections
) {
1115 $table->head
= array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
1116 $table->align
= array ('left', 'left', 'center', 'right', 'right');
1118 $table->head
= array ($strplural, $strduedate, $strsubmission, $strgrade);
1119 $table->align
= array ('left', 'left', 'center', 'right');
1121 $table->data
= array();
1123 $currentsection = '';
1124 foreach ($indexsummary->assignments
as $info) {
1125 $params = array('id' => $info['cmid']);
1126 $link = html_writer
::link(new moodle_url('/mod/assign/view.php', $params),
1128 $due = $info['timedue'] ?
userdate($info['timedue']) : '-';
1131 if ($indexsummary->usesections
) {
1132 if ($info['sectionname'] !== $currentsection) {
1133 if ($info['sectionname']) {
1134 $printsection = $info['sectionname'];
1136 if ($currentsection !== '') {
1137 $table->data
[] = 'hr';
1139 $currentsection = $info['sectionname'];
1143 if ($indexsummary->usesections
) {
1144 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
1146 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
1148 $table->data
[] = $row;
1151 $o .= html_writer
::table($table);
1159 * Internal function - creates htmls structure suitable for YUI tree.
1161 * @param assign_files $tree
1165 protected function htmllize_tree(assign_files
$tree, $dir) {
1167 $yuiconfig = array();
1168 $yuiconfig['type'] = 'html';
1170 if (empty($dir['subdirs']) and empty($dir['files'])) {
1175 foreach ($dir['subdirs'] as $subdir) {
1176 $image = $this->output
->pix_icon(file_folder_icon(),
1179 array('class'=>'icon'));
1180 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1181 '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
1182 $this->htmllize_tree($tree, $subdir) .
1186 foreach ($dir['files'] as $file) {
1187 $filename = $file->get_filename();
1188 if ($CFG->enableplagiarism
) {
1189 require_once($CFG->libdir
.'/plagiarismlib.php');
1190 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(),
1192 'cmid'=>$tree->cm
->id
,
1193 'course'=>$tree->course
));
1195 $plagiarismlinks = '';
1197 $image = $this->output
->pix_icon(file_file_icon($file),
1200 array('class'=>'icon'));
1201 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1202 '<div>' . $image . ' ' .
1203 $file->fileurl
. ' ' .
1205 $file->portfoliobutton
. '</div>' .
1215 * Helper method dealing with the fact we can not just fetch the output of flexible_table
1217 * @param flexible_table $table The table to render
1218 * @param int $rowsperpage How many assignments to render in a page
1219 * @param bool $displaylinks - Whether to render links in the table
1220 * (e.g. downloads would not enable this)
1221 * @return string HTML
1223 protected function flexible_table(flexible_table
$table, $rowsperpage, $displaylinks) {
1227 $table->out($rowsperpage, $displaylinks);
1228 $o = ob_get_contents();
1235 * Helper method dealing with the fact we can not just fetch the output of moodleforms
1237 * @param moodleform $mform
1238 * @return string HTML
1240 protected function moodleform(moodleform
$mform) {
1245 $o = ob_get_contents();