MDL-31295: Allow granting individual extension dates to students for mod_assign
[moodle.git] / mod / assign / renderer.php
CommitLineData
bbd0e548
DW
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/>.
16
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 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/** Include locallib.php */
28require_once($CFG->dirroot . '/mod/assign/locallib.php');
29
30
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 */
38class mod_assign_renderer extends plugin_renderer_base {
39
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 }
52
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>';
65
66 if ($tree->portfolioform) {
67 $html .= $tree->portfolioform;
68 }
69 return $html;
70 }
71
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 }
88
bf78ebd6
DW
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) {
2a4fbc32
SH
95 $url = new moodle_url('/mod/assign/view.php', array('id' => $result->coursemoduleid, 'action'=>'grading'));
96
bf78ebd6
DW
97 $o = '';
98 $o .= $this->output->heading(get_string('quickgradingresult', 'assign'), 4);
bf78ebd6 99 $o .= $this->output->notification($result->message);
2a4fbc32 100 $o .= $this->output->continue_button($url);
bf78ebd6
DW
101 return $o;
102 }
103
bbd0e548
DW
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 = '';
bf78ebd6
DW
111 if ($form->jsinitfunction) {
112 $this->page->requires->js_init_call($form->jsinitfunction, array());
113 }
bbd0e548
DW
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 }
119
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 = '';
128
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();
142
143 return $o;
144 }
145
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 = '';
154
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));
158
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
162
163 $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
164
165 foreach ($page->notifications as $notification) {
166 $o .= $this->output->notification($notification);
167 }
168
169 $o .= $this->output->continue_button($cancelurl);
170 } else {
94f26900
DW
171 // All submission plugins ready - show the confirmation form (may contain submission statement)
172 $o .= $this->moodleform($page->confirmform);
bbd0e548
DW
173 }
174 $o .= $this->output->container_end();
175
176
177 return $o;
178 }
179
180 /**
181 * Page is done - render the footer
182 *
183 * @return void
184 */
185 public function render_footer() {
186 return $this->output->footer();
187 }
188
189 /**
190 * render the header
191 *
192 * @param assign_header $header
193 * @return string
194 */
195 public function render_assign_header(assign_header $header) {
196 $o = '';
197
198 if ($header->subpage) {
199 $this->page->navbar->add($header->subpage);
200 }
201
202 $this->page->set_title(get_string('pluginname', 'assign'));
203 $this->page->set_heading($header->assign->name);
204
205 $o .= $this->output->header();
a1e54f4d
DW
206 if ($header->preface) {
207 $o .= $header->preface;
208 }
bbd0e548
DW
209 $o .= $this->output->heading(format_string($header->assign->name,false, array('context' => $header->context)));
210
211 if ($header->showintro) {
212 $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
213 $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
214 $o .= $this->output->box_end();
215 }
216
217 return $o;
218 }
219
220 /**
221 * render a table containing the current status of the grading process
222 *
223 * @param assign_grading_summary $summary
224 * @return string
225 */
226 public function render_assign_grading_summary(assign_grading_summary $summary) {
227 // create a table for the data
228 $o = '';
229 $o .= $this->output->container_start('gradingsummary');
230 $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
231 $o .= $this->output->box_start('boxaligncenter gradingsummarytable');
232 $t = new html_table();
233
234 // status
235 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
236 $summary->participantcount);
237
238 // drafts
239 if ($summary->submissiondraftsenabled) {
240 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
241 $summary->submissiondraftscount);
242 }
243
244 // submitted for grading
245 if ($summary->submissionsenabled) {
246 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
247 $summary->submissionssubmittedcount);
f70079b9
DW
248 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
249 $summary->submissionsneedgradingcount);
bbd0e548
DW
250 }
251
252 $time = time();
253 if ($summary->duedate) {
254 // due date
255 // submitted for grading
256 $duedate = $summary->duedate;
257 $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
258 userdate($duedate));
259
260 // time remaining
261 $due = '';
262 if ($duedate - $time <= 0) {
263 $due = get_string('assignmentisdue', 'assign');
264 } else {
265 $due = format_time($duedate - $time);
266 }
267 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
9e795179
DW
268
269 if ($duedate < $time) {
270 $cutoffdate = $summary->cutoffdate;
271 if ($cutoffdate) {
272 if ($cutoffdate > $time) {
273 $late = get_string('latesubmissionsaccepted', 'assign');
274 } else {
275 $late = get_string('nomoresubmissionsaccepted', 'assign');
276 }
277 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
278 }
279 }
280
bbd0e548
DW
281 }
282
283 // all done - write the table
284 $o .= html_writer::table($t);
285 $o .= $this->output->box_end();
286
287 // link to the grading page
d9a88f42
DW
288 $o .= $this->output->container_start('submissionlinks');
289 $o .= $this->output->action_link(new moodle_url('/mod/assign/view.php',
bbd0e548
DW
290 array('id' => $summary->coursemoduleid,
291 'action'=>'grading')),
d9a88f42
DW
292 get_string('viewgrading', 'assign'));
293 $o .= $this->output->container_end();
bbd0e548
DW
294
295 // close the container and insert a spacer
296 $o .= $this->output->container_end();
297
298 return $o;
299 }
300
301 /**
302 * render a table containing all the current grades and feedback
303 *
304 * @param assign_feedback_status $status
305 * @return string
306 */
307 public function render_assign_feedback_status(assign_feedback_status $status) {
308 global $DB, $CFG;
309 $o = '';
310
311 $o .= $this->output->container_start('feedback');
312 $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
313 $o .= $this->output->box_start('boxaligncenter feedbacktable');
314 $t = new html_table();
315
316 $row = new html_table_row();
317 $cell1 = new html_table_cell(get_string('grade'));
318 $cell2 = new html_table_cell($status->gradefordisplay);
319 $row->cells = array($cell1, $cell2);
320 $t->data[] = $row;
321
322 $row = new html_table_row();
323 $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
324 $cell2 = new html_table_cell(userdate($status->gradeddate));
325 $row->cells = array($cell1, $cell2);
326 $t->data[] = $row;
327
328 if ($status->grader) {
329 $row = new html_table_row();
330 $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
331 $cell2 = new html_table_cell($this->output->user_picture($status->grader) . $this->output->spacer(array('width'=>30)) . fullname($status->grader));
332 $row->cells = array($cell1, $cell2);
333 $t->data[] = $row;
334 }
335
336 foreach ($status->feedbackplugins as $plugin) {
8c0cf5be 337 if ($plugin->is_enabled() && $plugin->is_visible() && !empty($status->grade) && !$plugin->is_empty($status->grade)) {
bbd0e548
DW
338 $row = new html_table_row();
339 $cell1 = new html_table_cell($plugin->get_name());
340 $pluginfeedback = new assign_feedback_plugin_feedback($plugin, $status->grade, assign_feedback_plugin_feedback::SUMMARY, $status->coursemoduleid, $status->returnaction, $status->returnparams);
341 $cell2 = new html_table_cell($this->render($pluginfeedback));
342 $row->cells = array($cell1, $cell2);
343 $t->data[] = $row;
344 }
345 }
346
347
348 $o .= html_writer::table($t);
349 $o .= $this->output->box_end();
350
351 $o .= $this->output->container_end();
352 return $o;
353 }
354
355 /**
356 * render a table containing the current status of the submission
357 *
358 * @param assign_submission_status $status
359 * @return string
360 */
361 public function render_assign_submission_status(assign_submission_status $status) {
362 $o = '';
363 $o .= $this->output->container_start('submissionstatustable');
364 $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
365 $time = time();
366
367 if ($status->allowsubmissionsfromdate &&
368 $time <= $status->allowsubmissionsfromdate) {
369 $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
370 if ($status->alwaysshowdescription) {
371 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
372 } else {
373 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
374 }
375 $o .= $this->output->box_end();
376 }
377 $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
378
379 $t = new html_table();
380
381 $row = new html_table_row();
382 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
383 if ($status->submission) {
384 $cell2 = new html_table_cell(get_string('submissionstatus_' . $status->submission->status, 'assign'));
385 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
386 } else {
387 if (!$status->submissionsenabled) {
388 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
389 } else {
390 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
391 }
392 }
393 $row->cells = array($cell1, $cell2);
394 $t->data[] = $row;
395
396 // status
397 if ($status->locked) {
398 $row = new html_table_row();
399 $cell1 = new html_table_cell();
400 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
401 $cell2->attributes = array('class'=>'submissionlocked');
402 $row->cells = array($cell1, $cell2);
403 $t->data[] = $row;
404 }
405
406 // grading status
407 $row = new html_table_row();
408 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
409
410 if ($status->graded) {
411 $cell2 = new html_table_cell(get_string('graded', 'assign'));
412 $cell2->attributes = array('class'=>'submissiongraded');
413 } else {
414 $cell2 = new html_table_cell(get_string('notgraded', 'assign'));
415 $cell2->attributes = array('class'=>'submissionnotgraded');
416 }
417 $row->cells = array($cell1, $cell2);
418 $t->data[] = $row;
419
420
421 $duedate = $status->duedate;
9e795179 422 if ($duedate > 0) {
bbd0e548
DW
423 $row = new html_table_row();
424 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
425 $cell2 = new html_table_cell(userdate($duedate));
426 $row->cells = array($cell1, $cell2);
427 $t->data[] = $row;
428
9e795179
DW
429 if ($status->view == assign_submission_status::GRADER_VIEW) {
430 if ($status->cutoffdate) {
431 $row = new html_table_row();
432 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
433 $cell2 = new html_table_cell(userdate($status->cutoffdate));
434 $row->cells = array($cell1, $cell2);
435 $t->data[] = $row;
436 }
437 }
438
439 if ($status->extensionduedate) {
440 $row = new html_table_row();
441 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
442 $cell2 = new html_table_cell(userdate($status->extensionduedate));
443 $row->cells = array($cell1, $cell2);
444 $t->data[] = $row;
445 $duedate = $status->extensionduedate;
446 }
447
448 // Time remaining.
bbd0e548
DW
449 $row = new html_table_row();
450 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
451 if ($duedate - $time <= 0) {
84a8492a 452 if (!$status->submission || $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
bbd0e548
DW
453 if ($status->submissionsenabled) {
454 $cell2 = new html_table_cell(get_string('overdue', 'assign', format_time($time - $duedate)));
455 $cell2->attributes = array('class'=>'overdue');
456 } else {
457 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
458 }
459 } else {
460 if ($status->submission->timemodified > $duedate) {
461 $cell2 = new html_table_cell(get_string('submittedlate', 'assign', format_time($status->submission->timemodified - $duedate)));
462 $cell2->attributes = array('class'=>'latesubmission');
463 } else {
464 $cell2 = new html_table_cell(get_string('submittedearly', 'assign', format_time($status->submission->timemodified - $duedate)));
465 $cell2->attributes = array('class'=>'earlysubmission');
466 }
467 }
468 } else {
469 $cell2 = new html_table_cell(format_time($duedate - $time));
470 }
471 $row->cells = array($cell1, $cell2);
472 $t->data[] = $row;
473 }
474
9e795179
DW
475 // Show graders whether this submission is editable by students.
476 if ($status->view == assign_submission_status::GRADER_VIEW) {
477 $row = new html_table_row();
478 $cell1 = new html_table_cell(get_string('open', 'assign'));
479 if ($status->canedit) {
480 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
481 $cell2->attributes = array('class'=>'submissioneditable');
482 } else {
483 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
484 $cell2->attributes = array('class'=>'submissionnoteditable');
485 }
486 $row->cells = array($cell1, $cell2);
487 $t->data[] = $row;
488 }
489
490 // Last modified.
bbd0e548
DW
491 if ($status->submission) {
492 $row = new html_table_row();
493 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
494 $cell2 = new html_table_cell(userdate($status->submission->timemodified));
495 $row->cells = array($cell1, $cell2);
496 $t->data[] = $row;
497
498 foreach ($status->submissionplugins as $plugin) {
499 if ($plugin->is_enabled() && $plugin->is_visible() && !$plugin->is_empty($status->submission)) {
500 $row = new html_table_row();
501 $cell1 = new html_table_cell($plugin->get_name());
9e795179
DW
502 $pluginsubmission = new assign_submission_plugin_submission($plugin,
503 $status->submission,
504 assign_submission_plugin_submission::SUMMARY,
505 $status->coursemoduleid,
506 $status->returnaction,
507 $status->returnparams);
bbd0e548
DW
508 $cell2 = new html_table_cell($this->render($pluginsubmission));
509 $row->cells = array($cell1, $cell2);
510 $t->data[] = $row;
511 }
512 }
513 }
514
515
516 $o .= html_writer::table($t);
517 $o .= $this->output->box_end();
518
9e795179
DW
519 // Links.
520 if ($status->view == assign_submission_status::STUDENT_VIEW) {
521 if ($status->canedit) {
522 if (!$status->submission) {
523 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
524 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
525 get_string('addsubmission', 'assign'), 'get');
526 } else {
527 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
528 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
529 get_string('editsubmission', 'assign'), 'get');
530 }
caff10a0 531 }
bbd0e548 532
9e795179
DW
533 if ($status->cansubmit) {
534 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
535 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
536 get_string('submitassignment', 'assign'), 'get');
537 $o .= $this->output->box_start('boxaligncenter submithelp');
538 $o .= get_string('submitassignment_help', 'assign');
539 $o .= $this->output->box_end();
540 }
bbd0e548
DW
541 }
542
543 $o .= $this->output->container_end();
544 return $o;
545 }
546
547 /**
548 * render a submission plugin submission
549 *
550 * @param assign_submission_plugin_submission $submissionplugin
551 * @return string
552 */
553 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
554 $o = '';
555
556 if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
557 $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($submissionplugin->plugin->get_subtype(), strlen('assign')), 'mod_assign'));
558 $link = '';
559 $showviewlink = false;
560 $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, $showviewlink);
561 if ($showviewlink) {
562 $link = $this->output->action_link(
563 new moodle_url('/mod/assign/view.php',
564 array('id' => $submissionplugin->coursemoduleid,
565 'sid'=>$submissionplugin->submission->id,
566 'plugin'=>$submissionplugin->plugin->get_type(),
567 'action'=>'viewplugin' . $submissionplugin->plugin->get_subtype(),
568 'returnaction'=>$submissionplugin->returnaction,
569 'returnparams'=>http_build_query($submissionplugin->returnparams))),
570 $icon);
571
572 $link .= $this->output->spacer(array('width'=>15));
573 }
574
575 $o .= $link . $summary;
576 } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
577 $o .= $this->output->box_start('boxaligncenter submissionfull');
578 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
579 $o .= $this->output->box_end();
580 }
581
582 return $o;
583 }
584
585 /**
586 * render the grading table
587 *
588 * @param assign_grading_table $table
589 * @return string
590 */
591 public function render_assign_grading_table(assign_grading_table $table) {
592 $o = '';
593 $o .= $this->output->box_start('boxaligncenter gradingtable');
594 $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
595 $this->page->requires->string_for_js('nousersselected', 'assign');
9e795179 596 $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
bbd0e548 597 $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
bbd0e548 598 $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
9e795179 599 $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
bbd0e548
DW
600 $this->page->requires->string_for_js('editaction', 'assign');
601 // need to get from prefs
602 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
603 $o .= $this->output->box_end();
604
605 return $o;
606 }
607
608 /**
609 * Render a feedback plugin feedback
610 *
611 * @param assign_feedback_plugin_feedback $feedbackplugin
612 * @return string
613 */
614 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
615 $o = '';
616
617 if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
618 $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($feedbackplugin->plugin->get_subtype(), strlen('assign')), 'mod_assign'));
619 $link = '';
620 $showviewlink = false;
621 $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
622 if ($showviewlink) {
623 $link = $this->output->action_link(
624 new moodle_url('/mod/assign/view.php',
625 array('id' => $feedbackplugin->coursemoduleid,
626 'gid'=>$feedbackplugin->grade->id,
627 'plugin'=>$feedbackplugin->plugin->get_type(),
628 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
629 'returnaction'=>$feedbackplugin->returnaction,
630 'returnparams'=>http_build_query($feedbackplugin->returnparams))),
631 $icon);
632 $link .= $this->output->spacer(array('width'=>15));
633 }
634
635 $o .= $link . $summary;
636 } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
637 $o .= $this->output->box_start('boxaligncenter feedbackfull');
638 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
639 $o .= $this->output->box_end();
640 }
641
642 return $o;
643 }
644
645
646
647 /**
648 * Internal function - creates htmls structure suitable for YUI tree.
649 *
650 * @param assign_files $tree
651 * @param array $dir
652 * @return string
653 */
654 protected function htmllize_tree(assign_files $tree, $dir) {
655 global $CFG;
656 $yuiconfig = array();
657 $yuiconfig['type'] = 'html';
658
659 if (empty($dir['subdirs']) and empty($dir['files'])) {
660 return '';
661 }
662
663 $result = '<ul>';
664 foreach ($dir['subdirs'] as $subdir) {
559276b1 665 $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
bbd0e548
DW
666 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
667 }
668
669 foreach ($dir['files'] as $file) {
670 $filename = $file->get_filename();
bbd0e548
DW
671 if ($CFG->enableplagiarism) {
672 require_once($CFG->libdir.'/plagiarismlib.php');
673 $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
674 } else {
675 $plagiarsmlinks = '';
676 }
559276b1 677 $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
bbd0e548
DW
678 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
679 }
680
681 $result .= '</ul>';
682
683 return $result;
684 }
685
686 /**
687 * Helper method dealing with the fact we can not just fetch the output of flexible_table
688 *
689 * @param flexible_table $table The table to render
690 * @param int $rowsperpage How many assignments to render in a page
691 * @param bool $displaylinks - Whether to render links in the table (e.g. downloads would not enable this)
692 * @return string HTML
693 */
694 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
695
696 $o = '';
697 ob_start();
698 $table->out($rowsperpage, $displaylinks);
699 $o = ob_get_contents();
700 ob_end_clean();
701
702 return $o;
703 }
704
705 /**
706 * Helper method dealing with the fact we can not just fetch the output of moodleforms
707 *
708 * @param moodleform $mform
709 * @return string HTML
710 */
711 protected function moodleform(moodleform $mform) {
712
713 $o = '';
714 ob_start();
715 $mform->display();
716 $o = ob_get_contents();
717 ob_end_clean();
718
719 return $o;
720 }
721
722}
723