Merge branch 'MDL-58983-master' of git://github.com/damyon/moodle
[moodle.git] / mod / assign / renderer.php
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.
13 //
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
19  *
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
23  */
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.
33  *
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
37  */
38 class mod_assign_renderer extends plugin_renderer_base {
40     /**
41      * Rendering assignment files
42      *
43      * @param context $context
44      * @param int $userid
45      * @param string $filearea
46      * @param string $component
47      * @return string
48      */
49     public function assign_files(context $context, $userid, $filearea, $component) {
50         return $this->render(new assign_files($context, $userid, $filearea, $component));
51     }
53     /**
54      * Rendering assignment files
55      *
56      * @param assign_files $tree
57      * @return string
58      */
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;
68         }
69         return $html;
70     }
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
75      *
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
80      */
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;
87     }
89     /**
90      * Render a grading message notification
91      * @param assign_gradingmessage $result The result to render
92      * @return string
93      */
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;
98         }
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;
107     }
109     /**
110      * Render the generic form
111      * @param assign_form $form The form to render
112      * @return string
113      */
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());
118         }
119         $o .= $this->output->box_start('boxaligncenter ' . $form->classname);
120         $o .= $this->moodleform($form->form);
121         $o .= $this->output->box_end();
122         return $o;
123     }
125     /**
126      * Render the user summary
127      *
128      * @param assign_user_summary $summary The user summary to render
129      * @return string
130      */
131     public function render_assign_user_summary(assign_user_summary $summary) {
132         $o = '';
133         $supendedclass = '';
134         $suspendedicon = '';
136         if (!$summary->user) {
137             return;
138         }
140         if ($summary->suspendeduser) {
141             $supendedclass = ' usersuspended';
142             $suspendedstring = get_string('userenrolmentsuspended', 'grades');
143             $suspendedicon = ' ' . $this->pix_icon('i/enrolmentsuspended', $suspendedstring);
144         }
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;
158             }
159             if (count($extrainfo)) {
160                 $fullname .= ' (' . implode(', ', $extrainfo) . ')';
161             }
162             $fullname .= $suspendedicon;
163             $o .= $this->output->action_link($url, $fullname);
164         }
165         $o .= $this->output->box_end();
166         $o .= $this->output->container_end();
168         return $o;
169     }
171     /**
172      * Render the submit for grading page
173      *
174      * @param assign_submit_for_grading_page $page
175      * @return string
176      */
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('submitassignment', 'assign'), 3);
182         $o .= $this->output->spacer(array('height'=>30));
184         $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
185         if (count($page->notifications)) {
186             // At least one of the submission plugins is not ready for submission.
188             $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
190             foreach ($page->notifications as $notification) {
191                 $o .= $this->output->notification($notification);
192             }
194             $o .= $this->output->continue_button($cancelurl);
195         } else {
196             // All submission plugins ready - show the confirmation form.
197             $o .= $this->output->box_start('generalbox submitconfirm');
198             $o .= $this->moodleform($page->confirmform);
199             $o .= $this->output->box_end();
200         }
201         $o .= $this->output->container_end();
203         return $o;
204     }
206     /**
207      * Page is done - render the footer.
208      *
209      * @return void
210      */
211     public function render_footer() {
212         return $this->output->footer();
213     }
215     /**
216      * Render the header.
217      *
218      * @param assign_header $header
219      * @return string
220      */
221     public function render_assign_header(assign_header $header) {
222         $o = '';
224         if ($header->subpage) {
225             $this->page->navbar->add($header->subpage);
226         }
228         $this->page->set_title(get_string('pluginname', 'assign'));
229         $this->page->set_heading($this->page->course->fullname);
231         $o .= $this->output->header();
232         $heading = format_string($header->assign->name, false, array('context' => $header->context));
233         $o .= $this->output->heading($heading);
234         if ($header->preface) {
235             $o .= $header->preface;
236         }
238         if ($header->showintro) {
239             $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
240             $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
241             $o .= $header->postfix;
242             $o .= $this->output->box_end();
243         }
245         return $o;
246     }
248     /**
249      * Render the header for an individual plugin.
250      *
251      * @param assign_plugin_header $header
252      * @return string
253      */
254     public function render_assign_plugin_header(assign_plugin_header $header) {
255         $o = $header->plugin->view_header();
256         return $o;
257     }
259     /**
260      * Render a table containing the current status of the grading process.
261      *
262      * @param assign_grading_summary $summary
263      * @return string
264      */
265     public function render_assign_grading_summary(assign_grading_summary $summary) {
266         // Create a table for the data.
267         $o = '';
268         $o .= $this->output->container_start('gradingsummary');
269         $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
270         $o .= $this->output->box_start('boxaligncenter gradingsummarytable');
271         $t = new html_table();
273         // Status.
274         if ($summary->teamsubmission) {
275             if ($summary->warnofungroupedusers) {
276                 $o .= $this->output->notification(get_string('ungroupedusers', 'assign'));
277             }
279             $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
280                                        $summary->participantcount);
281         } else {
282             $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
283                                        $summary->participantcount);
284         }
286         // Drafts count and dont show drafts count when using offline assignment.
287         if ($summary->submissiondraftsenabled && $summary->submissionsenabled) {
288             $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
289                                        $summary->submissiondraftscount);
290         }
292         // Submitted for grading.
293         if ($summary->submissionsenabled) {
294             $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
295                                        $summary->submissionssubmittedcount);
296             if (!$summary->teamsubmission) {
297                 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
298                                            $summary->submissionsneedgradingcount);
299             }
300         }
302         $time = time();
303         if ($summary->duedate) {
304             // Due date.
305             $duedate = $summary->duedate;
306             $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
307                                        userdate($duedate));
309             // Time remaining.
310             $due = '';
311             if ($duedate - $time <= 0) {
312                 $due = get_string('assignmentisdue', 'assign');
313             } else {
314                 $due = format_time($duedate - $time);
315             }
316             $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
318             if ($duedate < $time) {
319                 $cutoffdate = $summary->cutoffdate;
320                 if ($cutoffdate) {
321                     if ($cutoffdate > $time) {
322                         $late = get_string('latesubmissionsaccepted', 'assign', userdate($summary->cutoffdate));
323                     } else {
324                         $late = get_string('nomoresubmissionsaccepted', 'assign');
325                     }
326                     $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
327                 }
328             }
330         }
332         // All done - write the table.
333         $o .= html_writer::table($t);
334         $o .= $this->output->box_end();
336         // Link to the grading page.
337         $o .= '<center>';
338         $o .= $this->output->container_start('submissionlinks');
339         $urlparams = array('id' => $summary->coursemoduleid, 'action' => 'grading');
340         $url = new moodle_url('/mod/assign/view.php', $urlparams);
341         $o .= '<a href="' . $url . '" class="btn btn-secondary">' . get_string('viewgrading', 'mod_assign') . '</a> ';
342         if ($summary->cangrade) {
343             $urlparams = array('id' => $summary->coursemoduleid, 'action' => 'grader');
344             $url = new moodle_url('/mod/assign/view.php', $urlparams);
345             $o .= '<a href="' . $url . '" class="btn btn-primary">' . get_string('grade') . '</a>';
346         }
347         $o .= $this->output->container_end();
349         // Close the container and insert a spacer.
350         $o .= $this->output->container_end();
351         $o .= '</center>';
353         return $o;
354     }
356     /**
357      * Render a table containing all the current grades and feedback.
358      *
359      * @param assign_feedback_status $status
360      * @return string
361      */
362     public function render_assign_feedback_status(assign_feedback_status $status) {
363         global $DB, $CFG;
364         $o = '';
366         $o .= $this->output->container_start('feedback');
367         $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
368         $o .= $this->output->box_start('boxaligncenter feedbacktable');
369         $t = new html_table();
371         // Grade.
372         if (isset($status->gradefordisplay)) {
373             $row = new html_table_row();
374             $cell1 = new html_table_cell(get_string('grade'));
375             $cell2 = new html_table_cell($status->gradefordisplay);
376             $row->cells = array($cell1, $cell2);
377             $t->data[] = $row;
379             // Grade date.
380             $row = new html_table_row();
381             $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
382             $cell2 = new html_table_cell(userdate($status->gradeddate));
383             $row->cells = array($cell1, $cell2);
384             $t->data[] = $row;
385         }
387         if ($status->grader) {
388             // Grader.
389             $row = new html_table_row();
390             $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
391             $userdescription = $this->output->user_picture($status->grader) .
392                                $this->output->spacer(array('width'=>30)) .
393                                fullname($status->grader, $status->canviewfullnames);
394             $cell2 = new html_table_cell($userdescription);
395             $row->cells = array($cell1, $cell2);
396             $t->data[] = $row;
397         }
399         foreach ($status->feedbackplugins as $plugin) {
400             if ($plugin->is_enabled() &&
401                     $plugin->is_visible() &&
402                     $plugin->has_user_summary() &&
403                     !empty($status->grade) &&
404                     !$plugin->is_empty($status->grade)) {
406                 $row = new html_table_row();
407                 $cell1 = new html_table_cell($plugin->get_name());
408                 $displaymode = assign_feedback_plugin_feedback::SUMMARY;
409                 $pluginfeedback = new assign_feedback_plugin_feedback($plugin,
410                                                                       $status->grade,
411                                                                       $displaymode,
412                                                                       $status->coursemoduleid,
413                                                                       $status->returnaction,
414                                                                       $status->returnparams);
415                 $cell2 = new html_table_cell($this->render($pluginfeedback));
416                 $row->cells = array($cell1, $cell2);
417                 $t->data[] = $row;
418             }
419         }
421         $o .= html_writer::table($t);
422         $o .= $this->output->box_end();
424         $o .= $this->output->container_end();
425         return $o;
426     }
428     /**
429      * Render a compact view of the current status of the submission.
430      *
431      * @param assign_submission_status_compact $status
432      * @return string
433      */
434     public function render_assign_submission_status_compact(assign_submission_status_compact $status) {
435         $o = '';
436         $o .= $this->output->container_start('submissionstatustable');
437         $o .= $this->output->heading(get_string('submission', 'assign'), 3);
438         $time = time();
440         if ($status->teamsubmissionenabled) {
441             $group = $status->submissiongroup;
442             if ($group) {
443                 $team = format_string($group->name, false, $status->context);
444             } else if ($status->preventsubmissionnotingroup) {
445                 if (count($status->usergroups) == 0) {
446                     $team = '<span class="alert alert-error">' . get_string('noteam', 'assign') . '</span>';
447                 } else if (count($status->usergroups) > 1) {
448                     $team = '<span class="alert alert-error">' . get_string('multipleteams', 'assign') . '</span>';
449                 }
450             } else {
451                 $team = get_string('defaultteam', 'assign');
452             }
453             $o .= $this->output->container(get_string('teamname', 'assign', $team), 'teamname');
454         }
456         if (!$status->teamsubmissionenabled) {
457             if ($status->submission && $status->submission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
458                 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign');
459                 $o .= $this->output->container($statusstr, 'submissionstatus' . $status->submission->status);
460             } else {
461                 if (!$status->submissionsenabled) {
462                     $o .= $this->output->container(get_string('noonlinesubmissions', 'assign'), 'submissionstatus');
463                 } else {
464                     $o .= $this->output->container(get_string('noattempt', 'assign'), 'submissionstatus');
465                 }
466             }
467         } else {
468             $group = $status->submissiongroup;
469             if (!$group && $status->preventsubmissionnotingroup) {
470                 $o .= $this->output->container(get_string('nosubmission', 'assign'), 'submissionstatus');
471             } else if ($status->teamsubmission && $status->teamsubmission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
472                 $teamstatus = $status->teamsubmission->status;
473                 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
474                 $groupid = 0;
475                 if ($status->submissiongroup) {
476                     $groupid = $status->submissiongroup->id;
477                 }
479                 $members = $status->submissiongroupmemberswhoneedtosubmit;
480                 $userslist = array();
481                 foreach ($members as $member) {
482                     $urlparams = array('id' => $member->id, 'course' => $status->courseid);
483                     $url = new moodle_url('/user/view.php', $urlparams);
484                     if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
485                         $userslist[] = $member->alias;
486                     } else {
487                         $fullname = fullname($member, $status->canviewfullnames);
488                         $userslist[] = $this->output->action_link($url, $fullname);
489                     }
490                 }
491                 if (count($userslist) > 0) {
492                     $userstr = join(', ', $userslist);
493                     $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
494                     $submissionsummary .= $this->output->container($formatteduserstr);
495                 }
496                 $o .= $this->output->container($submissionsummary, 'submissionstatus' . $status->teamsubmission->status);
497             } else {
498                 if (!$status->submissionsenabled) {
499                     $o .= $this->output->container(get_string('noonlinesubmissions', 'assign'), 'submissionstatus');
500                 } else {
501                     $o .= $this->output->container(get_string('nosubmission', 'assign'), 'submissionstatus');
502                 }
503             }
504         }
506         // Is locked?
507         if ($status->locked) {
508             $o .= $this->output->container(get_string('submissionslocked', 'assign'), 'submissionlocked');
509         }
511         // Grading status.
512         $statusstr = '';
513         $classname = 'gradingstatus';
514         if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
515             $status->gradingstatus == ASSIGN_GRADING_STATUS_NOT_GRADED) {
516             $statusstr = get_string($status->gradingstatus, 'assign');
517         } else {
518             $gradingstatus = 'markingworkflowstate' . $status->gradingstatus;
519             $statusstr = get_string($gradingstatus, 'assign');
520         }
521         if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
522             $status->gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
523             $classname = 'submissiongraded';
524         } else {
525             $classname = 'submissionnotgraded';
526         }
527         $o .= $this->output->container($statusstr, $classname);
529         $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
530         $duedate = $status->duedate;
531         if ($duedate > 0) {
533             if ($status->extensionduedate) {
534                 // Extension date.
535                 $duedate = $status->extensionduedate;
536             }
538             // Time remaining.
539             $classname = 'timeremaining';
540             if ($duedate - $time <= 0) {
541                 if (!$submission ||
542                         $submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
543                     if ($status->submissionsenabled) {
544                         $remaining = get_string('overdue', 'assign', format_time($time - $duedate));
545                         $classname = 'overdue';
546                     } else {
547                         $remaining = get_string('duedatereached', 'assign');
548                     }
549                 } else {
550                     if ($submission->timemodified > $duedate) {
551                         $remaining = get_string('submittedlate',
552                                               'assign',
553                                               format_time($submission->timemodified - $duedate));
554                         $classname = 'latesubmission';
555                     } else {
556                         $remaining = get_string('submittedearly',
557                                                'assign',
558                                                format_time($submission->timemodified - $duedate));
559                         $classname = 'earlysubmission';
560                     }
561                 }
562             } else {
563                 $remaining = get_string('paramtimeremaining', 'assign', format_time($duedate - $time));
564             }
565             $o .= $this->output->container($remaining, $classname);
566         }
568         // Show graders whether this submission is editable by students.
569         if ($status->view == assign_submission_status::GRADER_VIEW) {
570             if ($status->canedit) {
571                 $o .= $this->output->container(get_string('submissioneditable', 'assign'), 'submissioneditable');
572             } else {
573                 $o .= $this->output->container(get_string('submissionnoteditable', 'assign'), 'submissionnoteditable');
574             }
575         }
577         // Grading criteria preview.
578         if (!empty($status->gradingcontrollerpreview)) {
579             $o .= $this->output->container($status->gradingcontrollerpreview, 'gradingmethodpreview');
580         }
582         if ($submission) {
584             if (!$status->teamsubmission || $status->submissiongroup != false || !$status->preventsubmissionnotingroup) {
585                 foreach ($status->submissionplugins as $plugin) {
586                     $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
587                     if ($plugin->is_enabled() &&
588                         $plugin->is_visible() &&
589                         $plugin->has_user_summary() &&
590                         $pluginshowsummary
591                     ) {
593                         $displaymode = assign_submission_plugin_submission::SUMMARY;
594                         $pluginsubmission = new assign_submission_plugin_submission($plugin,
595                             $submission,
596                             $displaymode,
597                             $status->coursemoduleid,
598                             $status->returnaction,
599                             $status->returnparams);
600                         $plugincomponent = $plugin->get_subtype() . '_' . $plugin->get_type();
601                         $o .= $this->output->container($this->render($pluginsubmission), 'assignsubmission ' . $plugincomponent);
602                     }
603                 }
604             }
605         }
607         $o .= $this->output->container_end();
608         return $o;
609     }
611     /**
612      * Render a table containing the current status of the submission.
613      *
614      * @param assign_submission_status $status
615      * @return string
616      */
617     public function render_assign_submission_status(assign_submission_status $status) {
618         $o = '';
619         $o .= $this->output->container_start('submissionstatustable');
620         $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
621         $time = time();
623         if ($status->allowsubmissionsfromdate &&
624                 $time <= $status->allowsubmissionsfromdate) {
625             $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
626             if ($status->alwaysshowdescription) {
627                 $date = userdate($status->allowsubmissionsfromdate);
628                 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
629             } else {
630                 $date = userdate($status->allowsubmissionsfromdate);
631                 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
632             }
633             $o .= $this->output->box_end();
634         }
635         $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
637         $t = new html_table();
639         $warningmsg = '';
640         if ($status->teamsubmissionenabled) {
641             $row = new html_table_row();
642             $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
643             $group = $status->submissiongroup;
644             if ($group) {
645                 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
646             } else if ($status->preventsubmissionnotingroup) {
647                 if (count($status->usergroups) == 0) {
648                     $notification = new \core\output\notification(get_string('noteam', 'assign'), 'error');
649                     $notification->set_show_closebutton(false);
650                     $cell2 = new html_table_cell(
651                         $this->output->render($notification)
652                     );
653                     $warningmsg = $this->output->notification(get_string('noteam_desc', 'assign'), 'error');
654                 } else if (count($status->usergroups) > 1) {
655                     $notification = new \core\output\notification(get_string('multipleteams', 'assign'), 'error');
656                     $notification->set_show_closebutton(false);
657                     $cell2 = new html_table_cell(
658                         $this->output->render($notification)
659                     );
660                     $warningmsg = $this->output->notification(get_string('multipleteams_desc', 'assign'), 'error');
661                 }
662             } else {
663                 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
664             }
665             $row->cells = array($cell1, $cell2);
666             $t->data[] = $row;
667         }
669         if ($status->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
670             $currentattempt = 1;
671             if (!$status->teamsubmissionenabled) {
672                 if ($status->submission) {
673                     $currentattempt = $status->submission->attemptnumber + 1;
674                 }
675             } else {
676                 if ($status->teamsubmission) {
677                     $currentattempt = $status->teamsubmission->attemptnumber + 1;
678                 }
679             }
681             $row = new html_table_row();
682             $cell1 = new html_table_cell(get_string('attemptnumber', 'assign'));
683             $maxattempts = $status->maxattempts;
684             if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) {
685                 $message = get_string('currentattempt', 'assign', $currentattempt);
686             } else {
687                 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt,
688                                                                           'maxattempts'=>$maxattempts));
689             }
690             $cell2 = new html_table_cell($message);
691             $row->cells = array($cell1, $cell2);
692             $t->data[] = $row;
693         }
695         $row = new html_table_row();
696         $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
697         if (!$status->teamsubmissionenabled) {
698             if ($status->submission && $status->submission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
699                 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign');
700                 $cell2 = new html_table_cell($statusstr);
701                 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
702             } else {
703                 if (!$status->submissionsenabled) {
704                     $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
705                 } else {
706                     $cell2 = new html_table_cell(get_string('noattempt', 'assign'));
707                 }
708             }
709             $row->cells = array($cell1, $cell2);
710             $t->data[] = $row;
711         } else {
712             $row = new html_table_row();
713             $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
714             $group = $status->submissiongroup;
715             if (!$group && $status->preventsubmissionnotingroup) {
716                 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
717             } else if ($status->teamsubmission && $status->teamsubmission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
718                 $teamstatus = $status->teamsubmission->status;
719                 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
720                 $groupid = 0;
721                 if ($status->submissiongroup) {
722                     $groupid = $status->submissiongroup->id;
723                 }
725                 $members = $status->submissiongroupmemberswhoneedtosubmit;
726                 $userslist = array();
727                 foreach ($members as $member) {
728                     $urlparams = array('id' => $member->id, 'course'=>$status->courseid);
729                     $url = new moodle_url('/user/view.php', $urlparams);
730                     if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
731                         $userslist[] = $member->alias;
732                     } else {
733                         $fullname = fullname($member, $status->canviewfullnames);
734                         $userslist[] = $this->output->action_link($url, $fullname);
735                     }
736                 }
737                 if (count($userslist) > 0) {
738                     $userstr = join(', ', $userslist);
739                     $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
740                     $submissionsummary .= $this->output->container($formatteduserstr);
741                 }
743                 $cell2 = new html_table_cell($submissionsummary);
744                 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
745             } else {
746                 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
747                 if (!$status->submissionsenabled) {
748                     $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
749                 } else {
750                     $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
751                 }
752             }
753             $row->cells = array($cell1, $cell2);
754             $t->data[] = $row;
755         }
757         // Is locked?
758         if ($status->locked) {
759             $row = new html_table_row();
760             $cell1 = new html_table_cell();
761             $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
762             $cell2->attributes = array('class'=>'submissionlocked');
763             $row->cells = array($cell1, $cell2);
764             $t->data[] = $row;
765         }
767         // Grading status.
768         $row = new html_table_row();
769         $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
771         if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
772             $status->gradingstatus == ASSIGN_GRADING_STATUS_NOT_GRADED) {
773             $cell2 = new html_table_cell(get_string($status->gradingstatus, 'assign'));
774         } else {
775             $gradingstatus = 'markingworkflowstate' . $status->gradingstatus;
776             $cell2 = new html_table_cell(get_string($gradingstatus, 'assign'));
777         }
778         if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED ||
779             $status->gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) {
780             $cell2->attributes = array('class' => 'submissiongraded');
781         } else {
782             $cell2->attributes = array('class' => 'submissionnotgraded');
783         }
784         $row->cells = array($cell1, $cell2);
785         $t->data[] = $row;
787         $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
788         $duedate = $status->duedate;
789         if ($duedate > 0) {
790             // Due date.
791             $row = new html_table_row();
792             $cell1 = new html_table_cell(get_string('duedate', 'assign'));
793             $cell2 = new html_table_cell(userdate($duedate));
794             $row->cells = array($cell1, $cell2);
795             $t->data[] = $row;
797             if ($status->view == assign_submission_status::GRADER_VIEW) {
798                 if ($status->cutoffdate) {
799                     // Cut off date.
800                     $row = new html_table_row();
801                     $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
802                     $cell2 = new html_table_cell(userdate($status->cutoffdate));
803                     $row->cells = array($cell1, $cell2);
804                     $t->data[] = $row;
805                 }
806             }
808             if ($status->extensionduedate) {
809                 // Extension date.
810                 $row = new html_table_row();
811                 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
812                 $cell2 = new html_table_cell(userdate($status->extensionduedate));
813                 $row->cells = array($cell1, $cell2);
814                 $t->data[] = $row;
815                 $duedate = $status->extensionduedate;
816             }
818             // Time remaining.
819             $row = new html_table_row();
820             $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
821             if ($duedate - $time <= 0) {
822                 if (!$submission ||
823                         $submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
824                     if ($status->submissionsenabled) {
825                         $overduestr = get_string('overdue', 'assign', format_time($time - $duedate));
826                         $cell2 = new html_table_cell($overduestr);
827                         $cell2->attributes = array('class'=>'overdue');
828                     } else {
829                         $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
830                     }
831                 } else {
832                     if ($submission->timemodified > $duedate) {
833                         $latestr = get_string('submittedlate',
834                                               'assign',
835                                               format_time($submission->timemodified - $duedate));
836                         $cell2 = new html_table_cell($latestr);
837                         $cell2->attributes = array('class'=>'latesubmission');
838                     } else {
839                         $earlystr = get_string('submittedearly',
840                                                'assign',
841                                                format_time($submission->timemodified - $duedate));
842                         $cell2 = new html_table_cell($earlystr);
843                         $cell2->attributes = array('class'=>'earlysubmission');
844                     }
845                 }
846             } else {
847                 $cell2 = new html_table_cell(format_time($duedate - $time));
848             }
849             $row->cells = array($cell1, $cell2);
850             $t->data[] = $row;
851         }
853         // Show graders whether this submission is editable by students.
854         if ($status->view == assign_submission_status::GRADER_VIEW) {
855             $row = new html_table_row();
856             $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
857             if ($status->canedit) {
858                 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
859                 $cell2->attributes = array('class'=>'submissioneditable');
860             } else {
861                 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
862                 $cell2->attributes = array('class'=>'submissionnoteditable');
863             }
864             $row->cells = array($cell1, $cell2);
865             $t->data[] = $row;
866         }
868         // Grading criteria preview.
869         if (!empty($status->gradingcontrollerpreview)) {
870             $row = new html_table_row();
871             $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
872             $cell2 = new html_table_cell($status->gradingcontrollerpreview);
873             $row->cells = array($cell1, $cell2);
874             $t->data[] = $row;
875         }
877         // Last modified.
878         if ($submission) {
879             $row = new html_table_row();
880             $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
882             if ($submission->status != ASSIGN_SUBMISSION_STATUS_NEW) {
883                 $cell2 = new html_table_cell(userdate($submission->timemodified));
884             } else {
885                 $cell2 = new html_table_cell('-');
886             }
888             $row->cells = array($cell1, $cell2);
889             $t->data[] = $row;
891             if (!$status->teamsubmission || $status->submissiongroup != false || !$status->preventsubmissionnotingroup) {
892                 foreach ($status->submissionplugins as $plugin) {
893                     $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
894                     if ($plugin->is_enabled() &&
895                         $plugin->is_visible() &&
896                         $plugin->has_user_summary() &&
897                         $pluginshowsummary
898                     ) {
900                         $row = new html_table_row();
901                         $cell1 = new html_table_cell($plugin->get_name());
902                         $displaymode = assign_submission_plugin_submission::SUMMARY;
903                         $pluginsubmission = new assign_submission_plugin_submission($plugin,
904                             $submission,
905                             $displaymode,
906                             $status->coursemoduleid,
907                             $status->returnaction,
908                             $status->returnparams);
909                         $cell2 = new html_table_cell($this->render($pluginsubmission));
910                         $row->cells = array($cell1, $cell2);
911                         $t->data[] = $row;
912                     }
913                 }
914             }
915         }
917         $o .= $warningmsg;
918         $o .= html_writer::table($t);
919         $o .= $this->output->box_end();
921         // Links.
922         if ($status->view == assign_submission_status::STUDENT_VIEW) {
923             if ($status->canedit) {
924                 if (!$submission || $submission->status == ASSIGN_SUBMISSION_STATUS_NEW) {
925                     $o .= $this->output->box_start('generalbox submissionaction');
926                     $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
927                     $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
928                                                        get_string('addsubmission', 'assign'), 'get');
929                     $o .= $this->output->box_start('boxaligncenter submithelp');
930                     $o .= get_string('addsubmission_help', 'assign');
931                     $o .= $this->output->box_end();
932                     $o .= $this->output->box_end();
933                 } else if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
934                     $o .= $this->output->box_start('generalbox submissionaction');
935                     $urlparams = array('id' => $status->coursemoduleid,
936                                        'action' => 'editprevioussubmission',
937                                        'sesskey'=>sesskey());
938                     $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
939                                                        get_string('addnewattemptfromprevious', 'assign'), 'get');
940                     $o .= $this->output->box_start('boxaligncenter submithelp');
941                     $o .= get_string('addnewattemptfromprevious_help', 'assign');
942                     $o .= $this->output->box_end();
943                     $o .= $this->output->box_end();
944                     $o .= $this->output->box_start('generalbox submissionaction');
945                     $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
946                     $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
947                                                        get_string('addnewattempt', 'assign'), 'get');
948                     $o .= $this->output->box_start('boxaligncenter submithelp');
949                     $o .= get_string('addnewattempt_help', 'assign');
950                     $o .= $this->output->box_end();
951                     $o .= $this->output->box_end();
952                 } else {
953                     $o .= $this->output->box_start('generalbox submissionaction');
954                     $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
955                     $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
956                                                        get_string('editsubmission', 'assign'), 'get');
957                     $o .= $this->output->box_start('boxaligncenter submithelp');
958                     $o .= get_string('editsubmission_help', 'assign');
959                     $o .= $this->output->box_end();
960                     $o .= $this->output->box_end();
961                 }
962             }
964             if ($status->cansubmit) {
965                 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
966                 $o .= $this->output->box_start('generalbox submissionaction');
967                 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
968                                                    get_string('submitassignment', 'assign'), 'get');
969                 $o .= $this->output->box_start('boxaligncenter submithelp');
970                 $o .= get_string('submitassignment_help', 'assign');
971                 $o .= $this->output->box_end();
972                 $o .= $this->output->box_end();
973             }
974         }
976         $o .= $this->output->container_end();
977         return $o;
978     }
980     /**
981      * Output the attempt history chooser for this assignment
982      *
983      * @param assign_attempt_history_chooser $history
984      * @return string
985      */
986     public function render_assign_attempt_history_chooser(assign_attempt_history_chooser $history) {
987         $o = '';
989         $context = $history->export_for_template($this);
990         $o .= $this->render_from_template('mod_assign/attempt_history_chooser', $context);
992         return $o;
993     }
995     /**
996      * Output the attempt history for this assignment
997      *
998      * @param assign_attempt_history $history
999      * @return string
1000      */
1001     public function render_assign_attempt_history(assign_attempt_history $history) {
1002         $o = '';
1004         $submittedstr = get_string('submitted', 'assign');
1005         $gradestr = get_string('grade');
1006         $gradedonstr = get_string('gradedon', 'assign');
1007         $gradedbystr = get_string('gradedby', 'assign');
1009         // Don't show the last one because it is the current submission.
1010         array_pop($history->submissions);
1012         // Show newest to oldest.
1013         $history->submissions = array_reverse($history->submissions);
1015         if (empty($history->submissions)) {
1016             return '';
1017         }
1019         $containerid = 'attempthistory' . uniqid();
1020         $o .= $this->output->heading(get_string('attempthistory', 'assign'), 3);
1021         $o .= $this->box_start('attempthistory', $containerid);
1023         foreach ($history->submissions as $i => $submission) {
1024             $grade = null;
1025             foreach ($history->grades as $onegrade) {
1026                 if ($onegrade->attemptnumber == $submission->attemptnumber) {
1027                     $grade = $onegrade;
1028                     break;
1029                 }
1030             }
1032             $editbtn = '';
1034             if ($submission) {
1035                 $submissionsummary = userdate($submission->timemodified);
1036             } else {
1037                 $submissionsummary = get_string('nosubmission', 'assign');
1038             }
1040             $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+1,
1041                                           'submissionsummary'=>$submissionsummary);
1042             $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4);
1044             $t = new html_table();
1046             if ($submission) {
1047                 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
1048                 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status, 'assign'));
1049                 $t->data[] = new html_table_row(array($cell1, $cell2));
1051                 foreach ($history->submissionplugins as $plugin) {
1052                     $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
1053                     if ($plugin->is_enabled() &&
1054                             $plugin->is_visible() &&
1055                             $plugin->has_user_summary() &&
1056                             $pluginshowsummary) {
1058                         $cell1 = new html_table_cell($plugin->get_name());
1059                         $pluginsubmission = new assign_submission_plugin_submission($plugin,
1060                                                                                     $submission,
1061                                                                                     assign_submission_plugin_submission::SUMMARY,
1062                                                                                     $history->coursemoduleid,
1063                                                                                     $history->returnaction,
1064                                                                                     $history->returnparams);
1065                         $cell2 = new html_table_cell($this->render($pluginsubmission));
1067                         $t->data[] = new html_table_row(array($cell1, $cell2));
1068                     }
1069                 }
1070             }
1072             if ($grade) {
1073                 // Heading 'feedback'.
1074                 $title = get_string('feedback', 'assign', $i);
1075                 $title .= $this->output->spacer(array('width'=>10));
1076                 if ($history->cangrade) {
1077                     // Edit previous feedback.
1078                     $returnparams = http_build_query($history->returnparams);
1079                     $urlparams = array('id' => $history->coursemoduleid,
1080                                    'rownum'=>$history->rownum,
1081                                    'useridlistid'=>$history->useridlistid,
1082                                    'attemptnumber'=>$grade->attemptnumber,
1083                                    'action'=>'grade',
1084                                    'returnaction'=>$history->returnaction,
1085                                    'returnparams'=>$returnparams);
1086                     $url = new moodle_url('/mod/assign/view.php', $urlparams);
1087                     $icon = new pix_icon('gradefeedback',
1088                                             get_string('editattemptfeedback', 'assign', $grade->attemptnumber+1),
1089                                             'mod_assign');
1090                     $title .= $this->output->action_icon($url, $icon);
1091                 }
1092                 $cell = new html_table_cell($title);
1093                 $cell->attributes['class'] = 'feedbacktitle';
1094                 $cell->colspan = 2;
1095                 $t->data[] = new html_table_row(array($cell));
1097                 // Grade.
1098                 $cell1 = new html_table_cell($gradestr);
1099                 $cell2 = $grade->gradefordisplay;
1100                 $t->data[] = new html_table_row(array($cell1, $cell2));
1102                 // Graded on.
1103                 $cell1 = new html_table_cell($gradedonstr);
1104                 $cell2 = new html_table_cell(userdate($grade->timemodified));
1105                 $t->data[] = new html_table_row(array($cell1, $cell2));
1107                 // Graded by.
1108                 $cell1 = new html_table_cell($gradedbystr);
1109                 $cell2 = new html_table_cell($this->output->user_picture($grade->grader) .
1110                                              $this->output->spacer(array('width'=>30)) . fullname($grade->grader));
1111                 $t->data[] = new html_table_row(array($cell1, $cell2));
1113                 // Feedback from plugins.
1114                 foreach ($history->feedbackplugins as $plugin) {
1115                     if ($plugin->is_enabled() &&
1116                         $plugin->is_visible() &&
1117                         $plugin->has_user_summary() &&
1118                         !$plugin->is_empty($grade)) {
1120                         $cell1 = new html_table_cell($plugin->get_name());
1121                         $pluginfeedback = new assign_feedback_plugin_feedback(
1122                             $plugin, $grade, assign_feedback_plugin_feedback::SUMMARY, $history->coursemoduleid,
1123                             $history->returnaction, $history->returnparams
1124                         );
1125                         $cell2 = new html_table_cell($this->render($pluginfeedback));
1126                         $t->data[] = new html_table_row(array($cell1, $cell2));
1127                     }
1129                 }
1131             }
1133             $o .= html_writer::table($t);
1134         }
1135         $o .= $this->box_end();
1136         $jsparams = array($containerid);
1138         $this->page->requires->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history');
1140         return $o;
1141     }
1143     /**
1144      * Render a submission plugin submission
1145      *
1146      * @param assign_submission_plugin_submission $submissionplugin
1147      * @return string
1148      */
1149     public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
1150         $o = '';
1152         if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
1153             $showviewlink = false;
1154             $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission,
1155                                                                $showviewlink);
1157             $classsuffix = $submissionplugin->plugin->get_subtype() .
1158                            '_' .
1159                            $submissionplugin->plugin->get_type() .
1160                            '_' .
1161                            $submissionplugin->submission->id;
1163             $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1165             $link = '';
1166             if ($showviewlink) {
1167                 $previewstr = get_string('viewsubmission', 'assign');
1168                 $icon = $this->output->pix_icon('t/preview', $previewstr);
1170                 $expandstr = get_string('viewfull', 'assign');
1171                 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1172                 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
1174                 $jsparams = array($submissionplugin->plugin->get_subtype(),
1175                                   $submissionplugin->plugin->get_type(),
1176                                   $submissionplugin->submission->id);
1178                 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1180                 $action = 'viewplugin' . $submissionplugin->plugin->get_subtype();
1181                 $returnparams = http_build_query($submissionplugin->returnparams);
1182                 $link .= '<noscript>';
1183                 $urlparams = array('id' => $submissionplugin->coursemoduleid,
1184                                    'sid'=>$submissionplugin->submission->id,
1185                                    'plugin'=>$submissionplugin->plugin->get_type(),
1186                                    'action'=>$action,
1187                                    'returnaction'=>$submissionplugin->returnaction,
1188                                    'returnparams'=>$returnparams);
1189                 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1190                 $link .= $this->output->action_link($url, $icon);
1191                 $link .= '</noscript>';
1193                 $link .= $this->output->spacer(array('width'=>15));
1194             }
1196             $o .= $link . $summary;
1197             $o .= $this->output->box_end();
1198             if ($showviewlink) {
1199                 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
1200                 $classes = 'expandsummaryicon contract_' . $classsuffix;
1201                 $o .= $this->output->pix_icon('t/switch_minus',
1202                                               get_string('viewsummary', 'assign'),
1203                                               null,
1204                                               array('class'=>$classes));
1205                 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
1206                 $o .= $this->output->box_end();
1207             }
1208         } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
1209             $o .= $this->output->box_start('boxaligncenter submissionfull');
1210             $o .= $submissionplugin->plugin->view($submissionplugin->submission);
1211             $o .= $this->output->box_end();
1212         }
1214         return $o;
1215     }
1217     /**
1218      * Render the grading table.
1219      *
1220      * @param assign_grading_table $table
1221      * @return string
1222      */
1223     public function render_assign_grading_table(assign_grading_table $table) {
1224         $o = '';
1225         $o .= $this->output->box_start('boxaligncenter gradingtable');
1227         $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
1228         $this->page->requires->string_for_js('nousersselected', 'assign');
1229         $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
1230         $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
1231         $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
1232         $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
1233         $this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign');
1234         $this->page->requires->string_for_js('batchoperationconfirmdownloadselected', 'assign');
1235         $this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
1236         $this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
1237         $this->page->requires->string_for_js('editaction', 'assign');
1238         foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
1239             foreach ($operations as $operation => $description) {
1240                 $this->page->requires->string_for_js('batchoperationconfirm' . $operation,
1241                                                      'assignfeedback_' . $plugin);
1242             }
1243         }
1244         $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
1245         $o .= $this->output->box_end();
1247         return $o;
1248     }
1250     /**
1251      * Render a feedback plugin feedback
1252      *
1253      * @param assign_feedback_plugin_feedback $feedbackplugin
1254      * @return string
1255      */
1256     public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
1257         $o = '';
1259         if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
1260             $showviewlink = false;
1261             $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
1263             $classsuffix = $feedbackplugin->plugin->get_subtype() .
1264                            '_' .
1265                            $feedbackplugin->plugin->get_type() .
1266                            '_' .
1267                            $feedbackplugin->grade->id;
1268             $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1270             $link = '';
1271             if ($showviewlink) {
1272                 $previewstr = get_string('viewfeedback', 'assign');
1273                 $icon = $this->output->pix_icon('t/preview', $previewstr);
1275                 $expandstr = get_string('viewfull', 'assign');
1276                 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1277                 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
1279                 $jsparams = array($feedbackplugin->plugin->get_subtype(),
1280                                   $feedbackplugin->plugin->get_type(),
1281                                   $feedbackplugin->grade->id);
1282                 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1284                 $urlparams = array('id' => $feedbackplugin->coursemoduleid,
1285                                    'gid'=>$feedbackplugin->grade->id,
1286                                    'plugin'=>$feedbackplugin->plugin->get_type(),
1287                                    'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
1288                                    'returnaction'=>$feedbackplugin->returnaction,
1289                                    'returnparams'=>http_build_query($feedbackplugin->returnparams));
1290                 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1291                 $link .= '<noscript>';
1292                 $link .= $this->output->action_link($url, $icon);
1293                 $link .= '</noscript>';
1295                 $link .= $this->output->spacer(array('width'=>15));
1296             }
1298             $o .= $link . $summary;
1299             $o .= $this->output->box_end();
1300             if ($showviewlink) {
1301                 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
1302                 $classes = 'expandsummaryicon contract_' . $classsuffix;
1303                 $o .= $this->output->pix_icon('t/switch_minus',
1304                                               get_string('viewsummary', 'assign'),
1305                                               null,
1306                                               array('class'=>$classes));
1307                 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1308                 $o .= $this->output->box_end();
1309             }
1310         } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
1311             $o .= $this->output->box_start('boxaligncenter feedbackfull');
1312             $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1313             $o .= $this->output->box_end();
1314         }
1316         return $o;
1317     }
1319     /**
1320      * Render a course index summary
1321      *
1322      * @param assign_course_index_summary $indexsummary
1323      * @return string
1324      */
1325     public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
1326         $o = '';
1328         $strplural = get_string('modulenameplural', 'assign');
1329         $strsectionname  = $indexsummary->courseformatname;
1330         $strduedate = get_string('duedate', 'assign');
1331         $strsubmission = get_string('submission', 'assign');
1332         $strgrade = get_string('grade');
1334         $table = new html_table();
1335         if ($indexsummary->usesections) {
1336             $table->head  = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
1337             $table->align = array ('left', 'left', 'center', 'right', 'right');
1338         } else {
1339             $table->head  = array ($strplural, $strduedate, $strsubmission, $strgrade);
1340             $table->align = array ('left', 'left', 'center', 'right');
1341         }
1342         $table->data = array();
1344         $currentsection = '';
1345         foreach ($indexsummary->assignments as $info) {
1346             $params = array('id' => $info['cmid']);
1347             $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
1348                                       $info['cmname']);
1349             $due = $info['timedue'] ? userdate($info['timedue']) : '-';
1351             $printsection = '';
1352             if ($indexsummary->usesections) {
1353                 if ($info['sectionname'] !== $currentsection) {
1354                     if ($info['sectionname']) {
1355                         $printsection = $info['sectionname'];
1356                     }
1357                     if ($currentsection !== '') {
1358                         $table->data[] = 'hr';
1359                     }
1360                     $currentsection = $info['sectionname'];
1361                 }
1362             }
1364             if ($indexsummary->usesections) {
1365                 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
1366             } else {
1367                 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
1368             }
1369             $table->data[] = $row;
1370         }
1372         $o .= html_writer::table($table);
1374         return $o;
1375     }
1379     /**
1380      * Internal function - creates htmls structure suitable for YUI tree.
1381      *
1382      * @param assign_files $tree
1383      * @param array $dir
1384      * @return string
1385      */
1386     protected function htmllize_tree(assign_files $tree, $dir) {
1387         global $CFG;
1388         $yuiconfig = array();
1389         $yuiconfig['type'] = 'html';
1391         if (empty($dir['subdirs']) and empty($dir['files'])) {
1392             return '';
1393         }
1395         $result = '<ul>';
1396         foreach ($dir['subdirs'] as $subdir) {
1397             $image = $this->output->pix_icon(file_folder_icon(),
1398                                              $subdir['dirname'],
1399                                              'moodle',
1400                                              array('class'=>'icon'));
1401             $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1402                        '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
1403                        $this->htmllize_tree($tree, $subdir) .
1404                        '</li>';
1405         }
1407         foreach ($dir['files'] as $file) {
1408             $filename = $file->get_filename();
1409             if ($CFG->enableplagiarism) {
1410                 require_once($CFG->libdir.'/plagiarismlib.php');
1411                 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(),
1412                                                              'file'=>$file,
1413                                                              'cmid'=>$tree->cm->id,
1414                                                              'course'=>$tree->course));
1415             } else {
1416                 $plagiarismlinks = '';
1417             }
1418             $image = $this->output->pix_icon(file_file_icon($file),
1419                                              $filename,
1420                                              'moodle',
1421                                              array('class'=>'icon'));
1422             $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1423                        '<div>' . $image . ' ' .
1424                                  $file->fileurl . ' ' .
1425                                  $plagiarismlinks . ' ' .
1426                                  $file->portfoliobutton . '</div>' .
1427                        '</li>';
1428         }
1430         $result .= '</ul>';
1432         return $result;
1433     }
1435     /**
1436      * Helper method dealing with the fact we can not just fetch the output of flexible_table
1437      *
1438      * @param flexible_table $table The table to render
1439      * @param int $rowsperpage How many assignments to render in a page
1440      * @param bool $displaylinks - Whether to render links in the table
1441      *                             (e.g. downloads would not enable this)
1442      * @return string HTML
1443      */
1444     protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
1446         $o = '';
1447         ob_start();
1448         $table->out($rowsperpage, $displaylinks);
1449         $o = ob_get_contents();
1450         ob_end_clean();
1452         return $o;
1453     }
1455     /**
1456      * Helper method dealing with the fact we can not just fetch the output of moodleforms
1457      *
1458      * @param moodleform $mform
1459      * @return string HTML
1460      */
1461     protected function moodleform(moodleform $mform) {
1463         $o = '';
1464         ob_start();
1465         $mform->display();
1466         $o = ob_get_contents();
1467         ob_end_clean();
1469         return $o;
1470     }
1472     /**
1473      * Defer to template..
1474      *
1475      * @param grading_app $app - All the data to render the grading app.
1476      */
1477     public function render_grading_app(grading_app $app) {
1478         $context = $app->export_for_template($this);
1479         return $this->render_from_template('mod_assign/grading_app', $context);
1480     }