2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file contains a renderer for the assignment class
21 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
27 require_once($CFG->dirroot
. '/mod/assign/locallib.php');
30 * A custom renderer class that extends the plugin_renderer_base and is used by the assign module.
33 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class mod_assign_renderer
extends plugin_renderer_base
{
39 * Rendering assignment files
41 * @param context $context
43 * @param string $filearea
44 * @param string $component
47 public function assign_files(context
$context, $userid, $filearea, $component) {
48 return $this->render(new assign_files($context, $userid, $filearea, $component));
52 * Rendering assignment files
54 * @param assign_files $tree
57 public function render_assign_files(assign_files
$tree) {
58 $this->htmlid
= html_writer
::random_id('assign_files_tree');
59 $this->page
->requires
->js_init_call('M.mod_assign.init_tree', array(true, $this->htmlid
));
60 $html = '<div id="'.$this->htmlid
.'">';
61 $html .= $this->htmllize_tree($tree, $tree->dir
);
64 if ($tree->portfolioform
) {
65 $html .= $tree->portfolioform
;
71 * Utility function to add a row of data to a table with 2 columns. Modified
72 * the table param and does not return a value
74 * @param html_table $table The table to append the row of data to
75 * @param string $first The first column text
76 * @param string $second The second column text
79 private function add_table_row_tuple(html_table
$table, $first, $second) {
80 $row = new html_table_row();
81 $cell1 = new html_table_cell($first);
82 $cell2 = new html_table_cell($second);
83 $row->cells
= array($cell1, $cell2);
84 $table->data
[] = $row;
88 * Render a grading message notification
89 * @param assign_gradingmessage $result The result to render
92 public function render_assign_gradingmessage(assign_gradingmessage
$result) {
93 $urlparams = array('id' => $result->coursemoduleid
, 'action'=>'grading');
94 $url = new moodle_url('/mod/assign/view.php', $urlparams);
97 $o .= $this->output
->heading($result->heading
, 4);
98 $o .= $this->output
->notification($result->message
);
99 $o .= $this->output
->continue_button($url);
104 * Render the generic form
105 * @param assign_form $form The form to render
108 public function render_assign_form(assign_form
$form) {
110 if ($form->jsinitfunction
) {
111 $this->page
->requires
->js_init_call($form->jsinitfunction
, array());
113 $o .= $this->output
->box_start('boxaligncenter ' . $form->classname
);
114 $o .= $this->moodleform($form->form
);
115 $o .= $this->output
->box_end();
120 * Render the user summary
122 * @param assign_user_summary $summary The user summary to render
125 public function render_assign_user_summary(assign_user_summary
$summary) {
130 if (!$summary->user
) {
134 if ($summary->suspendeduser
) {
135 $supendedclass = ' usersuspended';
136 $suspendedstring = get_string('userenrolmentsuspended', 'grades');
137 $suspendedicon = ' ' . html_writer
::empty_tag('img', array('src' => $this->pix_url('i/enrolmentsuspended'),
138 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
140 $o .= $this->output
->container_start('usersummary');
141 $o .= $this->output
->box_start('boxaligncenter usersummarysection'.$supendedclass);
142 if ($summary->blindmarking
) {
143 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser
.$suspendedicon;
145 $o .= $this->output
->user_picture($summary->user
);
146 $o .= $this->output
->spacer(array('width'=>30));
147 $urlparams = array('id' => $summary->user
->id
, 'course'=>$summary->courseid
);
148 $url = new moodle_url('/user/view.php', $urlparams);
149 $fullname = fullname($summary->user
, $summary->viewfullnames
);
150 $extrainfo = array();
151 foreach ($summary->extrauserfields
as $extrafield) {
152 $extrainfo[] = $summary->user
->$extrafield;
154 if (count($extrainfo)) {
155 $fullname .= ' (' . implode(', ', $extrainfo) . ')';
157 $fullname .= $suspendedicon;
158 $o .= $this->output
->action_link($url, $fullname);
160 $o .= $this->output
->box_end();
161 $o .= $this->output
->container_end();
167 * Render the submit for grading page
169 * @param assign_submit_for_grading_page $page
172 public function render_assign_submit_for_grading_page($page) {
175 $o .= $this->output
->container_start('submitforgrading');
176 $o .= $this->output
->heading(get_string('submitassignment', 'assign'), 3);
177 $o .= $this->output
->spacer(array('height'=>30));
179 $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid
));
180 if (count($page->notifications
)) {
181 // At least one of the submission plugins is not ready for submission.
183 $o .= $this->output
->heading(get_string('submissionnotready', 'assign'), 4);
185 foreach ($page->notifications
as $notification) {
186 $o .= $this->output
->notification($notification);
189 $o .= $this->output
->continue_button($cancelurl);
191 // All submission plugins ready - show the confirmation form.
192 $o .= $this->output
->box_start('generalbox submitconfirm');
193 $o .= $this->moodleform($page->confirmform
);
194 $o .= $this->output
->box_end();
196 $o .= $this->output
->container_end();
202 * Page is done - render the footer.
206 public function render_footer() {
207 return $this->output
->footer();
213 * @param assign_header $header
216 public function render_assign_header(assign_header
$header) {
219 if ($header->subpage
) {
220 $this->page
->navbar
->add($header->subpage
);
223 $this->page
->set_title(get_string('pluginname', 'assign'));
224 $this->page
->set_heading($this->page
->course
->fullname
);
226 $o .= $this->output
->header();
227 $heading = format_string($header->assign
->name
, false, array('context' => $header->context
));
228 $o .= $this->output
->heading($heading);
229 if ($header->preface
) {
230 $o .= $header->preface
;
233 if ($header->showintro
) {
234 $o .= $this->output
->box_start('generalbox boxaligncenter', 'intro');
235 $o .= format_module_intro('assign', $header->assign
, $header->coursemoduleid
);
236 $o .= $this->output
->box_end();
243 * Render a table containing the current status of the grading process.
245 * @param assign_grading_summary $summary
248 public function render_assign_grading_summary(assign_grading_summary
$summary) {
249 // Create a table for the data.
251 $o .= $this->output
->container_start('gradingsummary');
252 $o .= $this->output
->heading(get_string('gradingsummary', 'assign'), 3);
253 $o .= $this->output
->box_start('boxaligncenter gradingsummarytable');
254 $t = new html_table();
257 if ($summary->teamsubmission
) {
258 $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
259 $summary->participantcount
);
261 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
262 $summary->participantcount
);
265 // Drafts count and dont show drafts count when using offline assignment.
266 if ($summary->submissiondraftsenabled
&& $summary->submissionsenabled
) {
267 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
268 $summary->submissiondraftscount
);
271 // Submitted for grading.
272 if ($summary->submissionsenabled
) {
273 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
274 $summary->submissionssubmittedcount
);
275 if (!$summary->teamsubmission
) {
276 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
277 $summary->submissionsneedgradingcount
);
282 if ($summary->duedate
) {
284 $duedate = $summary->duedate
;
285 $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
290 if ($duedate - $time <= 0) {
291 $due = get_string('assignmentisdue', 'assign');
293 $due = format_time($duedate - $time);
295 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
297 if ($duedate < $time) {
298 $cutoffdate = $summary->cutoffdate
;
300 if ($cutoffdate > $time) {
301 $late = get_string('latesubmissionsaccepted', 'assign');
303 $late = get_string('nomoresubmissionsaccepted', 'assign');
305 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
311 // All done - write the table.
312 $o .= html_writer
::table($t);
313 $o .= $this->output
->box_end();
315 // Link to the grading page.
316 $o .= $this->output
->container_start('submissionlinks');
317 $urlparams = array('id' => $summary->coursemoduleid
, 'action'=>'grading');
318 $url = new moodle_url('/mod/assign/view.php', $urlparams);
319 $o .= $this->output
->action_link($url, get_string('viewgrading', 'assign'));
320 $o .= $this->output
->container_end();
322 // Close the container and insert a spacer.
323 $o .= $this->output
->container_end();
329 * Render a table containing all the current grades and feedback.
331 * @param assign_feedback_status $status
334 public function render_assign_feedback_status(assign_feedback_status
$status) {
338 $o .= $this->output
->container_start('feedback');
339 $o .= $this->output
->heading(get_string('feedback', 'assign'), 3);
340 $o .= $this->output
->box_start('boxaligncenter feedbacktable');
341 $t = new html_table();
344 if (isset($status->gradefordisplay
)) {
345 $row = new html_table_row();
346 $cell1 = new html_table_cell(get_string('grade'));
347 $cell2 = new html_table_cell($status->gradefordisplay
);
348 $row->cells
= array($cell1, $cell2);
352 $row = new html_table_row();
353 $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
354 $cell2 = new html_table_cell(userdate($status->gradeddate
));
355 $row->cells
= array($cell1, $cell2);
359 if ($status->grader
) {
361 $row = new html_table_row();
362 $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
363 $userdescription = $this->output
->user_picture($status->grader
) .
364 $this->output
->spacer(array('width'=>30)) .
365 fullname($status->grader
);
366 $cell2 = new html_table_cell($userdescription);
367 $row->cells
= array($cell1, $cell2);
371 foreach ($status->feedbackplugins
as $plugin) {
372 if ($plugin->is_enabled() &&
373 $plugin->is_visible() &&
374 $plugin->has_user_summary() &&
375 !empty($status->grade
) &&
376 !$plugin->is_empty($status->grade
)) {
378 $row = new html_table_row();
379 $cell1 = new html_table_cell($plugin->get_name());
380 $displaymode = assign_feedback_plugin_feedback
::SUMMARY
;
381 $pluginfeedback = new assign_feedback_plugin_feedback($plugin,
384 $status->coursemoduleid
,
385 $status->returnaction
,
386 $status->returnparams
);
387 $cell2 = new html_table_cell($this->render($pluginfeedback));
388 $row->cells
= array($cell1, $cell2);
393 $o .= html_writer
::table($t);
394 $o .= $this->output
->box_end();
396 $o .= $this->output
->container_end();
401 * Render a table containing the current status of the submission.
403 * @param assign_submission_status $status
406 public function render_assign_submission_status(assign_submission_status
$status) {
408 $o .= $this->output
->container_start('submissionstatustable');
409 $o .= $this->output
->heading(get_string('submissionstatusheading', 'assign'), 3);
412 if ($status->allowsubmissionsfromdate
&&
413 $time <= $status->allowsubmissionsfromdate
) {
414 $o .= $this->output
->box_start('generalbox boxaligncenter submissionsalloweddates');
415 if ($status->alwaysshowdescription
) {
416 $date = userdate($status->allowsubmissionsfromdate
);
417 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
419 $date = userdate($status->allowsubmissionsfromdate
);
420 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
422 $o .= $this->output
->box_end();
424 $o .= $this->output
->box_start('boxaligncenter submissionsummarytable');
426 $t = new html_table();
428 if ($status->teamsubmissionenabled
) {
429 $row = new html_table_row();
430 $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
431 $group = $status->submissiongroup
;
433 $cell2 = new html_table_cell(format_string($group->name
, false, $status->context
));
435 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
437 $row->cells
= array($cell1, $cell2);
441 if ($status->attemptreopenmethod
!= ASSIGN_ATTEMPT_REOPEN_METHOD_NONE
) {
443 if (!$status->teamsubmissionenabled
) {
444 if ($status->submission
) {
445 $currentattempt = $status->submission
->attemptnumber +
1;
448 if ($status->teamsubmission
) {
449 $currentattempt = $status->teamsubmission
->attemptnumber +
1;
453 $row = new html_table_row();
454 $cell1 = new html_table_cell(get_string('attemptnumber', 'assign'));
455 $maxattempts = $status->maxattempts
;
456 if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS
) {
457 $message = get_string('currentattempt', 'assign', $currentattempt);
459 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt,
460 'maxattempts'=>$maxattempts));
462 $cell2 = new html_table_cell($message);
463 $row->cells
= array($cell1, $cell2);
467 $row = new html_table_row();
468 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
469 if (!$status->teamsubmissionenabled
) {
470 if ($status->submission
) {
471 $statusstr = get_string('submissionstatus_' . $status->submission
->status
, 'assign');
472 $cell2 = new html_table_cell($statusstr);
473 $cell2->attributes
= array('class'=>'submissionstatus' . $status->submission
->status
);
475 if (!$status->submissionsenabled
) {
476 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
478 $cell2 = new html_table_cell(get_string('noattempt', 'assign'));
481 $row->cells
= array($cell1, $cell2);
484 $row = new html_table_row();
485 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
486 if ($status->teamsubmission
) {
487 $teamstatus = $status->teamsubmission
->status
;
488 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
490 if ($status->submissiongroup
) {
491 $groupid = $status->submissiongroup
->id
;
494 $members = $status->submissiongroupmemberswhoneedtosubmit
;
495 $userslist = array();
496 foreach ($members as $member) {
497 $urlparams = array('id' => $member->id
, 'course'=>$status->courseid
);
498 $url = new moodle_url('/user/view.php', $urlparams);
499 if ($status->view
== assign_submission_status
::GRADER_VIEW
&& $status->blindmarking
) {
500 $userslist[] = $member->alias
;
502 $fullname = fullname($member, $status->canviewfullnames
);
503 $userslist[] = $this->output
->action_link($url, $fullname);
506 if (count($userslist) > 0) {
507 $userstr = join(', ', $userslist);
508 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
509 $submissionsummary .= $this->output
->container($formatteduserstr);
512 $cell2 = new html_table_cell($submissionsummary);
513 $cell2->attributes
= array('class'=>'submissionstatus' . $status->teamsubmission
->status
);
515 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
516 if (!$status->submissionsenabled
) {
517 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
519 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
522 $row->cells
= array($cell1, $cell2);
527 if ($status->locked
) {
528 $row = new html_table_row();
529 $cell1 = new html_table_cell();
530 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
531 $cell2->attributes
= array('class'=>'submissionlocked');
532 $row->cells
= array($cell1, $cell2);
537 $row = new html_table_row();
538 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
540 if ($status->graded
) {
541 $cell2 = new html_table_cell(get_string('graded', 'assign'));
542 $cell2->attributes
= array('class'=>'submissiongraded');
544 $cell2 = new html_table_cell(get_string('notgraded', 'assign'));
545 $cell2->attributes
= array('class'=>'submissionnotgraded');
547 $row->cells
= array($cell1, $cell2);
550 $duedate = $status->duedate
;
553 $row = new html_table_row();
554 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
555 $cell2 = new html_table_cell(userdate($duedate));
556 $row->cells
= array($cell1, $cell2);
559 if ($status->view
== assign_submission_status
::GRADER_VIEW
) {
560 if ($status->cutoffdate
) {
562 $row = new html_table_row();
563 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
564 $cell2 = new html_table_cell(userdate($status->cutoffdate
));
565 $row->cells
= array($cell1, $cell2);
570 if ($status->extensionduedate
) {
572 $row = new html_table_row();
573 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
574 $cell2 = new html_table_cell(userdate($status->extensionduedate
));
575 $row->cells
= array($cell1, $cell2);
577 $duedate = $status->extensionduedate
;
581 $row = new html_table_row();
582 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
583 if ($duedate - $time <= 0) {
584 if (!$status->submission ||
585 $status->submission
->status
!= ASSIGN_SUBMISSION_STATUS_SUBMITTED
) {
586 if ($status->submissionsenabled
) {
587 $overduestr = get_string('overdue', 'assign', format_time($time - $duedate));
588 $cell2 = new html_table_cell($overduestr);
589 $cell2->attributes
= array('class'=>'overdue');
591 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
594 if ($status->submission
->timemodified
> $duedate) {
595 $latestr = get_string('submittedlate',
597 format_time($status->submission
->timemodified
- $duedate));
598 $cell2 = new html_table_cell($latestr);
599 $cell2->attributes
= array('class'=>'latesubmission');
601 $earlystr = get_string('submittedearly',
603 format_time($status->submission
->timemodified
- $duedate));
604 $cell2 = new html_table_cell($earlystr);
605 $cell2->attributes
= array('class'=>'earlysubmission');
609 $cell2 = new html_table_cell(format_time($duedate - $time));
611 $row->cells
= array($cell1, $cell2);
615 // Show graders whether this submission is editable by students.
616 if ($status->view
== assign_submission_status
::GRADER_VIEW
) {
617 $row = new html_table_row();
618 $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
619 if ($status->canedit
) {
620 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
621 $cell2->attributes
= array('class'=>'submissioneditable');
623 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
624 $cell2->attributes
= array('class'=>'submissionnoteditable');
626 $row->cells
= array($cell1, $cell2);
630 // Grading criteria preview.
631 if (!empty($status->gradingcontrollerpreview
)) {
632 $row = new html_table_row();
633 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
634 $cell2 = new html_table_cell($status->gradingcontrollerpreview
);
635 $row->cells
= array($cell1, $cell2);
640 $submission = $status->teamsubmission ?
$status->teamsubmission
: $status->submission
;
642 $row = new html_table_row();
643 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
644 $cell2 = new html_table_cell(userdate($submission->timemodified
));
645 $row->cells
= array($cell1, $cell2);
648 foreach ($status->submissionplugins
as $plugin) {
649 $pluginshowsummary = !$plugin->is_empty($submission) ||
!$plugin->allow_submissions();
650 if ($plugin->is_enabled() &&
651 $plugin->is_visible() &&
652 $plugin->has_user_summary() &&
653 $pluginshowsummary) {
655 $row = new html_table_row();
656 $cell1 = new html_table_cell($plugin->get_name());
657 $displaymode = assign_submission_plugin_submission
::SUMMARY
;
658 $pluginsubmission = new assign_submission_plugin_submission($plugin,
661 $status->coursemoduleid
,
662 $status->returnaction
,
663 $status->returnparams
);
664 $cell2 = new html_table_cell($this->render($pluginsubmission));
665 $row->cells
= array($cell1, $cell2);
671 $o .= html_writer
::table($t);
672 $o .= $this->output
->box_end();
675 if ($status->view
== assign_submission_status
::STUDENT_VIEW
) {
676 if ($status->canedit
) {
678 $o .= $this->output
->box_start('generalbox submissionaction');
679 $urlparams = array('id' => $status->coursemoduleid
, 'action' => 'editsubmission');
680 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
681 get_string('addsubmission', 'assign'), 'get');
682 $o .= $this->output
->box_start('boxaligncenter submithelp');
683 $o .= get_string('editsubmission_help', 'assign');
684 $o .= $this->output
->box_end();
685 $o .= $this->output
->box_end();
686 } else if ($submission->status
== ASSIGN_SUBMISSION_STATUS_REOPENED
) {
687 $o .= $this->output
->box_start('generalbox submissionaction');
688 $urlparams = array('id' => $status->coursemoduleid
,
689 'action' => 'editprevioussubmission',
690 'sesskey'=>sesskey());
691 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
692 get_string('addnewattemptfromprevious', 'assign'), 'get');
693 $o .= $this->output
->box_start('boxaligncenter submithelp');
694 $o .= get_string('addnewattemptfromprevious_help', 'assign');
695 $o .= $this->output
->box_end();
696 $o .= $this->output
->box_end();
697 $o .= $this->output
->box_start('generalbox submissionaction');
698 $urlparams = array('id' => $status->coursemoduleid
, 'action' => 'editsubmission');
699 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
700 get_string('addnewattempt', 'assign'), 'get');
701 $o .= $this->output
->box_start('boxaligncenter submithelp');
702 $o .= get_string('addnewattempt_help', 'assign');
703 $o .= $this->output
->box_end();
704 $o .= $this->output
->box_end();
706 $o .= $this->output
->box_start('generalbox submissionaction');
707 $urlparams = array('id' => $status->coursemoduleid
, 'action' => 'editsubmission');
708 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
709 get_string('editsubmission', 'assign'), 'get');
710 $o .= $this->output
->box_start('boxaligncenter submithelp');
711 $o .= get_string('editsubmission_help', 'assign');
712 $o .= $this->output
->box_end();
713 $o .= $this->output
->box_end();
717 if ($status->cansubmit
) {
718 $urlparams = array('id' => $status->coursemoduleid
, 'action'=>'submit');
719 $o .= $this->output
->box_start('generalbox submissionaction');
720 $o .= $this->output
->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
721 get_string('submitassignment', 'assign'), 'get');
722 $o .= $this->output
->box_start('boxaligncenter submithelp');
723 $o .= get_string('submitassignment_help', 'assign');
724 $o .= $this->output
->box_end();
725 $o .= $this->output
->box_end();
729 $o .= $this->output
->container_end();
734 * Output the attempt history for this assignment
736 * @param assign_attempt_history $history
739 public function render_assign_attempt_history(assign_attempt_history
$history) {
742 $submittedstr = get_string('submitted', 'assign');
743 $gradestr = get_string('grade');
744 $gradedonstr = get_string('gradedon', 'assign');
745 $gradedbystr = get_string('gradedby', 'assign');
747 // Don't show the last one because it is the current submission.
748 array_pop($history->submissions
);
750 // Show newest to oldest.
751 $history->submissions
= array_reverse($history->submissions
);
753 if (empty($history->submissions
)) {
757 $containerid = 'attempthistory' . uniqid();
758 $o .= $this->heading(get_string('attempthistory', 'assign'), 3);
759 $o .= $this->box_start('attempthistory', $containerid);
761 foreach ($history->submissions
as $i => $submission) {
763 foreach ($history->grades
as $onegrade) {
764 if ($onegrade->attemptnumber
== $submission->attemptnumber
) {
773 $submissionsummary = userdate($submission->timemodified
);
775 $submissionsummary = get_string('nosubmission', 'assign');
778 $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+
1,
779 'submissionsummary'=>$submissionsummary);
780 $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4);
782 $t = new html_table();
785 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
786 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status
, 'assign'));
787 $t->data
[] = new html_table_row(array($cell1, $cell2));
789 foreach ($history->submissionplugins
as $plugin) {
790 $pluginshowsummary = !$plugin->is_empty($submission) ||
!$plugin->allow_submissions();
791 if ($plugin->is_enabled() &&
792 $plugin->is_visible() &&
793 $plugin->has_user_summary() &&
794 $pluginshowsummary) {
796 $cell1 = new html_table_cell($plugin->get_name());
797 $pluginsubmission = new assign_submission_plugin_submission($plugin,
799 assign_submission_plugin_submission
::SUMMARY
,
800 $history->coursemoduleid
,
801 $history->returnaction
,
802 $history->returnparams
);
803 $cell2 = new html_table_cell($this->render($pluginsubmission));
805 $t->data
[] = new html_table_row(array($cell1, $cell2));
811 // Heading 'feedback'.
812 $title = get_string('feedback', 'assign', $i);
813 $title .= $this->output
->spacer(array('width'=>10));
814 if ($history->cangrade
) {
815 // Edit previous feedback.
816 $returnparams = http_build_query($history->returnparams
);
817 $urlparams = array('id' => $history->coursemoduleid
,
818 'rownum'=>$history->rownum
,
819 'useridlistid'=>$history->useridlistid
,
820 'attemptnumber'=>$grade->attemptnumber
,
822 'returnaction'=>$history->returnaction
,
823 'returnparams'=>$returnparams);
824 $url = new moodle_url('/mod/assign/view.php', $urlparams);
825 $icon = new pix_icon('gradefeedback',
826 get_string('editattemptfeedback', 'assign', $grade->attemptnumber+
1),
828 $title .= $this->output
->action_icon($url, $icon);
830 $cell = new html_table_cell($title);
831 $cell->attributes
['class'] = 'feedbacktitle';
833 $t->data
[] = new html_table_row(array($cell));
836 $cell1 = new html_table_cell($gradestr);
837 $cell2 = $grade->gradefordisplay
;
838 $t->data
[] = new html_table_row(array($cell1, $cell2));
841 $cell1 = new html_table_cell($gradedonstr);
842 $cell2 = new html_table_cell(userdate($grade->timemodified
));
843 $t->data
[] = new html_table_row(array($cell1, $cell2));
846 $cell1 = new html_table_cell($gradedbystr);
847 $cell2 = new html_table_cell($this->output
->user_picture($grade->grader
) .
848 $this->output
->spacer(array('width'=>30)) . fullname($grade->grader
));
849 $t->data
[] = new html_table_row(array($cell1, $cell2));
851 // Feedback from plugins.
852 foreach ($history->feedbackplugins
as $plugin) {
853 if ($plugin->is_enabled() &&
854 $plugin->is_visible() &&
855 $plugin->has_user_summary() &&
856 !$plugin->is_empty($grade)) {
858 $cell1 = new html_table_cell($plugin->get_name());
859 $pluginfeedback = new assign_feedback_plugin_feedback(
860 $plugin, $grade, assign_feedback_plugin_feedback
::SUMMARY
, $history->coursemoduleid
,
861 $history->returnaction
, $history->returnparams
863 $cell2 = new html_table_cell($this->render($pluginfeedback));
864 $t->data
[] = new html_table_row(array($cell1, $cell2));
871 $o .= html_writer
::table($t);
873 $o .= $this->box_end();
874 $jsparams = array($containerid);
876 $this->page
->requires
->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history');
882 * Render a submission plugin submission
884 * @param assign_submission_plugin_submission $submissionplugin
887 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission
$submissionplugin) {
890 if ($submissionplugin->view
== assign_submission_plugin_submission
::SUMMARY
) {
891 $showviewlink = false;
892 $summary = $submissionplugin->plugin
->view_summary($submissionplugin->submission
,
895 $classsuffix = $submissionplugin->plugin
->get_subtype() .
897 $submissionplugin->plugin
->get_type() .
899 $submissionplugin->submission
->id
;
901 $o .= $this->output
->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
905 $previewstr = get_string('viewsubmission', 'assign');
906 $icon = $this->output
->pix_icon('t/preview', $previewstr);
908 $expandstr = get_string('viewfull', 'assign');
909 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
910 $o .= $this->output
->pix_icon('t/switch_plus', $expandstr, null, $options);
912 $jsparams = array($submissionplugin->plugin
->get_subtype(),
913 $submissionplugin->plugin
->get_type(),
914 $submissionplugin->submission
->id
);
916 $this->page
->requires
->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
918 $action = 'viewplugin' . $submissionplugin->plugin
->get_subtype();
919 $returnparams = http_build_query($submissionplugin->returnparams
);
920 $link .= '<noscript>';
921 $urlparams = array('id' => $submissionplugin->coursemoduleid
,
922 'sid'=>$submissionplugin->submission
->id
,
923 'plugin'=>$submissionplugin->plugin
->get_type(),
925 'returnaction'=>$submissionplugin->returnaction
,
926 'returnparams'=>$returnparams);
927 $url = new moodle_url('/mod/assign/view.php', $urlparams);
928 $link .= $this->output
->action_link($url, $icon);
929 $link .= '</noscript>';
931 $link .= $this->output
->spacer(array('width'=>15));
934 $o .= $link . $summary;
935 $o .= $this->output
->box_end();
937 $o .= $this->output
->box_start('boxaligncenter hidefull full_' . $classsuffix);
938 $classes = 'expandsummaryicon contract_' . $classsuffix;
939 $o .= $this->output
->pix_icon('t/switch_minus',
940 get_string('viewsummary', 'assign'),
942 array('class'=>$classes));
943 $o .= $submissionplugin->plugin
->view($submissionplugin->submission
);
944 $o .= $this->output
->box_end();
946 } else if ($submissionplugin->view
== assign_submission_plugin_submission
::FULL
) {
947 $o .= $this->output
->box_start('boxaligncenter submissionfull');
948 $o .= $submissionplugin->plugin
->view($submissionplugin->submission
);
949 $o .= $this->output
->box_end();
956 * Render the grading table.
958 * @param assign_grading_table $table
961 public function render_assign_grading_table(assign_grading_table
$table) {
963 $o .= $this->output
->box_start('boxaligncenter gradingtable');
965 $this->page
->requires
->js_init_call('M.mod_assign.init_grading_table', array());
966 $this->page
->requires
->string_for_js('nousersselected', 'assign');
967 $this->page
->requires
->string_for_js('batchoperationconfirmgrantextension', 'assign');
968 $this->page
->requires
->string_for_js('batchoperationconfirmlock', 'assign');
969 $this->page
->requires
->string_for_js('batchoperationconfirmreverttodraft', 'assign');
970 $this->page
->requires
->string_for_js('batchoperationconfirmunlock', 'assign');
971 $this->page
->requires
->string_for_js('batchoperationconfirmaddattempt', 'assign');
972 $this->page
->requires
->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
973 $this->page
->requires
->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
974 $this->page
->requires
->string_for_js('editaction', 'assign');
975 foreach ($table->plugingradingbatchoperations
as $plugin => $operations) {
976 foreach ($operations as $operation => $description) {
977 $this->page
->requires
->string_for_js('batchoperationconfirm' . $operation,
978 'assignfeedback_' . $plugin);
981 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
982 $o .= $this->output
->box_end();
988 * Render a feedback plugin feedback
990 * @param assign_feedback_plugin_feedback $feedbackplugin
993 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback
$feedbackplugin) {
996 if ($feedbackplugin->view
== assign_feedback_plugin_feedback
::SUMMARY
) {
997 $showviewlink = false;
998 $summary = $feedbackplugin->plugin
->view_summary($feedbackplugin->grade
, $showviewlink);
1000 $classsuffix = $feedbackplugin->plugin
->get_subtype() .
1002 $feedbackplugin->plugin
->get_type() .
1004 $feedbackplugin->grade
->id
;
1005 $o .= $this->output
->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1008 if ($showviewlink) {
1009 $previewstr = get_string('viewfeedback', 'assign');
1010 $icon = $this->output
->pix_icon('t/preview', $previewstr);
1012 $expandstr = get_string('viewfull', 'assign');
1013 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1014 $o .= $this->output
->pix_icon('t/switch_plus', $expandstr, null, $options);
1016 $jsparams = array($feedbackplugin->plugin
->get_subtype(),
1017 $feedbackplugin->plugin
->get_type(),
1018 $feedbackplugin->grade
->id
);
1019 $this->page
->requires
->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1021 $urlparams = array('id' => $feedbackplugin->coursemoduleid
,
1022 'gid'=>$feedbackplugin->grade
->id
,
1023 'plugin'=>$feedbackplugin->plugin
->get_type(),
1024 'action'=>'viewplugin' . $feedbackplugin->plugin
->get_subtype(),
1025 'returnaction'=>$feedbackplugin->returnaction
,
1026 'returnparams'=>http_build_query($feedbackplugin->returnparams
));
1027 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1028 $link .= '<noscript>';
1029 $link .= $this->output
->action_link($url, $icon);
1030 $link .= '</noscript>';
1032 $link .= $this->output
->spacer(array('width'=>15));
1035 $o .= $link . $summary;
1036 $o .= $this->output
->box_end();
1037 if ($showviewlink) {
1038 $o .= $this->output
->box_start('boxaligncenter hidefull full_' . $classsuffix);
1039 $classes = 'expandsummaryicon contract_' . $classsuffix;
1040 $o .= $this->output
->pix_icon('t/switch_minus',
1041 get_string('viewsummary', 'assign'),
1043 array('class'=>$classes));
1044 $o .= $feedbackplugin->plugin
->view($feedbackplugin->grade
);
1045 $o .= $this->output
->box_end();
1047 } else if ($feedbackplugin->view
== assign_feedback_plugin_feedback
::FULL
) {
1048 $o .= $this->output
->box_start('boxaligncenter feedbackfull');
1049 $o .= $feedbackplugin->plugin
->view($feedbackplugin->grade
);
1050 $o .= $this->output
->box_end();
1057 * Render a course index summary
1059 * @param assign_course_index_summary $indexsummary
1062 public function render_assign_course_index_summary(assign_course_index_summary
$indexsummary) {
1065 $strplural = get_string('modulenameplural', 'assign');
1066 $strsectionname = $indexsummary->courseformatname
;
1067 $strduedate = get_string('duedate', 'assign');
1068 $strsubmission = get_string('submission', 'assign');
1069 $strgrade = get_string('grade');
1071 $table = new html_table();
1072 if ($indexsummary->usesections
) {
1073 $table->head
= array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
1074 $table->align
= array ('left', 'left', 'center', 'right', 'right');
1076 $table->head
= array ($strplural, $strduedate, $strsubmission, $strgrade);
1077 $table->align
= array ('left', 'left', 'center', 'right');
1079 $table->data
= array();
1081 $currentsection = '';
1082 foreach ($indexsummary->assignments
as $info) {
1083 $params = array('id' => $info['cmid']);
1084 $link = html_writer
::link(new moodle_url('/mod/assign/view.php', $params),
1086 $due = $info['timedue'] ?
userdate($info['timedue']) : '-';
1089 if ($indexsummary->usesections
) {
1090 if ($info['sectionname'] !== $currentsection) {
1091 if ($info['sectionname']) {
1092 $printsection = $info['sectionname'];
1094 if ($currentsection !== '') {
1095 $table->data
[] = 'hr';
1097 $currentsection = $info['sectionname'];
1101 if ($indexsummary->usesections
) {
1102 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
1104 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
1106 $table->data
[] = $row;
1109 $o .= html_writer
::table($table);
1117 * Internal function - creates htmls structure suitable for YUI tree.
1119 * @param assign_files $tree
1123 protected function htmllize_tree(assign_files
$tree, $dir) {
1125 $yuiconfig = array();
1126 $yuiconfig['type'] = 'html';
1128 if (empty($dir['subdirs']) and empty($dir['files'])) {
1133 foreach ($dir['subdirs'] as $subdir) {
1134 $image = $this->output
->pix_icon(file_folder_icon(),
1137 array('class'=>'icon'));
1138 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1139 '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
1140 $this->htmllize_tree($tree, $subdir) .
1144 foreach ($dir['files'] as $file) {
1145 $filename = $file->get_filename();
1146 if ($CFG->enableplagiarism
) {
1147 require_once($CFG->libdir
.'/plagiarismlib.php');
1148 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(),
1150 'cmid'=>$tree->cm
->id
,
1151 'course'=>$tree->course
));
1153 $plagiarismlinks = '';
1155 $image = $this->output
->pix_icon(file_file_icon($file),
1158 array('class'=>'icon'));
1159 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1160 '<div>' . $image . ' ' .
1161 $file->fileurl
. ' ' .
1163 $file->portfoliobutton
. '</div>' .
1173 * Helper method dealing with the fact we can not just fetch the output of flexible_table
1175 * @param flexible_table $table The table to render
1176 * @param int $rowsperpage How many assignments to render in a page
1177 * @param bool $displaylinks - Whether to render links in the table
1178 * (e.g. downloads would not enable this)
1179 * @return string HTML
1181 protected function flexible_table(flexible_table
$table, $rowsperpage, $displaylinks) {
1185 $table->out($rowsperpage, $displaylinks);
1186 $o = ob_get_contents();
1193 * Helper method dealing with the fact we can not just fetch the output of moodleforms
1195 * @param moodleform $mform
1196 * @return string HTML
1198 protected function moodleform(moodleform
$mform) {
1203 $o = ob_get_contents();