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