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