MDL-35375: Ensure the assignment grading table is always sorted by at least one uniqu...
[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 134 if ($summary->blindmarking) {
df47b77f 135 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser;
b473171a
DW
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) {
df47b77f
DW
346 if ($plugin->is_enabled() &&
347 $plugin->is_visible() &&
348 $plugin->has_user_summary() &&
349 !empty($status->grade) &&
350 !$plugin->is_empty($status->grade)) {
351
bbd0e548
DW
352 $row = new html_table_row();
353 $cell1 = new html_table_cell($plugin->get_name());
354 $pluginfeedback = new assign_feedback_plugin_feedback($plugin, $status->grade, assign_feedback_plugin_feedback::SUMMARY, $status->coursemoduleid, $status->returnaction, $status->returnparams);
355 $cell2 = new html_table_cell($this->render($pluginfeedback));
356 $row->cells = array($cell1, $cell2);
357 $t->data[] = $row;
358 }
359 }
360
361
362 $o .= html_writer::table($t);
363 $o .= $this->output->box_end();
364
365 $o .= $this->output->container_end();
366 return $o;
367 }
368
369 /**
370 * render a table containing the current status of the submission
371 *
372 * @param assign_submission_status $status
373 * @return string
374 */
375 public function render_assign_submission_status(assign_submission_status $status) {
376 $o = '';
377 $o .= $this->output->container_start('submissionstatustable');
378 $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
379 $time = time();
380
381 if ($status->allowsubmissionsfromdate &&
382 $time <= $status->allowsubmissionsfromdate) {
383 $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
384 if ($status->alwaysshowdescription) {
385 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
386 } else {
387 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', userdate($status->allowsubmissionsfromdate));
388 }
389 $o .= $this->output->box_end();
390 }
391 $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
392
393 $t = new html_table();
394
12a1a0da
DW
395 if ($status->teamsubmissionenabled) {
396 $row = new html_table_row();
397 $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
398 $group = $status->submissiongroup;
399 if ($group) {
400 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
401 } else {
402 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
403 }
404 $row->cells = array($cell1, $cell2);
405 $t->data[] = $row;
406 }
407
bbd0e548
DW
408 $row = new html_table_row();
409 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
12a1a0da
DW
410 if (!$status->teamsubmissionenabled) {
411 if ($status->submission) {
412 $cell2 = new html_table_cell(get_string('submissionstatus_' . $status->submission->status, 'assign'));
413 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
414 } else {
415 if (!$status->submissionsenabled) {
416 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
417 } else {
418 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
419 }
420 }
421 $row->cells = array($cell1, $cell2);
422 $t->data[] = $row;
bbd0e548 423 } else {
12a1a0da
DW
424 $row = new html_table_row();
425 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
426 if ($status->teamsubmission) {
427 $submissionsummary = get_string('submissionstatus_' . $status->teamsubmission->status, 'assign');
428 $groupid = 0;
429 if ($status->submissiongroup) {
430 $groupid = $status->submissiongroup->id;
431 }
432
433 $members = $status->submissiongroupmemberswhoneedtosubmit;
434 $userslist = array();
435 foreach ($members as $member) {
436 $url = new moodle_url('/user/view.php', array('id' => $member->id, 'course'=>$status->courseid));
88cfe469
DW
437 if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
438 $userslist[] = $member->alias;
439 } else {
440 $userslist[] = $this->output->action_link($url, fullname($member, $status->canviewfullnames));
441 }
12a1a0da
DW
442 }
443 if (count($userslist) > 0) {
444 $userstr = join(', ', $userslist);
445 $submissionsummary .= $this->output->container(get_string('userswhoneedtosubmit', 'assign', $userstr));
446 }
447
448 $cell2 = new html_table_cell($submissionsummary);
449 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
bbd0e548
DW
450 } else {
451 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
12a1a0da
DW
452 if (!$status->submissionsenabled) {
453 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
454 } else {
455 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
456 }
bbd0e548 457 }
12a1a0da
DW
458 $row->cells = array($cell1, $cell2);
459 $t->data[] = $row;
bbd0e548 460 }
bbd0e548
DW
461
462 // status
463 if ($status->locked) {
464 $row = new html_table_row();
465 $cell1 = new html_table_cell();
466 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
467 $cell2->attributes = array('class'=>'submissionlocked');
468 $row->cells = array($cell1, $cell2);
469 $t->data[] = $row;
470 }
471
472 // grading status
473 $row = new html_table_row();
474 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
475
476 if ($status->graded) {
477 $cell2 = new html_table_cell(get_string('graded', 'assign'));
478 $cell2->attributes = array('class'=>'submissiongraded');
479 } else {
480 $cell2 = new html_table_cell(get_string('notgraded', 'assign'));
481 $cell2->attributes = array('class'=>'submissionnotgraded');
482 }
483 $row->cells = array($cell1, $cell2);
484 $t->data[] = $row;
485
486
487 $duedate = $status->duedate;
9e795179 488 if ($duedate > 0) {
bbd0e548
DW
489 $row = new html_table_row();
490 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
491 $cell2 = new html_table_cell(userdate($duedate));
492 $row->cells = array($cell1, $cell2);
493 $t->data[] = $row;
494
9e795179
DW
495 if ($status->view == assign_submission_status::GRADER_VIEW) {
496 if ($status->cutoffdate) {
497 $row = new html_table_row();
498 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
499 $cell2 = new html_table_cell(userdate($status->cutoffdate));
500 $row->cells = array($cell1, $cell2);
501 $t->data[] = $row;
502 }
503 }
504
505 if ($status->extensionduedate) {
506 $row = new html_table_row();
507 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
508 $cell2 = new html_table_cell(userdate($status->extensionduedate));
509 $row->cells = array($cell1, $cell2);
510 $t->data[] = $row;
511 $duedate = $status->extensionduedate;
512 }
513
514 // Time remaining.
bbd0e548
DW
515 $row = new html_table_row();
516 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
517 if ($duedate - $time <= 0) {
84a8492a 518 if (!$status->submission || $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
bbd0e548
DW
519 if ($status->submissionsenabled) {
520 $cell2 = new html_table_cell(get_string('overdue', 'assign', format_time($time - $duedate)));
521 $cell2->attributes = array('class'=>'overdue');
522 } else {
523 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
524 }
525 } else {
526 if ($status->submission->timemodified > $duedate) {
527 $cell2 = new html_table_cell(get_string('submittedlate', 'assign', format_time($status->submission->timemodified - $duedate)));
528 $cell2->attributes = array('class'=>'latesubmission');
529 } else {
530 $cell2 = new html_table_cell(get_string('submittedearly', 'assign', format_time($status->submission->timemodified - $duedate)));
531 $cell2->attributes = array('class'=>'earlysubmission');
532 }
533 }
534 } else {
535 $cell2 = new html_table_cell(format_time($duedate - $time));
536 }
537 $row->cells = array($cell1, $cell2);
538 $t->data[] = $row;
539 }
540
9e795179
DW
541 // Show graders whether this submission is editable by students.
542 if ($status->view == assign_submission_status::GRADER_VIEW) {
543 $row = new html_table_row();
544 $cell1 = new html_table_cell(get_string('open', 'assign'));
545 if ($status->canedit) {
546 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
547 $cell2->attributes = array('class'=>'submissioneditable');
548 } else {
549 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
550 $cell2->attributes = array('class'=>'submissionnoteditable');
551 }
ec32d068
RW
552 }
553
554 // Grading criteria preview.
555 if (!empty($status->gradingcontrollerpreview)) {
556 $row = new html_table_row();
557 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
558 $cell2 = new html_table_cell($status->gradingcontrollerpreview);
9e795179
DW
559 $row->cells = array($cell1, $cell2);
560 $t->data[] = $row;
561 }
562
563 // Last modified.
12a1a0da
DW
564 $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
565 if ($submission) {
bbd0e548
DW
566 $row = new html_table_row();
567 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
12a1a0da 568 $cell2 = new html_table_cell(userdate($submission->timemodified));
bbd0e548
DW
569 $row->cells = array($cell1, $cell2);
570 $t->data[] = $row;
571
572 foreach ($status->submissionplugins as $plugin) {
df47b77f
DW
573 if ($plugin->is_enabled() &&
574 $plugin->is_visible() &&
575 $plugin->has_user_summary() &&
576 !$plugin->is_empty($submission)) {
577
bbd0e548
DW
578 $row = new html_table_row();
579 $cell1 = new html_table_cell($plugin->get_name());
9e795179 580 $pluginsubmission = new assign_submission_plugin_submission($plugin,
dd1fe178 581 $submission,
9e795179
DW
582 assign_submission_plugin_submission::SUMMARY,
583 $status->coursemoduleid,
584 $status->returnaction,
585 $status->returnparams);
bbd0e548
DW
586 $cell2 = new html_table_cell($this->render($pluginsubmission));
587 $row->cells = array($cell1, $cell2);
588 $t->data[] = $row;
589 }
590 }
591 }
592
593
594 $o .= html_writer::table($t);
595 $o .= $this->output->box_end();
596
9e795179
DW
597 // Links.
598 if ($status->view == assign_submission_status::STUDENT_VIEW) {
599 if ($status->canedit) {
cd01491c 600 if (!$submission) {
9e795179
DW
601 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
602 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
603 get_string('addsubmission', 'assign'), 'get');
604 } else {
605 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
606 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
607 get_string('editsubmission', 'assign'), 'get');
608 }
caff10a0 609 }
bbd0e548 610
9e795179
DW
611 if ($status->cansubmit) {
612 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
613 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
614 get_string('submitassignment', 'assign'), 'get');
615 $o .= $this->output->box_start('boxaligncenter submithelp');
616 $o .= get_string('submitassignment_help', 'assign');
617 $o .= $this->output->box_end();
618 }
bbd0e548
DW
619 }
620
621 $o .= $this->output->container_end();
622 return $o;
623 }
624
625 /**
626 * render a submission plugin submission
627 *
628 * @param assign_submission_plugin_submission $submissionplugin
629 * @return string
630 */
631 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
632 $o = '';
633
634 if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
635 $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($submissionplugin->plugin->get_subtype(), strlen('assign')), 'mod_assign'));
636 $link = '';
637 $showviewlink = false;
638 $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, $showviewlink);
639 if ($showviewlink) {
640 $link = $this->output->action_link(
641 new moodle_url('/mod/assign/view.php',
642 array('id' => $submissionplugin->coursemoduleid,
643 'sid'=>$submissionplugin->submission->id,
644 'plugin'=>$submissionplugin->plugin->get_type(),
645 'action'=>'viewplugin' . $submissionplugin->plugin->get_subtype(),
646 'returnaction'=>$submissionplugin->returnaction,
647 'returnparams'=>http_build_query($submissionplugin->returnparams))),
648 $icon);
649
650 $link .= $this->output->spacer(array('width'=>15));
651 }
652
653 $o .= $link . $summary;
654 } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
655 $o .= $this->output->box_start('boxaligncenter submissionfull');
656 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
657 $o .= $this->output->box_end();
658 }
659
660 return $o;
661 }
662
663 /**
664 * render the grading table
665 *
666 * @param assign_grading_table $table
667 * @return string
668 */
669 public function render_assign_grading_table(assign_grading_table $table) {
670 $o = '';
671 $o .= $this->output->box_start('boxaligncenter gradingtable');
df47b77f 672
bbd0e548
DW
673 $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
674 $this->page->requires->string_for_js('nousersselected', 'assign');
9e795179 675 $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
bbd0e548 676 $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
bbd0e548 677 $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
9e795179 678 $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
bbd0e548 679 $this->page->requires->string_for_js('editaction', 'assign');
df47b77f
DW
680 foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
681 foreach ($operations as $operation => $description) {
682 $this->page->requires->string_for_js('batchoperationconfirm' . $operation, 'assignfeedback_' . $plugin);
683 }
684 }
bbd0e548
DW
685 // need to get from prefs
686 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
687 $o .= $this->output->box_end();
688
689 return $o;
690 }
691
692 /**
693 * Render a feedback plugin feedback
694 *
695 * @param assign_feedback_plugin_feedback $feedbackplugin
696 * @return string
697 */
698 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
699 $o = '';
700
701 if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
702 $icon = $this->output->pix_icon('t/preview', get_string('view' . substr($feedbackplugin->plugin->get_subtype(), strlen('assign')), 'mod_assign'));
703 $link = '';
704 $showviewlink = false;
705 $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
706 if ($showviewlink) {
707 $link = $this->output->action_link(
708 new moodle_url('/mod/assign/view.php',
709 array('id' => $feedbackplugin->coursemoduleid,
710 'gid'=>$feedbackplugin->grade->id,
711 'plugin'=>$feedbackplugin->plugin->get_type(),
712 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
713 'returnaction'=>$feedbackplugin->returnaction,
714 'returnparams'=>http_build_query($feedbackplugin->returnparams))),
715 $icon);
716 $link .= $this->output->spacer(array('width'=>15));
717 }
718
719 $o .= $link . $summary;
720 } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
721 $o .= $this->output->box_start('boxaligncenter feedbackfull');
722 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
723 $o .= $this->output->box_end();
724 }
725
726 return $o;
727 }
728
729
730
731 /**
732 * Internal function - creates htmls structure suitable for YUI tree.
733 *
734 * @param assign_files $tree
735 * @param array $dir
736 * @return string
737 */
738 protected function htmllize_tree(assign_files $tree, $dir) {
739 global $CFG;
740 $yuiconfig = array();
741 $yuiconfig['type'] = 'html';
742
743 if (empty($dir['subdirs']) and empty($dir['files'])) {
744 return '';
745 }
746
747 $result = '<ul>';
748 foreach ($dir['subdirs'] as $subdir) {
559276b1 749 $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
bbd0e548
DW
750 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
751 }
752
753 foreach ($dir['files'] as $file) {
754 $filename = $file->get_filename();
bbd0e548
DW
755 if ($CFG->enableplagiarism) {
756 require_once($CFG->libdir.'/plagiarismlib.php');
757 $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
758 } else {
759 $plagiarsmlinks = '';
760 }
559276b1 761 $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
bbd0e548
DW
762 $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
763 }
764
765 $result .= '</ul>';
766
767 return $result;
768 }
769
770 /**
771 * Helper method dealing with the fact we can not just fetch the output of flexible_table
772 *
773 * @param flexible_table $table The table to render
774 * @param int $rowsperpage How many assignments to render in a page
775 * @param bool $displaylinks - Whether to render links in the table (e.g. downloads would not enable this)
776 * @return string HTML
777 */
778 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
779
780 $o = '';
781 ob_start();
782 $table->out($rowsperpage, $displaylinks);
783 $o = ob_get_contents();
784 ob_end_clean();
785
786 return $o;
787 }
788
789 /**
790 * Helper method dealing with the fact we can not just fetch the output of moodleforms
791 *
792 * @param moodleform $mform
793 * @return string HTML
794 */
795 protected function moodleform(moodleform $mform) {
796
797 $o = '';
798 ob_start();
799 $mform->display();
800 $o = ob_get_contents();
801 ob_end_clean();
802
803 return $o;
804 }
805
806}
807