3ca0232f515badbb3638de2d40af003d0c3e4dba
[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         $o .= $this->output->user_picture($summary->user);
135         $o .= $this->output->spacer(array('width'=>30));
136         $o .= $this->output->action_link(new moodle_url('/user/view.php',
137                                                         array('id' => $summary->user->id,
138                                                               'course'=>$summary->courseid)),
139                                                               fullname($summary->user, $summary->viewfullnames));
140         $o .= $this->output->box_end();
141         $o .= $this->output->container_end();
143         return $o;
144     }
146     /**
147      * Render the submit for grading page
148      *
149      * @param assign_submit_for_grading_page $page
150      * @return string
151      */
152     public function render_assign_submit_for_grading_page($page) {
153         $o = '';
155         $o .= $this->output->container_start('submitforgrading');
156         $o .= $this->output->heading(get_string('submitassignment', 'assign'), 3);
157         $o .= $this->output->spacer(array('height'=>30));
159         $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
160         if (count($page->notifications)) {
161             // At least one of the submission plugins is not ready for submission
163             $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
165             foreach ($page->notifications as $notification) {
166                 $o .= $this->output->notification($notification);
167             }
169             $o .= $this->output->continue_button($cancelurl);
170         } else {
171             // All submission plugins ready - confirm the student really does want to submit for marking
172             $continueurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid,
173                                                                         'action' => 'confirmsubmit',
174                                                                         'sesskey' => sesskey()));
175             $o .= $this->output->confirm(get_string('confirmsubmission', 'mod_assign'), $continueurl, $cancelurl);
176         }
177         $o .= $this->output->container_end();
180         return $o;
181     }
183     /**
184      * Page is done - render the footer
185      *
186      * @return void
187      */
188     public function render_footer() {
189         return $this->output->footer();
190     }
192     /**
193      * render the header
194      *
195      * @param assign_header $header
196      * @return string
197      */
198     public function render_assign_header(assign_header $header) {
199         $o = '';
201         if ($header->subpage) {
202             $this->page->navbar->add($header->subpage);
203         }
205         $this->page->set_title(get_string('pluginname', 'assign'));
206         $this->page->set_heading($header->assign->name);
208         $o .= $this->output->header();
209         if ($header->preface) {
210             $o .= $header->preface;
211         }
212         $o .= $this->output->heading(format_string($header->assign->name,false, array('context' => $header->context)));
214         if ($header->showintro) {
215             $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
216             $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
217             $o .= $this->output->box_end();
218         }
220         return $o;
221     }
223     /**
224      * render a table containing the current status of the grading process
225      *
226      * @param assign_grading_summary $summary
227      * @return string
228      */
229     public function render_assign_grading_summary(assign_grading_summary $summary) {
230         // create a table for the data
231         $o = '';
232         $o .= $this->output->container_start('gradingsummary');
233         $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
234         $o .= $this->output->box_start('boxaligncenter gradingsummarytable');
235         $t = new html_table();
237         // status
238         $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
239                                    $summary->participantcount);
241         // drafts
242         if ($summary->submissiondraftsenabled) {
243             $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
244                                        $summary->submissiondraftscount);
245        }
247         // submitted for grading
248         if ($summary->submissionsenabled) {
249             $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
250                                        $summary->submissionssubmittedcount);
251             $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
252                                        $summary->submissionsneedgradingcount);
253         }
255         $time = time();
256         if ($summary->duedate) {
257             // due date
258             // submitted for grading
259             $duedate = $summary->duedate;
260             $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
261                                        userdate($duedate));
263             // time remaining
264             $due = '';
265             if ($duedate - $time <= 0) {
266                 $due = get_string('assignmentisdue', 'assign');
267             } else {
268                 $due = format_time($duedate - $time);
269             }
270             $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
271         }
273         // all done - write the table
274         $o .= html_writer::table($t);
275         $o .= $this->output->box_end();
277         // link to the grading page
278         $o .= $this->output->container_start('submissionlinks');
279         $o .= $this->output->action_link(new moodle_url('/mod/assign/view.php',
280                                                           array('id' => $summary->coursemoduleid,
281                                                                 'action'=>'grading')),
282                                                           get_string('viewgrading', 'assign'));
283         $o .= $this->output->container_end();
285         // close the container and insert a spacer
286         $o .= $this->output->container_end();
288         return $o;
289     }
291     /**
292      * render a table containing all the current grades and feedback
293      *
294      * @param assign_feedback_status $status
295      * @return string
296      */
297     public function render_assign_feedback_status(assign_feedback_status $status) {
298         global $DB, $CFG;
299         $o = '';
301         $o .= $this->output->container_start('feedback');
302         $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
303         $o .= $this->output->box_start('boxaligncenter feedbacktable');
304         $t = new html_table();
306         $row = new html_table_row();
307         $cell1 = new html_table_cell(get_string('grade'));
308         $cell2 = new html_table_cell($status->gradefordisplay);
309         $row->cells = array($cell1, $cell2);
310         $t->data[] = $row;
312         $row = new html_table_row();
313         $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
314         $cell2 = new html_table_cell(userdate($status->gradeddate));
315         $row->cells = array($cell1, $cell2);
316         $t->data[] = $row;
318         if ($status->grader) {
319             $row = new html_table_row();
320             $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
321             $cell2 = new html_table_cell($this->output->user_picture($status->grader) . $this->output->spacer(array('width'=>30)) . fullname($status->grader));
322             $row->cells = array($cell1, $cell2);
323             $t->data[] = $row;
324         }
326         foreach ($status->feedbackplugins as $plugin) {
327             if ($plugin->is_enabled() && $plugin->is_visible() && !$plugin->is_empty($status->grade)) {
328                 $row = new html_table_row();
329                 $cell1 = new html_table_cell($plugin->get_name());
330                 $pluginfeedback = new assign_feedback_plugin_feedback($plugin, $status->grade, assign_feedback_plugin_feedback::SUMMARY, $status->coursemoduleid, $status->returnaction, $status->returnparams);
331                 $cell2 = new html_table_cell($this->render($pluginfeedback));
332                 $row->cells = array($cell1, $cell2);
333                 $t->data[] = $row;
334             }
335         }
338         $o .= html_writer::table($t);
339         $o .= $this->output->box_end();
341         $o .= $this->output->container_end();
342         return $o;
343     }
345     /**
346      * render a table containing the current status of the submission
347      *
348      * @param assign_submission_status $status
349      * @return string
350      */
351     public function render_assign_submission_status(assign_submission_status $status) {
352         $o = '';
353         $o .= $this->output->container_start('submissionstatustable');
354         $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
355         $time = time();
357         if ($status->allowsubmissionsfromdate &&
358                 $time <= $status->allowsubmissionsfromdate) {
359             $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
360             if ($status->alwaysshowdescription) {
361                 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
362             } else {
363                 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
364             }
365             $o .= $this->output->box_end();
366         }
367         $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
369         $t = new html_table();
371         $row = new html_table_row();
372         $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
373         if ($status->submission) {
374             $cell2 = new html_table_cell(get_string('submissionstatus_' . $status->submission->status, 'assign'));
375             $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
376         } else {
377             if (!$status->submissionsenabled) {
378                 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
379             } else {
380                 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
381             }
382         }
383         $row->cells = array($cell1, $cell2);
384         $t->data[] = $row;
386         // status
387         if ($status->locked) {
388             $row = new html_table_row();
389             $cell1 = new html_table_cell();
390             $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
391             $cell2->attributes = array('class'=>'submissionlocked');
392             $row->cells = array($cell1, $cell2);
393             $t->data[] = $row;
394         }
396         // grading status
397         $row = new html_table_row();
398         $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
400         if ($status->graded) {
401             $cell2 = new html_table_cell(get_string('graded', 'assign'));
402             $cell2->attributes = array('class'=>'submissiongraded');
403         } else {
404             $cell2 = new html_table_cell(get_string('notgraded', 'assign'));
405             $cell2->attributes = array('class'=>'submissionnotgraded');
406         }
407         $row->cells = array($cell1, $cell2);
408         $t->data[] = $row;
411         $duedate = $status->duedate;
412         if ($duedate >= 1) {
413             $row = new html_table_row();
414             $cell1 = new html_table_cell(get_string('duedate', 'assign'));
415             $cell2 = new html_table_cell(userdate($duedate));
416             $row->cells = array($cell1, $cell2);
417             $t->data[] = $row;
419             // time remaining
420             $row = new html_table_row();
421             $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
422             if ($duedate - $time <= 0) {
423                 if (!$status->submission || $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
424                     if ($status->submissionsenabled) {
425                         $cell2 = new html_table_cell(get_string('overdue', 'assign', format_time($time - $duedate)));
426                         $cell2->attributes = array('class'=>'overdue');
427                     } else {
428                         $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
429                     }
430                 } else {
431                     if ($status->submission->timemodified > $duedate) {
432                         $cell2 = new html_table_cell(get_string('submittedlate', 'assign', format_time($status->submission->timemodified - $duedate)));
433                         $cell2->attributes = array('class'=>'latesubmission');
434                     } else {
435                         $cell2 = new html_table_cell(get_string('submittedearly', 'assign', format_time($status->submission->timemodified - $duedate)));
436                         $cell2->attributes = array('class'=>'earlysubmission');
437                     }
438                 }
439             } else {
440                 $cell2 = new html_table_cell(format_time($duedate - $time));
441             }
442             $row->cells = array($cell1, $cell2);
443             $t->data[] = $row;
444         }
446         // last modified
447         if ($status->submission) {
448             $row = new html_table_row();
449             $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
450             $cell2 = new html_table_cell(userdate($status->submission->timemodified));
451             $row->cells = array($cell1, $cell2);
452             $t->data[] = $row;
454             foreach ($status->submissionplugins as $plugin) {
455                 if ($plugin->is_enabled() && $plugin->is_visible() && !$plugin->is_empty($status->submission)) {
456                     $row = new html_table_row();
457                     $cell1 = new html_table_cell($plugin->get_name());
458                     $pluginsubmission = new assign_submission_plugin_submission($plugin, $status->submission, assign_submission_plugin_submission::SUMMARY, $status->coursemoduleid, $status->returnaction, $status->returnparams);
459                     $cell2 = new html_table_cell($this->render($pluginsubmission));
460                     $row->cells = array($cell1, $cell2);
461                     $t->data[] = $row;
462                 }
463             }
464         }
467         $o .= html_writer::table($t);
468         $o .= $this->output->box_end();
470         // links
471         if ($status->canedit) {
472             if (!$status->submission) {
473                 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php',
474                     array('id' => $status->coursemoduleid, 'action' => 'editsubmission')), get_string('addsubmission', 'assign'), 'get');
475             } else {
476                 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php',
477                     array('id' => $status->coursemoduleid, 'action' => 'editsubmission')), get_string('editsubmission', 'assign'), 'get');
478             }
479         }
481         if ($status->cansubmit) {
482             // submission.php
483             $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php',
484                     array('id' => $status->coursemoduleid, 'action'=>'submit')), get_string('submitassignment', 'assign'), 'get');
485             $o .= $this->output->box_start('boxaligncenter submithelp');
486             $o .= get_string('submitassignment_help', 'assign');
487             $o .= $this->output->box_end();
488         }
490         $o .= $this->output->container_end();
491         return $o;
492     }
494     /**
495      * render a submission plugin submission
496      *
497      * @param assign_submission_plugin_submission $submissionplugin
498      * @return string
499      */
500     public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
501         $o = '';
503         if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
504             $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($submissionplugin->plugin->get_subtype(), strlen('assign')), 'mod_assign'));
505             $link = '';
506             $showviewlink = false;
507             $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, $showviewlink);
508             if ($showviewlink) {
509                 $link = $this->output->action_link(
510                                 new moodle_url('/mod/assign/view.php',
511                                                array('id' => $submissionplugin->coursemoduleid,
512                                                      'sid'=>$submissionplugin->submission->id,
513                                                      'plugin'=>$submissionplugin->plugin->get_type(),
514                                                      'action'=>'viewplugin' . $submissionplugin->plugin->get_subtype(),
515                                                      'returnaction'=>$submissionplugin->returnaction,
516                                                      'returnparams'=>http_build_query($submissionplugin->returnparams))),
517                                 $icon);
519                 $link .= $this->output->spacer(array('width'=>15));
520             }
522             $o .= $link . $summary;
523         } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
524             $o .= $this->output->box_start('boxaligncenter submissionfull');
525             $o .= $submissionplugin->plugin->view($submissionplugin->submission);
526             $o .= $this->output->box_end();
527         }
529         return $o;
530     }
532     /**
533      * render the grading table
534      *
535      * @param assign_grading_table $table
536      * @return string
537      */
538     public function render_assign_grading_table(assign_grading_table $table) {
539         $o = '';
540         $o .= $this->output->box_start('boxaligncenter gradingtable');
541         $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
542         $this->page->requires->string_for_js('nousersselected', 'assign');
543         $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
544         $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
545         $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
546         $this->page->requires->string_for_js('editaction', 'assign');
547         // need to get from prefs
548         $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
549         $o .= $this->output->box_end();
551         return $o;
552    }
554     /**
555      * Render a feedback plugin feedback
556      *
557      * @param assign_feedback_plugin_feedback $feedbackplugin
558      * @return string
559      */
560     public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
561         $o = '';
563         if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
564             $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($feedbackplugin->plugin->get_subtype(), strlen('assign')), 'mod_assign'));
565             $link = '';
566             $showviewlink = false;
567             $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
568             if ($showviewlink) {
569                 $link = $this->output->action_link(
570                                 new moodle_url('/mod/assign/view.php',
571                                                array('id' => $feedbackplugin->coursemoduleid,
572                                                      'gid'=>$feedbackplugin->grade->id,
573                                                      'plugin'=>$feedbackplugin->plugin->get_type(),
574                                                      'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
575                                                      'returnaction'=>$feedbackplugin->returnaction,
576                                                      'returnparams'=>http_build_query($feedbackplugin->returnparams))),
577                                 $icon);
578                 $link .= $this->output->spacer(array('width'=>15));
579             }
581             $o .= $link . $summary;
582         } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
583             $o .= $this->output->box_start('boxaligncenter feedbackfull');
584             $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
585             $o .= $this->output->box_end();
586         }
588         return $o;
589     }
593     /**
594      * Internal function - creates htmls structure suitable for YUI tree.
595      *
596      * @param assign_files $tree
597      * @param array $dir
598      * @return string
599      */
600     protected function htmllize_tree(assign_files $tree, $dir) {
601         global $CFG;
602         $yuiconfig = array();
603         $yuiconfig['type'] = 'html';
605         if (empty($dir['subdirs']) and empty($dir['files'])) {
606             return '';
607         }
609         $result = '<ul>';
610         foreach ($dir['subdirs'] as $subdir) {
611             $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
612             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
613         }
615         foreach ($dir['files'] as $file) {
616             $filename = $file->get_filename();
617             if ($CFG->enableplagiarism) {
618                 require_once($CFG->libdir.'/plagiarismlib.php');
619                 $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
620             } else {
621                 $plagiarsmlinks = '';
622             }
623             $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
624             $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
625         }
627         $result .= '</ul>';
629         return $result;
630     }
632     /**
633      * Helper method dealing with the fact we can not just fetch the output of flexible_table
634      *
635      * @param flexible_table $table The table to render
636      * @param int $rowsperpage How many assignments to render in a page
637      * @param bool $displaylinks - Whether to render links in the table (e.g. downloads would not enable this)
638      * @return string HTML
639      */
640     protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
642         $o = '';
643         ob_start();
644         $table->out($rowsperpage, $displaylinks);
645         $o = ob_get_contents();
646         ob_end_clean();
648         return $o;
649     }
651     /**
652      * Helper method dealing with the fact we can not just fetch the output of moodleforms
653      *
654      * @param moodleform $mform
655      * @return string HTML
656      */
657     protected function moodleform(moodleform $mform) {
659         $o = '';
660         ob_start();
661         $mform->display();
662         $o = ob_get_contents();
663         ob_end_clean();
665         return $o;
666     }