MDL-44732 add cli script for execution of scheduled tasks
[moodle.git] / mod / assign / renderer.php
blob8633c819fed1023de500dd956f098637023e4741
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.
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/>.
17 /**
18 * This file contains a renderer for the assignment class
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
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->dirroot . '/mod/assign/locallib.php');
29 /**
30 * A custom renderer class that extends the plugin_renderer_base and is used by the assign module.
32 * @package mod_assign
33 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 class mod_assign_renderer extends plugin_renderer_base {
38 /**
39 * Rendering assignment files
41 * @param context $context
42 * @param int $userid
43 * @param string $filearea
44 * @param string $component
45 * @return string
47 public function assign_files(context $context, $userid, $filearea, $component) {
48 return $this->render(new assign_files($context, $userid, $filearea, $component));
51 /**
52 * Rendering assignment files
54 * @param assign_files $tree
55 * @return string
57 public function render_assign_files(assign_files $tree) {
58 $this->htmlid = html_writer::random_id('assign_files_tree');
59 $this->page->requires->js_init_call('M.mod_assign.init_tree', array(true, $this->htmlid));
60 $html = '<div id="'.$this->htmlid.'">';
61 $html .= $this->htmllize_tree($tree, $tree->dir);
62 $html .= '</div>';
64 if ($tree->portfolioform) {
65 $html .= $tree->portfolioform;
67 return $html;
70 /**
71 * Utility function to add a row of data to a table with 2 columns. Modified
72 * the table param and does not return a value
74 * @param html_table $table The table to append the row of data to
75 * @param string $first The first column text
76 * @param string $second The second column text
77 * @return void
79 private function add_table_row_tuple(html_table $table, $first, $second) {
80 $row = new html_table_row();
81 $cell1 = new html_table_cell($first);
82 $cell2 = new html_table_cell($second);
83 $row->cells = array($cell1, $cell2);
84 $table->data[] = $row;
87 /**
88 * Render a grading message notification
89 * @param assign_gradingmessage $result The result to render
90 * @return string
92 public function render_assign_gradingmessage(assign_gradingmessage $result) {
93 $urlparams = array('id' => $result->coursemoduleid, 'action'=>'grading');
94 $url = new moodle_url('/mod/assign/view.php', $urlparams);
96 $o = '';
97 $o .= $this->output->heading($result->heading, 4);
98 $o .= $this->output->notification($result->message);
99 $o .= $this->output->continue_button($url);
100 return $o;
104 * Render the generic form
105 * @param assign_form $form The form to render
106 * @return string
108 public function render_assign_form(assign_form $form) {
109 $o = '';
110 if ($form->jsinitfunction) {
111 $this->page->requires->js_init_call($form->jsinitfunction, array());
113 $o .= $this->output->box_start('boxaligncenter ' . $form->classname);
114 $o .= $this->moodleform($form->form);
115 $o .= $this->output->box_end();
116 return $o;
120 * Render the user summary
122 * @param assign_user_summary $summary The user summary to render
123 * @return string
125 public function render_assign_user_summary(assign_user_summary $summary) {
126 $o = '';
127 $supendedclass = '';
128 $suspendedicon = '';
130 if (!$summary->user) {
131 return;
134 if ($summary->suspendeduser) {
135 $supendedclass = ' usersuspended';
136 $suspendedstring = get_string('userenrolmentsuspended', 'grades');
137 $suspendedicon = ' ' . html_writer::empty_tag('img', array('src' => $this->pix_url('i/enrolmentsuspended'),
138 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon'));
140 $o .= $this->output->container_start('usersummary');
141 $o .= $this->output->box_start('boxaligncenter usersummarysection'.$supendedclass);
142 if ($summary->blindmarking) {
143 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser.$suspendedicon;
144 } else {
145 $o .= $this->output->user_picture($summary->user);
146 $o .= $this->output->spacer(array('width'=>30));
147 $urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid);
148 $url = new moodle_url('/user/view.php', $urlparams);
149 $fullname = fullname($summary->user, $summary->viewfullnames);
150 $extrainfo = array();
151 foreach ($summary->extrauserfields as $extrafield) {
152 $extrainfo[] = $summary->user->$extrafield;
154 if (count($extrainfo)) {
155 $fullname .= ' (' . implode(', ', $extrainfo) . ')';
157 $fullname .= $suspendedicon;
158 $o .= $this->output->action_link($url, $fullname);
160 $o .= $this->output->box_end();
161 $o .= $this->output->container_end();
163 return $o;
167 * Render the submit for grading page
169 * @param assign_submit_for_grading_page $page
170 * @return string
172 public function render_assign_submit_for_grading_page($page) {
173 $o = '';
175 $o .= $this->output->container_start('submitforgrading');
176 $o .= $this->output->heading(get_string('submitassignment', 'assign'), 3);
177 $o .= $this->output->spacer(array('height'=>30));
179 $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
180 if (count($page->notifications)) {
181 // At least one of the submission plugins is not ready for submission.
183 $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
185 foreach ($page->notifications as $notification) {
186 $o .= $this->output->notification($notification);
189 $o .= $this->output->continue_button($cancelurl);
190 } else {
191 // All submission plugins ready - show the confirmation form.
192 $o .= $this->output->box_start('generalbox submitconfirm');
193 $o .= $this->moodleform($page->confirmform);
194 $o .= $this->output->box_end();
196 $o .= $this->output->container_end();
198 return $o;
202 * Page is done - render the footer.
204 * @return void
206 public function render_footer() {
207 return $this->output->footer();
211 * Render the header.
213 * @param assign_header $header
214 * @return string
216 public function render_assign_header(assign_header $header) {
217 $o = '';
219 if ($header->subpage) {
220 $this->page->navbar->add($header->subpage);
223 $this->page->set_title(get_string('pluginname', 'assign'));
224 $this->page->set_heading($this->page->course->fullname);
226 $o .= $this->output->header();
227 $heading = format_string($header->assign->name, false, array('context' => $header->context));
228 $o .= $this->output->heading($heading);
229 if ($header->preface) {
230 $o .= $header->preface;
233 if ($header->showintro) {
234 $o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
235 $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
236 $o .= $this->output->box_end();
239 return $o;
243 * Render a table containing the current status of the grading process.
245 * @param assign_grading_summary $summary
246 * @return string
248 public function render_assign_grading_summary(assign_grading_summary $summary) {
249 // Create a table for the data.
250 $o = '';
251 $o .= $this->output->container_start('gradingsummary');
252 $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3);
253 $o .= $this->output->box_start('boxaligncenter gradingsummarytable');
254 $t = new html_table();
256 // Status.
257 if ($summary->teamsubmission) {
258 $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'),
259 $summary->participantcount);
260 } else {
261 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'),
262 $summary->participantcount);
265 // Drafts count and dont show drafts count when using offline assignment.
266 if ($summary->submissiondraftsenabled && $summary->submissionsenabled) {
267 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'),
268 $summary->submissiondraftscount);
271 // Submitted for grading.
272 if ($summary->submissionsenabled) {
273 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'),
274 $summary->submissionssubmittedcount);
275 if (!$summary->teamsubmission) {
276 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'),
277 $summary->submissionsneedgradingcount);
281 $time = time();
282 if ($summary->duedate) {
283 // Due date.
284 $duedate = $summary->duedate;
285 $this->add_table_row_tuple($t, get_string('duedate', 'assign'),
286 userdate($duedate));
288 // Time remaining.
289 $due = '';
290 if ($duedate - $time <= 0) {
291 $due = get_string('assignmentisdue', 'assign');
292 } else {
293 $due = format_time($duedate - $time);
295 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due);
297 if ($duedate < $time) {
298 $cutoffdate = $summary->cutoffdate;
299 if ($cutoffdate) {
300 if ($cutoffdate > $time) {
301 $late = get_string('latesubmissionsaccepted', 'assign');
302 } else {
303 $late = get_string('nomoresubmissionsaccepted', 'assign');
305 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late);
311 // All done - write the table.
312 $o .= html_writer::table($t);
313 $o .= $this->output->box_end();
315 // Link to the grading page.
316 $o .= $this->output->container_start('submissionlinks');
317 $urlparams = array('id' => $summary->coursemoduleid, 'action'=>'grading');
318 $url = new moodle_url('/mod/assign/view.php', $urlparams);
319 $o .= $this->output->action_link($url, get_string('viewgrading', 'assign'));
320 $o .= $this->output->container_end();
322 // Close the container and insert a spacer.
323 $o .= $this->output->container_end();
325 return $o;
329 * Render a table containing all the current grades and feedback.
331 * @param assign_feedback_status $status
332 * @return string
334 public function render_assign_feedback_status(assign_feedback_status $status) {
335 global $DB, $CFG;
336 $o = '';
338 $o .= $this->output->container_start('feedback');
339 $o .= $this->output->heading(get_string('feedback', 'assign'), 3);
340 $o .= $this->output->box_start('boxaligncenter feedbacktable');
341 $t = new html_table();
343 // Grade.
344 if (isset($status->gradefordisplay)) {
345 $row = new html_table_row();
346 $cell1 = new html_table_cell(get_string('grade'));
347 $cell2 = new html_table_cell($status->gradefordisplay);
348 $row->cells = array($cell1, $cell2);
349 $t->data[] = $row;
351 // Grade date.
352 $row = new html_table_row();
353 $cell1 = new html_table_cell(get_string('gradedon', 'assign'));
354 $cell2 = new html_table_cell(userdate($status->gradeddate));
355 $row->cells = array($cell1, $cell2);
356 $t->data[] = $row;
359 if ($status->grader) {
360 // Grader.
361 $row = new html_table_row();
362 $cell1 = new html_table_cell(get_string('gradedby', 'assign'));
363 $userdescription = $this->output->user_picture($status->grader) .
364 $this->output->spacer(array('width'=>30)) .
365 fullname($status->grader);
366 $cell2 = new html_table_cell($userdescription);
367 $row->cells = array($cell1, $cell2);
368 $t->data[] = $row;
371 foreach ($status->feedbackplugins as $plugin) {
372 if ($plugin->is_enabled() &&
373 $plugin->is_visible() &&
374 $plugin->has_user_summary() &&
375 !empty($status->grade) &&
376 !$plugin->is_empty($status->grade)) {
378 $row = new html_table_row();
379 $cell1 = new html_table_cell($plugin->get_name());
380 $displaymode = assign_feedback_plugin_feedback::SUMMARY;
381 $pluginfeedback = new assign_feedback_plugin_feedback($plugin,
382 $status->grade,
383 $displaymode,
384 $status->coursemoduleid,
385 $status->returnaction,
386 $status->returnparams);
387 $cell2 = new html_table_cell($this->render($pluginfeedback));
388 $row->cells = array($cell1, $cell2);
389 $t->data[] = $row;
393 $o .= html_writer::table($t);
394 $o .= $this->output->box_end();
396 $o .= $this->output->container_end();
397 return $o;
401 * Render a table containing the current status of the submission.
403 * @param assign_submission_status $status
404 * @return string
406 public function render_assign_submission_status(assign_submission_status $status) {
407 $o = '';
408 $o .= $this->output->container_start('submissionstatustable');
409 $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3);
410 $time = time();
412 if ($status->allowsubmissionsfromdate &&
413 $time <= $status->allowsubmissionsfromdate) {
414 $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates');
415 if ($status->alwaysshowdescription) {
416 $date = userdate($status->allowsubmissionsfromdate);
417 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date);
418 } else {
419 $date = userdate($status->allowsubmissionsfromdate);
420 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date);
422 $o .= $this->output->box_end();
424 $o .= $this->output->box_start('boxaligncenter submissionsummarytable');
426 $t = new html_table();
428 if ($status->teamsubmissionenabled) {
429 $row = new html_table_row();
430 $cell1 = new html_table_cell(get_string('submissionteam', 'assign'));
431 $group = $status->submissiongroup;
432 if ($group) {
433 $cell2 = new html_table_cell(format_string($group->name, false, $status->context));
434 } else {
435 $cell2 = new html_table_cell(get_string('defaultteam', 'assign'));
437 $row->cells = array($cell1, $cell2);
438 $t->data[] = $row;
441 if ($status->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
442 $currentattempt = 1;
443 if (!$status->teamsubmissionenabled) {
444 if ($status->submission) {
445 $currentattempt = $status->submission->attemptnumber + 1;
447 } else {
448 if ($status->teamsubmission) {
449 $currentattempt = $status->teamsubmission->attemptnumber + 1;
453 $row = new html_table_row();
454 $cell1 = new html_table_cell(get_string('attemptnumber', 'assign'));
455 $maxattempts = $status->maxattempts;
456 if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) {
457 $message = get_string('currentattempt', 'assign', $currentattempt);
458 } else {
459 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt,
460 'maxattempts'=>$maxattempts));
462 $cell2 = new html_table_cell($message);
463 $row->cells = array($cell1, $cell2);
464 $t->data[] = $row;
467 $row = new html_table_row();
468 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
469 if (!$status->teamsubmissionenabled) {
470 if ($status->submission) {
471 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign');
472 $cell2 = new html_table_cell($statusstr);
473 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status);
474 } else {
475 if (!$status->submissionsenabled) {
476 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
477 } else {
478 $cell2 = new html_table_cell(get_string('noattempt', 'assign'));
481 $row->cells = array($cell1, $cell2);
482 $t->data[] = $row;
483 } else {
484 $row = new html_table_row();
485 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
486 if ($status->teamsubmission) {
487 $teamstatus = $status->teamsubmission->status;
488 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign');
489 $groupid = 0;
490 if ($status->submissiongroup) {
491 $groupid = $status->submissiongroup->id;
494 $members = $status->submissiongroupmemberswhoneedtosubmit;
495 $userslist = array();
496 foreach ($members as $member) {
497 $urlparams = array('id' => $member->id, 'course'=>$status->courseid);
498 $url = new moodle_url('/user/view.php', $urlparams);
499 if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) {
500 $userslist[] = $member->alias;
501 } else {
502 $fullname = fullname($member, $status->canviewfullnames);
503 $userslist[] = $this->output->action_link($url, $fullname);
506 if (count($userslist) > 0) {
507 $userstr = join(', ', $userslist);
508 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr);
509 $submissionsummary .= $this->output->container($formatteduserstr);
512 $cell2 = new html_table_cell($submissionsummary);
513 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status);
514 } else {
515 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
516 if (!$status->submissionsenabled) {
517 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign'));
518 } else {
519 $cell2 = new html_table_cell(get_string('nosubmission', 'assign'));
522 $row->cells = array($cell1, $cell2);
523 $t->data[] = $row;
526 // Is locked?
527 if ($status->locked) {
528 $row = new html_table_row();
529 $cell1 = new html_table_cell();
530 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign'));
531 $cell2->attributes = array('class'=>'submissionlocked');
532 $row->cells = array($cell1, $cell2);
533 $t->data[] = $row;
536 // Grading status.
537 $row = new html_table_row();
538 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign'));
540 if ($status->graded) {
541 $cell2 = new html_table_cell(get_string('graded', 'assign'));
542 $cell2->attributes = array('class'=>'submissiongraded');
543 } else {
544 $cell2 = new html_table_cell(get_string('notgraded', 'assign'));
545 $cell2->attributes = array('class'=>'submissionnotgraded');
547 $row->cells = array($cell1, $cell2);
548 $t->data[] = $row;
550 $duedate = $status->duedate;
551 if ($duedate > 0) {
552 // Due date.
553 $row = new html_table_row();
554 $cell1 = new html_table_cell(get_string('duedate', 'assign'));
555 $cell2 = new html_table_cell(userdate($duedate));
556 $row->cells = array($cell1, $cell2);
557 $t->data[] = $row;
559 if ($status->view == assign_submission_status::GRADER_VIEW) {
560 if ($status->cutoffdate) {
561 // Cut off date.
562 $row = new html_table_row();
563 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign'));
564 $cell2 = new html_table_cell(userdate($status->cutoffdate));
565 $row->cells = array($cell1, $cell2);
566 $t->data[] = $row;
570 if ($status->extensionduedate) {
571 // Extension date.
572 $row = new html_table_row();
573 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign'));
574 $cell2 = new html_table_cell(userdate($status->extensionduedate));
575 $row->cells = array($cell1, $cell2);
576 $t->data[] = $row;
577 $duedate = $status->extensionduedate;
580 // Time remaining.
581 $row = new html_table_row();
582 $cell1 = new html_table_cell(get_string('timeremaining', 'assign'));
583 if ($duedate - $time <= 0) {
584 if (!$status->submission ||
585 $status->submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) {
586 if ($status->submissionsenabled) {
587 $overduestr = get_string('overdue', 'assign', format_time($time - $duedate));
588 $cell2 = new html_table_cell($overduestr);
589 $cell2->attributes = array('class'=>'overdue');
590 } else {
591 $cell2 = new html_table_cell(get_string('duedatereached', 'assign'));
593 } else {
594 if ($status->submission->timemodified > $duedate) {
595 $latestr = get_string('submittedlate',
596 'assign',
597 format_time($status->submission->timemodified - $duedate));
598 $cell2 = new html_table_cell($latestr);
599 $cell2->attributes = array('class'=>'latesubmission');
600 } else {
601 $earlystr = get_string('submittedearly',
602 'assign',
603 format_time($status->submission->timemodified - $duedate));
604 $cell2 = new html_table_cell($earlystr);
605 $cell2->attributes = array('class'=>'earlysubmission');
608 } else {
609 $cell2 = new html_table_cell(format_time($duedate - $time));
611 $row->cells = array($cell1, $cell2);
612 $t->data[] = $row;
615 // Show graders whether this submission is editable by students.
616 if ($status->view == assign_submission_status::GRADER_VIEW) {
617 $row = new html_table_row();
618 $cell1 = new html_table_cell(get_string('editingstatus', 'assign'));
619 if ($status->canedit) {
620 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign'));
621 $cell2->attributes = array('class'=>'submissioneditable');
622 } else {
623 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign'));
624 $cell2->attributes = array('class'=>'submissionnoteditable');
626 $row->cells = array($cell1, $cell2);
627 $t->data[] = $row;
630 // Grading criteria preview.
631 if (!empty($status->gradingcontrollerpreview)) {
632 $row = new html_table_row();
633 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign'));
634 $cell2 = new html_table_cell($status->gradingcontrollerpreview);
635 $row->cells = array($cell1, $cell2);
636 $t->data[] = $row;
639 // Last modified.
640 $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission;
641 if ($submission) {
642 $row = new html_table_row();
643 $cell1 = new html_table_cell(get_string('timemodified', 'assign'));
644 $cell2 = new html_table_cell(userdate($submission->timemodified));
645 $row->cells = array($cell1, $cell2);
646 $t->data[] = $row;
648 foreach ($status->submissionplugins as $plugin) {
649 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
650 if ($plugin->is_enabled() &&
651 $plugin->is_visible() &&
652 $plugin->has_user_summary() &&
653 $pluginshowsummary) {
655 $row = new html_table_row();
656 $cell1 = new html_table_cell($plugin->get_name());
657 $displaymode = assign_submission_plugin_submission::SUMMARY;
658 $pluginsubmission = new assign_submission_plugin_submission($plugin,
659 $submission,
660 $displaymode,
661 $status->coursemoduleid,
662 $status->returnaction,
663 $status->returnparams);
664 $cell2 = new html_table_cell($this->render($pluginsubmission));
665 $row->cells = array($cell1, $cell2);
666 $t->data[] = $row;
671 $o .= html_writer::table($t);
672 $o .= $this->output->box_end();
674 // Links.
675 if ($status->view == assign_submission_status::STUDENT_VIEW) {
676 if ($status->canedit) {
677 if (!$submission) {
678 $o .= $this->output->box_start('generalbox submissionaction');
679 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
680 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
681 get_string('addsubmission', 'assign'), 'get');
682 $o .= $this->output->box_start('boxaligncenter submithelp');
683 $o .= get_string('editsubmission_help', 'assign');
684 $o .= $this->output->box_end();
685 $o .= $this->output->box_end();
686 } else if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) {
687 $o .= $this->output->box_start('generalbox submissionaction');
688 $urlparams = array('id' => $status->coursemoduleid,
689 'action' => 'editprevioussubmission',
690 'sesskey'=>sesskey());
691 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
692 get_string('addnewattemptfromprevious', 'assign'), 'get');
693 $o .= $this->output->box_start('boxaligncenter submithelp');
694 $o .= get_string('addnewattemptfromprevious_help', 'assign');
695 $o .= $this->output->box_end();
696 $o .= $this->output->box_end();
697 $o .= $this->output->box_start('generalbox submissionaction');
698 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
699 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
700 get_string('addnewattempt', 'assign'), 'get');
701 $o .= $this->output->box_start('boxaligncenter submithelp');
702 $o .= get_string('addnewattempt_help', 'assign');
703 $o .= $this->output->box_end();
704 $o .= $this->output->box_end();
705 } else {
706 $o .= $this->output->box_start('generalbox submissionaction');
707 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission');
708 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
709 get_string('editsubmission', 'assign'), 'get');
710 $o .= $this->output->box_start('boxaligncenter submithelp');
711 $o .= get_string('editsubmission_help', 'assign');
712 $o .= $this->output->box_end();
713 $o .= $this->output->box_end();
717 if ($status->cansubmit) {
718 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit');
719 $o .= $this->output->box_start('generalbox submissionaction');
720 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams),
721 get_string('submitassignment', 'assign'), 'get');
722 $o .= $this->output->box_start('boxaligncenter submithelp');
723 $o .= get_string('submitassignment_help', 'assign');
724 $o .= $this->output->box_end();
725 $o .= $this->output->box_end();
729 $o .= $this->output->container_end();
730 return $o;
734 * Output the attempt history for this assignment
736 * @param assign_attempt_history $history
737 * @return string
739 public function render_assign_attempt_history(assign_attempt_history $history) {
740 $o = '';
742 $submittedstr = get_string('submitted', 'assign');
743 $gradestr = get_string('grade');
744 $gradedonstr = get_string('gradedon', 'assign');
745 $gradedbystr = get_string('gradedby', 'assign');
747 // Don't show the last one because it is the current submission.
748 array_pop($history->submissions);
750 // Show newest to oldest.
751 $history->submissions = array_reverse($history->submissions);
753 if (empty($history->submissions)) {
754 return '';
757 $containerid = 'attempthistory' . uniqid();
758 $o .= $this->heading(get_string('attempthistory', 'assign'), 3);
759 $o .= $this->box_start('attempthistory', $containerid);
761 foreach ($history->submissions as $i => $submission) {
762 $grade = null;
763 foreach ($history->grades as $onegrade) {
764 if ($onegrade->attemptnumber == $submission->attemptnumber) {
765 $grade = $onegrade;
766 break;
770 $editbtn = '';
772 if ($submission) {
773 $submissionsummary = userdate($submission->timemodified);
774 } else {
775 $submissionsummary = get_string('nosubmission', 'assign');
778 $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+1,
779 'submissionsummary'=>$submissionsummary);
780 $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4);
782 $t = new html_table();
784 if ($submission) {
785 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign'));
786 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status, 'assign'));
787 $t->data[] = new html_table_row(array($cell1, $cell2));
789 foreach ($history->submissionplugins as $plugin) {
790 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions();
791 if ($plugin->is_enabled() &&
792 $plugin->is_visible() &&
793 $plugin->has_user_summary() &&
794 $pluginshowsummary) {
796 $cell1 = new html_table_cell($plugin->get_name());
797 $pluginsubmission = new assign_submission_plugin_submission($plugin,
798 $submission,
799 assign_submission_plugin_submission::SUMMARY,
800 $history->coursemoduleid,
801 $history->returnaction,
802 $history->returnparams);
803 $cell2 = new html_table_cell($this->render($pluginsubmission));
805 $t->data[] = new html_table_row(array($cell1, $cell2));
810 if ($grade) {
811 // Heading 'feedback'.
812 $title = get_string('feedback', 'assign', $i);
813 $title .= $this->output->spacer(array('width'=>10));
814 if ($history->cangrade) {
815 // Edit previous feedback.
816 $returnparams = http_build_query($history->returnparams);
817 $urlparams = array('id' => $history->coursemoduleid,
818 'rownum'=>$history->rownum,
819 'useridlistid'=>$history->useridlistid,
820 'attemptnumber'=>$grade->attemptnumber,
821 'action'=>'grade',
822 'returnaction'=>$history->returnaction,
823 'returnparams'=>$returnparams);
824 $url = new moodle_url('/mod/assign/view.php', $urlparams);
825 $icon = new pix_icon('gradefeedback',
826 get_string('editattemptfeedback', 'assign', $grade->attemptnumber+1),
827 'mod_assign');
828 $title .= $this->output->action_icon($url, $icon);
830 $cell = new html_table_cell($title);
831 $cell->attributes['class'] = 'feedbacktitle';
832 $cell->colspan = 2;
833 $t->data[] = new html_table_row(array($cell));
835 // Grade.
836 $cell1 = new html_table_cell($gradestr);
837 $cell2 = $grade->gradefordisplay;
838 $t->data[] = new html_table_row(array($cell1, $cell2));
840 // Graded on.
841 $cell1 = new html_table_cell($gradedonstr);
842 $cell2 = new html_table_cell(userdate($grade->timemodified));
843 $t->data[] = new html_table_row(array($cell1, $cell2));
845 // Graded by.
846 $cell1 = new html_table_cell($gradedbystr);
847 $cell2 = new html_table_cell($this->output->user_picture($grade->grader) .
848 $this->output->spacer(array('width'=>30)) . fullname($grade->grader));
849 $t->data[] = new html_table_row(array($cell1, $cell2));
851 // Feedback from plugins.
852 foreach ($history->feedbackplugins as $plugin) {
853 if ($plugin->is_enabled() &&
854 $plugin->is_visible() &&
855 $plugin->has_user_summary() &&
856 !$plugin->is_empty($grade)) {
858 $cell1 = new html_table_cell($plugin->get_name());
859 $pluginfeedback = new assign_feedback_plugin_feedback(
860 $plugin, $grade, assign_feedback_plugin_feedback::SUMMARY, $history->coursemoduleid,
861 $history->returnaction, $history->returnparams
863 $cell2 = new html_table_cell($this->render($pluginfeedback));
864 $t->data[] = new html_table_row(array($cell1, $cell2));
871 $o .= html_writer::table($t);
873 $o .= $this->box_end();
874 $jsparams = array($containerid);
876 $this->page->requires->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history');
878 return $o;
882 * Render a submission plugin submission
884 * @param assign_submission_plugin_submission $submissionplugin
885 * @return string
887 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) {
888 $o = '';
890 if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) {
891 $showviewlink = false;
892 $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission,
893 $showviewlink);
895 $classsuffix = $submissionplugin->plugin->get_subtype() .
896 '_' .
897 $submissionplugin->plugin->get_type() .
898 '_' .
899 $submissionplugin->submission->id;
901 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
903 $link = '';
904 if ($showviewlink) {
905 $previewstr = get_string('viewsubmission', 'assign');
906 $icon = $this->output->pix_icon('t/preview', $previewstr);
908 $expandstr = get_string('viewfull', 'assign');
909 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
910 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
912 $jsparams = array($submissionplugin->plugin->get_subtype(),
913 $submissionplugin->plugin->get_type(),
914 $submissionplugin->submission->id);
916 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
918 $action = 'viewplugin' . $submissionplugin->plugin->get_subtype();
919 $returnparams = http_build_query($submissionplugin->returnparams);
920 $link .= '<noscript>';
921 $urlparams = array('id' => $submissionplugin->coursemoduleid,
922 'sid'=>$submissionplugin->submission->id,
923 'plugin'=>$submissionplugin->plugin->get_type(),
924 'action'=>$action,
925 'returnaction'=>$submissionplugin->returnaction,
926 'returnparams'=>$returnparams);
927 $url = new moodle_url('/mod/assign/view.php', $urlparams);
928 $link .= $this->output->action_link($url, $icon);
929 $link .= '</noscript>';
931 $link .= $this->output->spacer(array('width'=>15));
934 $o .= $link . $summary;
935 $o .= $this->output->box_end();
936 if ($showviewlink) {
937 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
938 $classes = 'expandsummaryicon contract_' . $classsuffix;
939 $o .= $this->output->pix_icon('t/switch_minus',
940 get_string('viewsummary', 'assign'),
941 null,
942 array('class'=>$classes));
943 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
944 $o .= $this->output->box_end();
946 } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) {
947 $o .= $this->output->box_start('boxaligncenter submissionfull');
948 $o .= $submissionplugin->plugin->view($submissionplugin->submission);
949 $o .= $this->output->box_end();
952 return $o;
956 * Render the grading table.
958 * @param assign_grading_table $table
959 * @return string
961 public function render_assign_grading_table(assign_grading_table $table) {
962 $o = '';
963 $o .= $this->output->box_start('boxaligncenter gradingtable');
965 $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
966 $this->page->requires->string_for_js('nousersselected', 'assign');
967 $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
968 $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
969 $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
970 $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
971 $this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign');
972 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
973 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
974 $this->page->requires->string_for_js('editaction', 'assign');
975 foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
976 foreach ($operations as $operation => $description) {
977 $this->page->requires->string_for_js('batchoperationconfirm' . $operation,
978 'assignfeedback_' . $plugin);
981 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
982 $o .= $this->output->box_end();
984 return $o;
988 * Render a feedback plugin feedback
990 * @param assign_feedback_plugin_feedback $feedbackplugin
991 * @return string
993 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) {
994 $o = '';
996 if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) {
997 $showviewlink = false;
998 $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink);
1000 $classsuffix = $feedbackplugin->plugin->get_subtype() .
1001 '_' .
1002 $feedbackplugin->plugin->get_type() .
1003 '_' .
1004 $feedbackplugin->grade->id;
1005 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix);
1007 $link = '';
1008 if ($showviewlink) {
1009 $previewstr = get_string('viewfeedback', 'assign');
1010 $icon = $this->output->pix_icon('t/preview', $previewstr);
1012 $expandstr = get_string('viewfull', 'assign');
1013 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix);
1014 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options);
1016 $jsparams = array($feedbackplugin->plugin->get_subtype(),
1017 $feedbackplugin->plugin->get_type(),
1018 $feedbackplugin->grade->id);
1019 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams);
1021 $urlparams = array('id' => $feedbackplugin->coursemoduleid,
1022 'gid'=>$feedbackplugin->grade->id,
1023 'plugin'=>$feedbackplugin->plugin->get_type(),
1024 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(),
1025 'returnaction'=>$feedbackplugin->returnaction,
1026 'returnparams'=>http_build_query($feedbackplugin->returnparams));
1027 $url = new moodle_url('/mod/assign/view.php', $urlparams);
1028 $link .= '<noscript>';
1029 $link .= $this->output->action_link($url, $icon);
1030 $link .= '</noscript>';
1032 $link .= $this->output->spacer(array('width'=>15));
1035 $o .= $link . $summary;
1036 $o .= $this->output->box_end();
1037 if ($showviewlink) {
1038 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix);
1039 $classes = 'expandsummaryicon contract_' . $classsuffix;
1040 $o .= $this->output->pix_icon('t/switch_minus',
1041 get_string('viewsummary', 'assign'),
1042 null,
1043 array('class'=>$classes));
1044 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1045 $o .= $this->output->box_end();
1047 } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) {
1048 $o .= $this->output->box_start('boxaligncenter feedbackfull');
1049 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade);
1050 $o .= $this->output->box_end();
1053 return $o;
1057 * Render a course index summary
1059 * @param assign_course_index_summary $indexsummary
1060 * @return string
1062 public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
1063 $o = '';
1065 $strplural = get_string('modulenameplural', 'assign');
1066 $strsectionname = $indexsummary->courseformatname;
1067 $strduedate = get_string('duedate', 'assign');
1068 $strsubmission = get_string('submission', 'assign');
1069 $strgrade = get_string('grade');
1071 $table = new html_table();
1072 if ($indexsummary->usesections) {
1073 $table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
1074 $table->align = array ('left', 'left', 'center', 'right', 'right');
1075 } else {
1076 $table->head = array ($strplural, $strduedate, $strsubmission, $strgrade);
1077 $table->align = array ('left', 'left', 'center', 'right');
1079 $table->data = array();
1081 $currentsection = '';
1082 foreach ($indexsummary->assignments as $info) {
1083 $params = array('id' => $info['cmid']);
1084 $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
1085 $info['cmname']);
1086 $due = $info['timedue'] ? userdate($info['timedue']) : '-';
1088 $printsection = '';
1089 if ($indexsummary->usesections) {
1090 if ($info['sectionname'] !== $currentsection) {
1091 if ($info['sectionname']) {
1092 $printsection = $info['sectionname'];
1094 if ($currentsection !== '') {
1095 $table->data[] = 'hr';
1097 $currentsection = $info['sectionname'];
1101 if ($indexsummary->usesections) {
1102 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
1103 } else {
1104 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
1106 $table->data[] = $row;
1109 $o .= html_writer::table($table);
1111 return $o;
1117 * Internal function - creates htmls structure suitable for YUI tree.
1119 * @param assign_files $tree
1120 * @param array $dir
1121 * @return string
1123 protected function htmllize_tree(assign_files $tree, $dir) {
1124 global $CFG;
1125 $yuiconfig = array();
1126 $yuiconfig['type'] = 'html';
1128 if (empty($dir['subdirs']) and empty($dir['files'])) {
1129 return '';
1132 $result = '<ul>';
1133 foreach ($dir['subdirs'] as $subdir) {
1134 $image = $this->output->pix_icon(file_folder_icon(),
1135 $subdir['dirname'],
1136 'moodle',
1137 array('class'=>'icon'));
1138 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1139 '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' .
1140 $this->htmllize_tree($tree, $subdir) .
1141 '</li>';
1144 foreach ($dir['files'] as $file) {
1145 $filename = $file->get_filename();
1146 if ($CFG->enableplagiarism) {
1147 require_once($CFG->libdir.'/plagiarismlib.php');
1148 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(),
1149 'file'=>$file,
1150 'cmid'=>$tree->cm->id,
1151 'course'=>$tree->course));
1152 } else {
1153 $plagiarismlinks = '';
1155 $image = $this->output->pix_icon(file_file_icon($file),
1156 $filename,
1157 'moodle',
1158 array('class'=>'icon'));
1159 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' .
1160 '<div>' . $image . ' ' .
1161 $file->fileurl . ' ' .
1162 $plagiarismlinks .
1163 $file->portfoliobutton . '</div>' .
1164 '</li>';
1167 $result .= '</ul>';
1169 return $result;
1173 * Helper method dealing with the fact we can not just fetch the output of flexible_table
1175 * @param flexible_table $table The table to render
1176 * @param int $rowsperpage How many assignments to render in a page
1177 * @param bool $displaylinks - Whether to render links in the table
1178 * (e.g. downloads would not enable this)
1179 * @return string HTML
1181 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
1183 $o = '';
1184 ob_start();
1185 $table->out($rowsperpage, $displaylinks);
1186 $o = ob_get_contents();
1187 ob_end_clean();
1189 return $o;
1193 * Helper method dealing with the fact we can not just fetch the output of moodleforms
1195 * @param moodleform $mform
1196 * @return string HTML
1198 protected function moodleform(moodleform $mform) {
1200 $o = '';
1201 ob_start();
1202 $mform->display();
1203 $o = ob_get_contents();
1204 ob_end_clean();
1206 return $o;