MDL-36263 Assignment: Do not count submissions of unenrolled users
[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             if (!$summary->teamsubmission) {
258                 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
259                                            $summary->submissionsneedgradingcount);
260             }
261         }
263         $time = time();
264         if ($summary->duedate) {
265             // due date
266             // submitted for grading
267             $duedate = $summary->duedate;
268             $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
269                                        userdate($duedate));
271             // time remaining
272             $due = '';
273             if ($duedate - $time <= 0) {
274                 $due = get_string('assignmentisdue', 'assign');
275             } else {
276                 $due = format_time($duedate - $time);
277             }
278             $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
280             if ($duedate < $time) {
281                 $cutoffdate = $summary->cutoffdate;
282                 if ($cutoffdate) {
283                     if ($cutoffdate > $time) {
284                         $late = get_string('latesubmissionsaccepted', 'assign');
285                     } else {
286                         $late = get_string('nomoresubmissionsaccepted', 'assign');
287                     }
288                     $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
289                 }
290             }
292         }
294         // all done - write the table
295         $o .= html_writer::table($t);
296         $o .= $this->output->box_end();
298         // link to the grading page
299         $o .= $this->output->container_start('submissionlinks');
300         $o .= $this->output->action_link(new moodle_url('/mod/assign/view.php',
301                                                           array('id' => $summary->coursemoduleid,
302                                                                 'action'=>'grading')),
303                                                           get_string('viewgrading', 'assign'));
304         $o .= $this->output->container_end();
306         // close the container and insert a spacer
307         $o .= $this->output->container_end();
309         return $o;
310     }
312     /**
313      * render a table containing all the current grades and feedback
314      *
315      * @param assign_feedback_status $status
316      * @return string
317      */
318     public function render_assign_feedback_status(assign_feedback_status $status) {
319         global $DB, $CFG;
320         $o = '';
322         $o .= $this->output->container_start('feedback');
323         $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
324         $o .= $this->output->box_start('boxaligncenter feedbacktable');
325         $t = new html_table();
327         $row = new html_table_row();
328         $cell1 = new html_table_cell(get_string('grade'));
329         $cell2 = new html_table_cell($status->gradefordisplay);
330         $row->cells = array($cell1, $cell2);
331         $t->data[] = $row;
333         $row = new html_table_row();
334         $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
335         $cell2 = new html_table_cell(userdate($status->gradeddate));
336         $row->cells = array($cell1, $cell2);
337         $t->data[] = $row;
339         if ($status->grader) {
340             $row = new html_table_row();
341             $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
342             $cell2 = new html_table_cell($this->output->user_picture($status->grader) . $this->output->spacer(array('width'=>30)) . fullname($status->grader));
343             $row->cells = array($cell1, $cell2);
344             $t->data[] = $row;
345         }
347         foreach ($status->feedbackplugins as $plugin) {
348             if ($plugin->is_enabled() &&
349                     $plugin->is_visible() &&
350                     $plugin->has_user_summary() &&
351                     !empty($status->grade) &&
352                     !$plugin->is_empty($status->grade)) {
354                 $row = new html_table_row();
355                 $cell1 = new html_table_cell($plugin->get_name());
356                 $pluginfeedback = new assign_feedback_plugin_feedback($plugin, $status->grade, assign_feedback_plugin_feedback::SUMMARY, $status->coursemoduleid, $status->returnaction, $status->returnparams);
357                 $cell2 = new html_table_cell($this->render($pluginfeedback));
358                 $row->cells = array($cell1, $cell2);
359                 $t->data[] = $row;
360             }
361         }
364         $o .= html_writer::table($t);
365         $o .= $this->output->box_end();
367         $o .= $this->output->container_end();
368         return $o;
369     }
371     /**
372      * render a table containing the current status of the submission
373      *
374      * @param assign_submission_status $status
375      * @return string
376      */
377     public function render_assign_submission_status(assign_submission_status $status) {
378         $o = '';
379         $o .= $this->output->container_start('submissionstatustable');
380         $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
381         $time = time();
383         if ($status->allowsubmissionsfromdate &&
384                 $time <= $status->allowsubmissionsfromdate) {
385             $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
386             if ($status->alwaysshowdescription) {
387                 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
388             } else {
389                 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
390             }
391             $o .= $this->output->box_end();
392         }
393         $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
395         $t = new html_table();
397         if ($status->teamsubmissionenabled) {
398             $row = new html_table_row();
399             $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
400             $group = $status->submissiongroup;
401             if ($group) {
402                 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
403             } else {
404                 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
405             }
406             $row->cells = array($cell1, $cell2);
407             $t->data[] = $row;
408         }
410         $row = new html_table_row();
411         $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
412         if (!$status->teamsubmissionenabled) {
413             if ($status->submission) {
414                 $cell2 = new html_table_cell(get_string('submissionstatus_' . $status->submission->status, 'assign'));
415                 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
416             } else {
417                 if (!$status->submissionsenabled) {
418                     $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
419                 } else {
420                     $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
421                 }
422             }
423             $row->cells = array($cell1, $cell2);
424             $t->data[] = $row;
425         } else {
426             $row = new html_table_row();
427             $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
428             if ($status->teamsubmission) {
429                 $submissionsummary = get_string('submissionstatus_' . $status->teamsubmission->status, 'assign');
430                 $groupid = 0;
431                 if ($status->submissiongroup) {
432                     $groupid = $status->submissiongroup->id;
433                 }
435                 $members = $status->submissiongroupmemberswhoneedtosubmit;
436                 $userslist = array();
437                 foreach ($members as $member) {
438                     $url = new moodle_url('/user/view.php', array('id' => $member->id, 'course'=>$status->courseid));
439                     if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
440                         $userslist[] = $member->alias;
441                     } else {
442                         $userslist[] = $this->output->action_link($url, fullname($member, $status->canviewfullnames));
443                     }
444                 }
445                 if (count($userslist) > 0) {
446                     $userstr = join(', ', $userslist);
447                     $submissionsummary .= $this->output->container(get_string('userswhoneedtosubmit', 'assign', $userstr));
448                 }
450                 $cell2 = new html_table_cell($submissionsummary);
451                 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
452             } else {
453                 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
454                 if (!$status->submissionsenabled) {
455                     $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
456                 } else {
457                     $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
458                 }
459             }
460             $row->cells = array($cell1, $cell2);
461             $t->data[] = $row;
462         }
464         // status
465         if ($status->locked) {
466             $row = new html_table_row();
467             $cell1 = new html_table_cell();
468             $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
469             $cell2->attributes = array('class'=>'submissionlocked');
470             $row->cells = array($cell1, $cell2);
471             $t->data[] = $row;
472         }
474         // grading status
475         $row = new html_table_row();
476         $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
478         if ($status->graded) {
479             $cell2 = new html_table_cell(get_string('graded', 'assign'));
480             $cell2->attributes = array('class'=>'submissiongraded');
481         } else {
482             $cell2 = new html_table_cell(get_string('notgraded', 'assign'));
483             $cell2->attributes = array('class'=>'submissionnotgraded');
484         }
485         $row->cells = array($cell1, $cell2);
486         $t->data[] = $row;
489         $duedate = $status->duedate;
490         if ($duedate > 0) {
491             $row = new html_table_row();
492             $cell1 = new html_table_cell(get_string('duedate', 'assign'));
493             $cell2 = new html_table_cell(userdate($duedate));
494             $row->cells = array($cell1, $cell2);
495             $t->data[] = $row;
497             if ($status->view == assign_submission_status::GRADER_VIEW) {
498                 if ($status->cutoffdate) {
499                     $row = new html_table_row();
500                     $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
501                     $cell2 = new html_table_cell(userdate($status->cutoffdate));
502                     $row->cells = array($cell1, $cell2);
503                     $t->data[] = $row;
504                 }
505             }
507             if ($status->extensionduedate) {
508                 $row = new html_table_row();
509                 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
510                 $cell2 = new html_table_cell(userdate($status->extensionduedate));
511                 $row->cells = array($cell1, $cell2);
512                 $t->data[] = $row;
513                 $duedate = $status->extensionduedate;
514             }
516             // Time remaining.
517             $row = new html_table_row();
518             $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
519             if ($duedate - $time <= 0) {
520                 if (!$status->submission || $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
521                     if ($status->submissionsenabled) {
522                         $cell2 = new html_table_cell(get_string('overdue', 'assign', format_time($time - $duedate)));
523                         $cell2->attributes = array('class'=>'overdue');
524                     } else {
525                         $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
526                     }
527                 } else {
528                     if ($status->submission->timemodified > $duedate) {
529                         $cell2 = new html_table_cell(get_string('submittedlate', 'assign', format_time($status->submission->timemodified - $duedate)));
530                         $cell2->attributes = array('class'=>'latesubmission');
531                     } else {
532                         $cell2 = new html_table_cell(get_string('submittedearly', 'assign', format_time($status->submission->timemodified - $duedate)));
533                         $cell2->attributes = array('class'=>'earlysubmission');
534                     }
535                 }
536             } else {
537                 $cell2 = new html_table_cell(format_time($duedate - $time));
538             }
539             $row->cells = array($cell1, $cell2);
540             $t->data[] = $row;
541         }
543         // Show graders whether this submission is editable by students.
544         if ($status->view == assign_submission_status::GRADER_VIEW) {
545             $row = new html_table_row();
546             $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
547             if ($status->canedit) {
548                 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
549                 $cell2->attributes = array('class'=>'submissioneditable');
550             } else {
551                 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
552                 $cell2->attributes = array('class'=>'submissionnoteditable');
553             }
554             $row->cells = array($cell1, $cell2);
555             $t->data[] = $row;
556         }
558         // Grading criteria preview.
559         if (!empty($status->gradingcontrollerpreview)) {
560             $row = new html_table_row();
561             $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
562             $cell2 = new html_table_cell($status->gradingcontrollerpreview);
563             $row->cells = array($cell1, $cell2);
564             $t->data[] = $row;
565         }
567         // Last modified.
568         $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
569         if ($submission) {
570             $row = new html_table_row();
571             $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
572             $cell2 = new html_table_cell(userdate($submission->timemodified));
573             $row->cells = array($cell1, $cell2);
574             $t->data[] = $row;
576             foreach ($status->submissionplugins as $plugin) {
577                 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
578                 if ($plugin->is_enabled() &&
579                     $plugin->is_visible() &&
580                     $plugin->has_user_summary() &&
581                     $pluginshowsummary) {
583                     $row = new html_table_row();
584                     $cell1 = new html_table_cell($plugin->get_name());
585                     $pluginsubmission = new assign_submission_plugin_submission($plugin,
586                                                                                 $submission,
587                                                                                 assign_submission_plugin_submission::SUMMARY,
588                                                                                 $status->coursemoduleid,
589                                                                                 $status->returnaction,
590                                                                                 $status->returnparams);
591                     $cell2 = new html_table_cell($this->render($pluginsubmission));
592                     $row->cells = array($cell1, $cell2);
593                     $t->data[] = $row;
594                 }
595             }
596         }
599         $o .= html_writer::table($t);
600         $o .= $this->output->box_end();
602         // Links.
603         if ($status->view == assign_submission_status::STUDENT_VIEW) {
604             if ($status->canedit) {
605                 if (!$submission) {
606                     $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
607                     $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
608                                                        get_string('addsubmission', 'assign'), 'get');
609                 } else {
610                     $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
611                     $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
612                                                        get_string('editsubmission', 'assign'), 'get');
613                 }
614             }
616             if ($status->cansubmit) {
617                 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
618                 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
619                                                    get_string('submitassignment', 'assign'), 'get');
620                 $o .= $this->output->box_start('boxaligncenter submithelp');
621                 $o .= get_string('submitassignment_help', 'assign');
622                 $o .= $this->output->box_end();
623             }
624         }
626         $o .= $this->output->container_end();
627         return $o;
628     }
630     /**
631      * render a submission plugin submission
632      *
633      * @param assign_submission_plugin_submission $submissionplugin
634      * @return string
635      */
636     public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
637         $o = '';
639         if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
640             $showviewlink = false;
641             $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, $showviewlink);
643             $classsuffix = $submissionplugin->plugin->get_subtype() . '_' . $submissionplugin->plugin->get_type() . '_' . $submissionplugin->submission->id;
644             $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
646             $link = '';
647             if ($showviewlink) {
648                 $previewstr = get_string('viewsubmission', 'assign');
649                 $icon = $this->output->pix_icon('t/preview', $previewstr);
651                 $expandstr = get_string('viewfull', 'assign');
652                 $classes = 'expandsummaryicon expand_' . $classsuffix;
653                 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, array('class'=>$classes));
655                 $jsparams = array($submissionplugin->plugin->get_subtype(),
656                                   $submissionplugin->plugin->get_type(),
657                                   $submissionplugin->submission->id);
658                 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
660                 $link .= '<noscript>';
661                 $link .= $this->output->action_link(
662                                 new moodle_url('/mod/assign/view.php',
663                                                array('id' => $submissionplugin->coursemoduleid,
664                                                      'sid'=>$submissionplugin->submission->id,
665                                                      'plugin'=>$submissionplugin->plugin->get_type(),
666                                                      'action'=>'viewplugin' . $submissionplugin->plugin->get_subtype(),
667                                                      'returnaction'=>$submissionplugin->returnaction,
668                                                      'returnparams'=>http_build_query($submissionplugin->returnparams))),
669                                 $icon);
670                 $link .= '</noscript>';
672                 $link .= $this->output->spacer(array('width'=>15));
673             }
675             $o .= $link . $summary;
676             $o .= $this->output->box_end();
677             if ($showviewlink) {
678                 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
679                 $classes = 'expandsummaryicon contract_' . $classsuffix;
680                 $o .= $this->output->pix_icon('t/switch_minus',
681                                               get_string('viewsummary', 'assign'),
682                                               null,
683                                               array('class'=>$classes));
684                 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
685                 $o .= $this->output->box_end();
686             }
687         } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
688             $o .= $this->output->box_start('boxaligncenter submissionfull');
689             $o .= $submissionplugin->plugin->view($submissionplugin->submission);
690             $o .= $this->output->box_end();
691         }
693         return $o;
694     }
696     /**
697      * render the grading table
698      *
699      * @param assign_grading_table $table
700      * @return string
701      */
702     public function render_assign_grading_table(assign_grading_table $table) {
703         $o = '';
704         $o .= $this->output->box_start('boxaligncenter gradingtable');
706         $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
707         $this->page->requires->string_for_js('nousersselected', 'assign');
708         $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
709         $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
710         $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
711         $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
712         $this->page->requires->string_for_js('editaction', 'assign');
713         foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
714             foreach ($operations as $operation => $description) {
715                 $this->page->requires->string_for_js('batchoperationconfirm' . $operation, 'assignfeedback_' . $plugin);
716             }
717         }
718         // need to get from prefs
719         $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
720         $o .= $this->output->box_end();
722         return $o;
723    }
725     /**
726      * Render a feedback plugin feedback
727      *
728      * @param assign_feedback_plugin_feedback $feedbackplugin
729      * @return string
730      */
731     public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
732         $o = '';
734         if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
735             $showviewlink = false;
736             $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
738             $classsuffix = $feedbackplugin->plugin->get_subtype() . '_' . $feedbackplugin->plugin->get_type() . '_' . $feedbackplugin->grade->id;
739             $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
741             $link = '';
742             if ($showviewlink) {
743                 $previewstr = get_string('viewfeedback', 'assign');
744                 $icon = $this->output->pix_icon('t/preview', $previewstr);
746                 $expandstr = get_string('viewfull', 'assign');
747                 $classes = 'expandsummaryicon expand_' . $classsuffix;
748                 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, array('class'=>$classes));
750                 $jsparams = array($feedbackplugin->plugin->get_subtype(),
751                                   $feedbackplugin->plugin->get_type(),
752                                   $feedbackplugin->grade->id);
753                 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
755                 $link .= '<noscript>';
756                 $link .= $this->output->action_link(
757                                 new moodle_url('/mod/assign/view.php',
758                                                array('id' => $feedbackplugin->coursemoduleid,
759                                                      'gid'=>$feedbackplugin->grade->id,
760                                                      'plugin'=>$feedbackplugin->plugin->get_type(),
761                                                      'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
762                                                      'returnaction'=>$feedbackplugin->returnaction,
763                                                      'returnparams'=>http_build_query($feedbackplugin->returnparams))),
764                                 $icon);
765                 $link .= '</noscript>';
767                 $link .= $this->output->spacer(array('width'=>15));
768             }
770             $o .= $link . $summary;
771             $o .= $this->output->box_end();
772             if ($showviewlink) {
773                 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
774                 $classes = 'expandsummaryicon contract_' . $classsuffix;
775                 $o .= $this->output->pix_icon('t/switch_minus',
776                                               get_string('viewsummary', 'assign'),
777                                               null,
778                                               array('class'=>$classes));
779                 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
780                 $o .= $this->output->box_end();
781             }
782         } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
783             $o .= $this->output->box_start('boxaligncenter feedbackfull');
784             $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
785             $o .= $this->output->box_end();
786         }
788         return $o;
789     }
793     /**
794      * Internal function - creates htmls structure suitable for YUI tree.
795      *
796      * @param assign_files $tree
797      * @param array $dir
798      * @return string
799      */
800     protected function htmllize_tree(assign_files $tree, $dir) {
801         global $CFG;
802         $yuiconfig = array();
803         $yuiconfig['type'] = 'html';
805         if (empty($dir['subdirs']) and empty($dir['files'])) {
806             return '';
807         }
809         $result = '<ul>';
810         foreach ($dir['subdirs'] as $subdir) {
811             $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
812             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
813         }
815         foreach ($dir['files'] as $file) {
816             $filename = $file->get_filename();
817             if ($CFG->enableplagiarism) {
818                 require_once($CFG->libdir.'/plagiarismlib.php');
819                 $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
820             } else {
821                 $plagiarsmlinks = '';
822             }
823             $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
824             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
825         }
827         $result .= '</ul>';
829         return $result;
830     }
832     /**
833      * Helper method dealing with the fact we can not just fetch the output of flexible_table
834      *
835      * @param flexible_table $table The table to render
836      * @param int $rowsperpage How many assignments to render in a page
837      * @param bool $displaylinks - Whether to render links in the table (e.g. downloads would not enable this)
838      * @return string HTML
839      */
840     protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
842         $o = '';
843         ob_start();
844         $table->out($rowsperpage, $displaylinks);
845         $o = ob_get_contents();
846         ob_end_clean();
848         return $o;
849     }
851     /**
852      * Helper method dealing with the fact we can not just fetch the output of moodleforms
853      *
854      * @param moodleform $mform
855      * @return string HTML
856      */
857     protected function moodleform(moodleform $mform) {
859         $o = '';
860         ob_start();
861         $mform->display();
862         $o = ob_get_contents();
863         ob_end_clean();
865         return $o;
866     }