MDL-36908 Assignment: Additional fixes for preventing empty submissions
[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 /** Include locallib.php */
28 require_once($CFG->dirroot . '/mod/assign/locallib.php');
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 = 'assign_files_tree_'.uniqid();
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 error notification
91      * @param assign_quickgrading_result $result The result to render
92      * @return string
93      */
94     public function render_assign_quickgrading_result(assign_quickgrading_result $result) {
95         $url = new moodle_url('/mod/assign/view.php', array('id' => $result->coursemoduleid, 'action'=>'grading'));
97         $o = '';
98         $o .= $this->output->heading(get_string('quickgradingresult', 'assign'), 4);
99         $o .= $this->output->notification($result->message);
100         $o .= $this->output->continue_button($url);
101         return $o;
102     }
104     /**
105      * Render the generic form
106      * @param assign_form $form The form to render
107      * @return string
108      */
109     public function render_assign_form(assign_form $form) {
110         $o = '';
111         if ($form->jsinitfunction) {
112             $this->page->requires->js_init_call($form->jsinitfunction, array());
113         }
114         $o .= $this->output->box_start('boxaligncenter ' . $form->classname);
115         $o .= $this->moodleform($form->form);
116         $o .= $this->output->box_end();
117         return $o;
118     }
120     /**
121      * Render the user summary
122      *
123      * @param assign_user_summary $summary The user summary to render
124      * @return string
125      */
126     public function render_assign_user_summary(assign_user_summary $summary) {
127         $o = '';
129         if (!$summary->user) {
130             return;
131         }
132         $o .= $this->output->container_start('usersummary');
133         $o .= $this->output->box_start('boxaligncenter usersummarysection');
134         if ($summary->blindmarking) {
135             $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser;
136         } else {
137             $o .= $this->output->user_picture($summary->user);
138             $o .= $this->output->spacer(array('width'=>30));
139             $o .= $this->output->action_link(new moodle_url('/user/view.php',
140                                                             array('id' => $summary->user->id,
141                                                                   'course'=>$summary->courseid)),
142                                                                   fullname($summary->user, $summary->viewfullnames));
143         }
144         $o .= $this->output->box_end();
145         $o .= $this->output->container_end();
147         return $o;
148     }
150     /**
151      * Render the submit for grading page
152      *
153      * @param assign_submit_for_grading_page $page
154      * @return string
155      */
156     public function render_assign_submit_for_grading_page($page) {
157         $o = '';
159         $o .= $this->output->container_start('submitforgrading');
160         $o .= $this->output->heading(get_string('submitassignment', 'assign'), 3);
161         $o .= $this->output->spacer(array('height'=>30));
163         $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
164         if (count($page->notifications)) {
165             // At least one of the submission plugins is not ready for submission
167             $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
169             foreach ($page->notifications as $notification) {
170                 $o .= $this->output->notification($notification);
171             }
173             $o .= $this->output->continue_button($cancelurl);
174         } else {
175             // All submission plugins ready - show the confirmation form (may contain submission statement)
176             $o .= $this->moodleform($page->confirmform);
177         }
178         $o .= $this->output->container_end();
181         return $o;
182     }
184     /**
185      * Page is done - render the footer
186      *
187      * @return void
188      */
189     public function render_footer() {
190         return $this->output->footer();
191     }
193     /**
194      * render the header
195      *
196      * @param assign_header $header
197      * @return string
198      */
199     public function render_assign_header(assign_header $header) {
200         $o = '';
202         if ($header->subpage) {
203             $this->page->navbar->add($header->subpage);
204         }
206         $this->page->set_title(get_string('pluginname', 'assign'));
207         $this->page->set_heading($header->assign->name);
209         $o .= $this->output->header();
210         if ($header->preface) {
211             $o .= $header->preface;
212         }
213         $o .= $this->output->heading(format_string($header->assign->name,false, array('context' => $header->context)));
215         if ($header->showintro) {
216             $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
217             $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
218             $o .= $this->output->box_end();
219         }
221         return $o;
222     }
224     /**
225      * render a table containing the current status of the grading process
226      *
227      * @param assign_grading_summary $summary
228      * @return string
229      */
230     public function render_assign_grading_summary(assign_grading_summary $summary) {
231         // create a table for the data
232         $o = '';
233         $o .= $this->output->container_start('gradingsummary');
234         $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
235         $o .= $this->output->box_start('boxaligncenter gradingsummarytable');
236         $t = new html_table();
238         // status
239         if ($summary->teamsubmission) {
240             $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
241                                        $summary->participantcount);
242         } else {
243             $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
244                                        $summary->participantcount);
245         }
247         // drafts
248         if ($summary->submissiondraftsenabled) {
249             $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
250                                        $summary->submissiondraftscount);
251        }
253         // submitted for grading
254         if ($summary->submissionsenabled) {
255             $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
256                                        $summary->submissionssubmittedcount);
257             $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
258                                        $summary->submissionsneedgradingcount);
259         }
261         $time = time();
262         if ($summary->duedate) {
263             // due date
264             // submitted for grading
265             $duedate = $summary->duedate;
266             $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
267                                        userdate($duedate));
269             // time remaining
270             $due = '';
271             if ($duedate - $time <= 0) {
272                 $due = get_string('assignmentisdue', 'assign');
273             } else {
274                 $due = format_time($duedate - $time);
275             }
276             $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
278             if ($duedate < $time) {
279                 $cutoffdate = $summary->cutoffdate;
280                 if ($cutoffdate) {
281                     if ($cutoffdate > $time) {
282                         $late = get_string('latesubmissionsaccepted', 'assign');
283                     } else {
284                         $late = get_string('nomoresubmissionsaccepted', 'assign');
285                     }
286                     $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
287                 }
288             }
290         }
292         // all done - write the table
293         $o .= html_writer::table($t);
294         $o .= $this->output->box_end();
296         // link to the grading page
297         $o .= $this->output->container_start('submissionlinks');
298         $o .= $this->output->action_link(new moodle_url('/mod/assign/view.php',
299                                                           array('id' => $summary->coursemoduleid,
300                                                                 'action'=>'grading')),
301                                                           get_string('viewgrading', 'assign'));
302         $o .= $this->output->container_end();
304         // close the container and insert a spacer
305         $o .= $this->output->container_end();
307         return $o;
308     }
310     /**
311      * render a table containing all the current grades and feedback
312      *
313      * @param assign_feedback_status $status
314      * @return string
315      */
316     public function render_assign_feedback_status(assign_feedback_status $status) {
317         global $DB, $CFG;
318         $o = '';
320         $o .= $this->output->container_start('feedback');
321         $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
322         $o .= $this->output->box_start('boxaligncenter feedbacktable');
323         $t = new html_table();
325         $row = new html_table_row();
326         $cell1 = new html_table_cell(get_string('grade'));
327         $cell2 = new html_table_cell($status->gradefordisplay);
328         $row->cells = array($cell1, $cell2);
329         $t->data[] = $row;
331         $row = new html_table_row();
332         $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
333         $cell2 = new html_table_cell(userdate($status->gradeddate));
334         $row->cells = array($cell1, $cell2);
335         $t->data[] = $row;
337         if ($status->grader) {
338             $row = new html_table_row();
339             $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
340             $cell2 = new html_table_cell($this->output->user_picture($status->grader) . $this->output->spacer(array('width'=>30)) . fullname($status->grader));
341             $row->cells = array($cell1, $cell2);
342             $t->data[] = $row;
343         }
345         foreach ($status->feedbackplugins as $plugin) {
346             if ($plugin->is_enabled() &&
347                     $plugin->is_visible() &&
348                     $plugin->has_user_summary() &&
349                     !empty($status->grade) &&
350                     !$plugin->is_empty($status->grade)) {
352                 $row = new html_table_row();
353                 $cell1 = new html_table_cell($plugin->get_name());
354                 $pluginfeedback = new assign_feedback_plugin_feedback($plugin, $status->grade, assign_feedback_plugin_feedback::SUMMARY, $status->coursemoduleid, $status->returnaction, $status->returnparams);
355                 $cell2 = new html_table_cell($this->render($pluginfeedback));
356                 $row->cells = array($cell1, $cell2);
357                 $t->data[] = $row;
358             }
359         }
362         $o .= html_writer::table($t);
363         $o .= $this->output->box_end();
365         $o .= $this->output->container_end();
366         return $o;
367     }
369     /**
370      * render a table containing the current status of the submission
371      *
372      * @param assign_submission_status $status
373      * @return string
374      */
375     public function render_assign_submission_status(assign_submission_status $status) {
376         $o = '';
377         $o .= $this->output->container_start('submissionstatustable');
378         $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
379         $time = time();
381         if ($status->allowsubmissionsfromdate &&
382                 $time <= $status->allowsubmissionsfromdate) {
383             $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
384             if ($status->alwaysshowdescription) {
385                 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
386             } else {
387                 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
388             }
389             $o .= $this->output->box_end();
390         }
391         $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
393         $t = new html_table();
395         if ($status->teamsubmissionenabled) {
396             $row = new html_table_row();
397             $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
398             $group = $status->submissiongroup;
399             if ($group) {
400                 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
401             } else {
402                 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
403             }
404             $row->cells = array($cell1, $cell2);
405             $t->data[] = $row;
406         }
408         $row = new html_table_row();
409         $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
410         if (!$status->teamsubmissionenabled) {
411             if ($status->submission) {
412                 $cell2 = new html_table_cell(get_string('submissionstatus_' . $status->submission->status, 'assign'));
413                 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
414             } else {
415                 if (!$status->submissionsenabled) {
416                     $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
417                 } else {
418                     $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
419                 }
420             }
421             $row->cells = array($cell1, $cell2);
422             $t->data[] = $row;
423         } else {
424             $row = new html_table_row();
425             $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
426             if ($status->teamsubmission) {
427                 $submissionsummary = get_string('submissionstatus_' . $status->teamsubmission->status, 'assign');
428                 $groupid = 0;
429                 if ($status->submissiongroup) {
430                     $groupid = $status->submissiongroup->id;
431                 }
433                 $members = $status->submissiongroupmemberswhoneedtosubmit;
434                 $userslist = array();
435                 foreach ($members as $member) {
436                     $url = new moodle_url('/user/view.php', array('id' => $member->id, 'course'=>$status->courseid));
437                     if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
438                         $userslist[] = $member->alias;
439                     } else {
440                         $userslist[] = $this->output->action_link($url, fullname($member, $status->canviewfullnames));
441                     }
442                 }
443                 if (count($userslist) > 0) {
444                     $userstr = join(', ', $userslist);
445                     $submissionsummary .= $this->output->container(get_string('userswhoneedtosubmit', 'assign', $userstr));
446                 }
448                 $cell2 = new html_table_cell($submissionsummary);
449                 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
450             } else {
451                 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
452                 if (!$status->submissionsenabled) {
453                     $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
454                 } else {
455                     $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
456                 }
457             }
458             $row->cells = array($cell1, $cell2);
459             $t->data[] = $row;
460         }
462         // status
463         if ($status->locked) {
464             $row = new html_table_row();
465             $cell1 = new html_table_cell();
466             $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
467             $cell2->attributes = array('class'=>'submissionlocked');
468             $row->cells = array($cell1, $cell2);
469             $t->data[] = $row;
470         }
472         // grading status
473         $row = new html_table_row();
474         $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
476         if ($status->graded) {
477             $cell2 = new html_table_cell(get_string('graded', 'assign'));
478             $cell2->attributes = array('class'=>'submissiongraded');
479         } else {
480             $cell2 = new html_table_cell(get_string('notgraded', 'assign'));
481             $cell2->attributes = array('class'=>'submissionnotgraded');
482         }
483         $row->cells = array($cell1, $cell2);
484         $t->data[] = $row;
487         $duedate = $status->duedate;
488         if ($duedate > 0) {
489             $row = new html_table_row();
490             $cell1 = new html_table_cell(get_string('duedate', 'assign'));
491             $cell2 = new html_table_cell(userdate($duedate));
492             $row->cells = array($cell1, $cell2);
493             $t->data[] = $row;
495             if ($status->view == assign_submission_status::GRADER_VIEW) {
496                 if ($status->cutoffdate) {
497                     $row = new html_table_row();
498                     $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
499                     $cell2 = new html_table_cell(userdate($status->cutoffdate));
500                     $row->cells = array($cell1, $cell2);
501                     $t->data[] = $row;
502                 }
503             }
505             if ($status->extensionduedate) {
506                 $row = new html_table_row();
507                 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
508                 $cell2 = new html_table_cell(userdate($status->extensionduedate));
509                 $row->cells = array($cell1, $cell2);
510                 $t->data[] = $row;
511                 $duedate = $status->extensionduedate;
512             }
514             // Time remaining.
515             $row = new html_table_row();
516             $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
517             if ($duedate - $time <= 0) {
518                 if (!$status->submission || $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
519                     if ($status->submissionsenabled) {
520                         $cell2 = new html_table_cell(get_string('overdue', 'assign', format_time($time - $duedate)));
521                         $cell2->attributes = array('class'=>'overdue');
522                     } else {
523                         $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
524                     }
525                 } else {
526                     if ($status->submission->timemodified > $duedate) {
527                         $cell2 = new html_table_cell(get_string('submittedlate', 'assign', format_time($status->submission->timemodified - $duedate)));
528                         $cell2->attributes = array('class'=>'latesubmission');
529                     } else {
530                         $cell2 = new html_table_cell(get_string('submittedearly', 'assign', format_time($status->submission->timemodified - $duedate)));
531                         $cell2->attributes = array('class'=>'earlysubmission');
532                     }
533                 }
534             } else {
535                 $cell2 = new html_table_cell(format_time($duedate - $time));
536             }
537             $row->cells = array($cell1, $cell2);
538             $t->data[] = $row;
539         }
541         // Show graders whether this submission is editable by students.
542         if ($status->view == assign_submission_status::GRADER_VIEW) {
543             $row = new html_table_row();
544             $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
545             if ($status->canedit) {
546                 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
547                 $cell2->attributes = array('class'=>'submissioneditable');
548             } else {
549                 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
550                 $cell2->attributes = array('class'=>'submissionnoteditable');
551             }
552             $row->cells = array($cell1, $cell2);
553             $t->data[] = $row;
554         }
556         // Grading criteria preview.
557         if (!empty($status->gradingcontrollerpreview)) {
558             $row = new html_table_row();
559             $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
560             $cell2 = new html_table_cell($status->gradingcontrollerpreview);
561             $row->cells = array($cell1, $cell2);
562             $t->data[] = $row;
563         }
565         // Last modified.
566         $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
567         if ($submission) {
568             $row = new html_table_row();
569             $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
570             $cell2 = new html_table_cell(userdate($submission->timemodified));
571             $row->cells = array($cell1, $cell2);
572             $t->data[] = $row;
574             foreach ($status->submissionplugins as $plugin) {
575                 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
576                 if ($plugin->is_enabled() &&
577                     $plugin->is_visible() &&
578                     $plugin->has_user_summary() &&
579                     $pluginshowsummary) {
581                     $row = new html_table_row();
582                     $cell1 = new html_table_cell($plugin->get_name());
583                     $pluginsubmission = new assign_submission_plugin_submission($plugin,
584                                                                                 $submission,
585                                                                                 assign_submission_plugin_submission::SUMMARY,
586                                                                                 $status->coursemoduleid,
587                                                                                 $status->returnaction,
588                                                                                 $status->returnparams);
589                     $cell2 = new html_table_cell($this->render($pluginsubmission));
590                     $row->cells = array($cell1, $cell2);
591                     $t->data[] = $row;
592                 }
593             }
594         }
597         $o .= html_writer::table($t);
598         $o .= $this->output->box_end();
600         // Links.
601         if ($status->view == assign_submission_status::STUDENT_VIEW) {
602             if ($status->canedit) {
603                 if (!$submission) {
604                     $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
605                     $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
606                                                        get_string('addsubmission', 'assign'), 'get');
607                 } else {
608                     $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
609                     $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
610                                                        get_string('editsubmission', 'assign'), 'get');
611                 }
612             }
614             if ($status->cansubmit) {
615                 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
616                 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
617                                                    get_string('submitassignment', 'assign'), 'get');
618                 $o .= $this->output->box_start('boxaligncenter submithelp');
619                 $o .= get_string('submitassignment_help', 'assign');
620                 $o .= $this->output->box_end();
621             }
622         }
624         $o .= $this->output->container_end();
625         return $o;
626     }
628     /**
629      * render a submission plugin submission
630      *
631      * @param assign_submission_plugin_submission $submissionplugin
632      * @return string
633      */
634     public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
635         $o = '';
637         if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
638             $showviewlink = false;
639             $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, $showviewlink);
641             $classsuffix = $submissionplugin->plugin->get_subtype() . '_' . $submissionplugin->plugin->get_type() . '_' . $submissionplugin->submission->id;
642             $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
644             $link = '';
645             if ($showviewlink) {
646                 $previewstr = get_string('viewsubmission', 'assign');
647                 $icon = $this->output->pix_icon('t/preview', $previewstr);
649                 $expandstr = get_string('viewfull', 'assign');
650                 $classes = 'expandsummaryicon expand_' . $classsuffix;
651                 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, array('class'=>$classes));
653                 $jsparams = array($submissionplugin->plugin->get_subtype(),
654                                   $submissionplugin->plugin->get_type(),
655                                   $submissionplugin->submission->id);
656                 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
658                 $link .= '<noscript>';
659                 $link .= $this->output->action_link(
660                                 new moodle_url('/mod/assign/view.php',
661                                                array('id' => $submissionplugin->coursemoduleid,
662                                                      'sid'=>$submissionplugin->submission->id,
663                                                      'plugin'=>$submissionplugin->plugin->get_type(),
664                                                      'action'=>'viewplugin' . $submissionplugin->plugin->get_subtype(),
665                                                      'returnaction'=>$submissionplugin->returnaction,
666                                                      'returnparams'=>http_build_query($submissionplugin->returnparams))),
667                                 $icon);
668                 $link .= '</noscript>';
670                 $link .= $this->output->spacer(array('width'=>15));
671             }
673             $o .= $link . $summary;
674             $o .= $this->output->box_end();
675             if ($showviewlink) {
676                 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
677                 $classes = 'expandsummaryicon contract_' . $classsuffix;
678                 $o .= $this->output->pix_icon('t/switch_minus',
679                                               get_string('viewsummary', 'assign'),
680                                               null,
681                                               array('class'=>$classes));
682                 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
683                 $o .= $this->output->box_end();
684             }
685         } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
686             $o .= $this->output->box_start('boxaligncenter submissionfull');
687             $o .= $submissionplugin->plugin->view($submissionplugin->submission);
688             $o .= $this->output->box_end();
689         }
691         return $o;
692     }
694     /**
695      * render the grading table
696      *
697      * @param assign_grading_table $table
698      * @return string
699      */
700     public function render_assign_grading_table(assign_grading_table $table) {
701         $o = '';
702         $o .= $this->output->box_start('boxaligncenter gradingtable');
704         $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
705         $this->page->requires->string_for_js('nousersselected', 'assign');
706         $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
707         $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
708         $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
709         $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
710         $this->page->requires->string_for_js('editaction', 'assign');
711         foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
712             foreach ($operations as $operation => $description) {
713                 $this->page->requires->string_for_js('batchoperationconfirm' . $operation, 'assignfeedback_' . $plugin);
714             }
715         }
716         // need to get from prefs
717         $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
718         $o .= $this->output->box_end();
720         return $o;
721    }
723     /**
724      * Render a feedback plugin feedback
725      *
726      * @param assign_feedback_plugin_feedback $feedbackplugin
727      * @return string
728      */
729     public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
730         $o = '';
732         if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
733             $showviewlink = false;
734             $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
736             $classsuffix = $feedbackplugin->plugin->get_subtype() . '_' . $feedbackplugin->plugin->get_type() . '_' . $feedbackplugin->grade->id;
737             $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
739             $link = '';
740             if ($showviewlink) {
741                 $previewstr = get_string('viewfeedback', 'assign');
742                 $icon = $this->output->pix_icon('t/preview', $previewstr);
744                 $expandstr = get_string('viewfull', 'assign');
745                 $classes = 'expandsummaryicon expand_' . $classsuffix;
746                 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, array('class'=>$classes));
748                 $jsparams = array($feedbackplugin->plugin->get_subtype(),
749                                   $feedbackplugin->plugin->get_type(),
750                                   $feedbackplugin->grade->id);
751                 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
753                 $link .= '<noscript>';
754                 $link .= $this->output->action_link(
755                                 new moodle_url('/mod/assign/view.php',
756                                                array('id' => $feedbackplugin->coursemoduleid,
757                                                      'gid'=>$feedbackplugin->grade->id,
758                                                      'plugin'=>$feedbackplugin->plugin->get_type(),
759                                                      'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
760                                                      'returnaction'=>$feedbackplugin->returnaction,
761                                                      'returnparams'=>http_build_query($feedbackplugin->returnparams))),
762                                 $icon);
763                 $link .= '</noscript>';
765                 $link .= $this->output->spacer(array('width'=>15));
766             }
768             $o .= $link . $summary;
769             $o .= $this->output->box_end();
770             if ($showviewlink) {
771                 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
772                 $classes = 'expandsummaryicon contract_' . $classsuffix;
773                 $o .= $this->output->pix_icon('t/switch_minus',
774                                               get_string('viewsummary', 'assign'),
775                                               null,
776                                               array('class'=>$classes));
777                 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
778                 $o .= $this->output->box_end();
779             }
780         } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
781             $o .= $this->output->box_start('boxaligncenter feedbackfull');
782             $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
783             $o .= $this->output->box_end();
784         }
786         return $o;
787     }
791     /**
792      * Internal function - creates htmls structure suitable for YUI tree.
793      *
794      * @param assign_files $tree
795      * @param array $dir
796      * @return string
797      */
798     protected function htmllize_tree(assign_files $tree, $dir) {
799         global $CFG;
800         $yuiconfig = array();
801         $yuiconfig['type'] = 'html';
803         if (empty($dir['subdirs']) and empty($dir['files'])) {
804             return '';
805         }
807         $result = '<ul>';
808         foreach ($dir['subdirs'] as $subdir) {
809             $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
810             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
811         }
813         foreach ($dir['files'] as $file) {
814             $filename = $file->get_filename();
815             if ($CFG->enableplagiarism) {
816                 require_once($CFG->libdir.'/plagiarismlib.php');
817                 $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
818             } else {
819                 $plagiarsmlinks = '';
820             }
821             $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
822             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
823         }
825         $result .= '</ul>';
827         return $result;
828     }
830     /**
831      * Helper method dealing with the fact we can not just fetch the output of flexible_table
832      *
833      * @param flexible_table $table The table to render
834      * @param int $rowsperpage How many assignments to render in a page
835      * @param bool $displaylinks - Whether to render links in the table (e.g. downloads would not enable this)
836      * @return string HTML
837      */
838     protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
840         $o = '';
841         ob_start();
842         $table->out($rowsperpage, $displaylinks);
843         $o = ob_get_contents();
844         ob_end_clean();
846         return $o;
847     }
849     /**
850      * Helper method dealing with the fact we can not just fetch the output of moodleforms
851      *
852      * @param moodleform $mform
853      * @return string HTML
854      */
855     protected function moodleform(moodleform $mform) {
857         $o = '';
858         ob_start();
859         $mform->display();
860         $o = ob_get_contents();
861         ob_end_clean();
863         return $o;
864     }