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