[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 25 defined('MOODLE_INTERNAL') || die(); 26 27 require_once($CFG->dirroot . '/mod/assign/locallib.php'); 28 29 /** 30 * A custom renderer class that extends the plugin_renderer_base and is used by the assign module. 31 * 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 35 */ 36 class mod_assign_renderer extends plugin_renderer_base { 37 38 /** 39 * Rendering assignment files 40 * 41 * @param context $context 42 * @param int $userid 43 * @param string $filearea 44 * @param string $component 45 * @return string 46 */ 47 public function assign_files(context $context, $userid, $filearea, $component) { 48 return $this->render(new assign_files($context, $userid, $filearea, $component)); 49 } 50 51 /** 52 * Rendering assignment files 53 * 54 * @param assign_files $tree 55 * @return string 56 */ 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>'; 63 64 if ($tree->portfolioform) { 65 $html .= $tree->portfolioform; 66 } 67 return $html; 68 } 69 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 73 * 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 78 */ 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; 85 } 86 87 /** 88 * Render a grading message notification 89 * @param assign_gradingmessage $result The result to render 90 * @return string 91 */ 92 public function render_assign_gradingmessage(assign_gradingmessage $result) { 93 $urlparams = array('id' => $result->coursemoduleid, 'action'=>'grading'); 94 if (!empty($result->page)) { 95 $urlparams['page'] = $result->page; 96 } 97 $url = new moodle_url('/mod/assign/view.php', $urlparams); 98 $classes = $result->gradingerror ? 'notifyproblem' : 'notifysuccess'; 99 100 $o = ''; 101 $o .= $this->output->heading($result->heading, 4); 102 $o .= $this->output->notification($result->message, $classes); 103 $o .= $this->output->continue_button($url); 104 return $o; 105 } 106 107 /** 108 * Render the generic form 109 * @param assign_form $form The form to render 110 * @return string 111 */ 112 public function render_assign_form(assign_form $form) { 113 $o = ''; 114 if ($form->jsinitfunction) { 115 $this->page->requires->js_init_call($form->jsinitfunction, array()); 116 } 117 $o .= $this->output->box_start('boxaligncenter ' . $form->classname); 118 $o .= $this->moodleform($form->form); 119 $o .= $this->output->box_end(); 120 return $o; 121 } 122 123 /** 124 * Render the user summary 125 * 126 * @param assign_user_summary $summary The user summary to render 127 * @return string 128 */ 129 public function render_assign_user_summary(assign_user_summary $summary) { 130 $o = ''; 131 $supendedclass = ''; 132 $suspendedicon = ''; 133 134 if (!$summary->user) { 135 return; 136 } 137 138 if ($summary->suspendeduser) { 139 $supendedclass = ' usersuspended'; 140 $suspendedstring = get_string('userenrolmentsuspended', 'grades'); 141 $suspendedicon = ' ' . html_writer::empty_tag('img', array('src' => $this->pix_url('i/enrolmentsuspended'), 142 'title' => $suspendedstring, 'alt' => $suspendedstring, 'class' => 'usersuspendedicon')); 143 } 144 $o .= $this->output->container_start('usersummary'); 145 $o .= $this->output->box_start('boxaligncenter usersummarysection'.$supendedclass); 146 if ($summary->blindmarking) { 147 $o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser.$suspendedicon; 148 } else { 149 $o .= $this->output->user_picture($summary->user); 150 $o .= $this->output->spacer(array('width'=>30)); 151 $urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid); 152 $url = new moodle_url('/user/view.php', $urlparams); 153 $fullname = fullname($summary->user, $summary->viewfullnames); 154 $extrainfo = array(); 155 foreach ($summary->extrauserfields as $extrafield) { 156 $extrainfo[] = $summary->user->$extrafield; 157 } 158 if (count($extrainfo)) { 159 $fullname .= ' (' . implode(', ', $extrainfo) . ')'; 160 } 161 $fullname .= $suspendedicon; 162 $o .= $this->output->action_link($url, $fullname); 163 } 164 $o .= $this->output->box_end(); 165 $o .= $this->output->container_end(); 166 167 return $o; 168 } 169 170 /** 171 * Render the submit for grading page 172 * 173 * @param assign_submit_for_grading_page $page 174 * @return string 175 */ 176 public function render_assign_submit_for_grading_page($page) { 177 $o = ''; 178 179 $o .= $this->output->container_start('submitforgrading'); 180 $o .= $this->output->heading(get_string('submitassignment', 'assign'), 3); 181 $o .= $this->output->spacer(array('height'=>30)); 182 183 $cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid)); 184 if (count($page->notifications)) { 185 // At least one of the submission plugins is not ready for submission. 186 187 $o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4); 188 189 foreach ($page->notifications as $notification) { 190 $o .= $this->output->notification($notification); 191 } 192 193 $o .= $this->output->continue_button($cancelurl); 194 } else { 195 // All submission plugins ready - show the confirmation form. 196 $o .= $this->output->box_start('generalbox submitconfirm'); 197 $o .= $this->moodleform($page->confirmform); 198 $o .= $this->output->box_end(); 199 } 200 $o .= $this->output->container_end(); 201 202 return $o; 203 } 204 205 /** 206 * Page is done - render the footer. 207 * 208 * @return void 209 */ 210 public function render_footer() { 211 return $this->output->footer(); 212 } 213 214 /** 215 * Render the header. 216 * 217 * @param assign_header $header 218 * @return string 219 */ 220 public function render_assign_header(assign_header $header) { 221 $o = ''; 222 223 if ($header->subpage) { 224 $this->page->navbar->add($header->subpage); 225 } 226 227 $this->page->set_title(get_string('pluginname', 'assign')); 228 $this->page->set_heading($this->page->course->fullname); 229 230 $o .= $this->output->header(); 231 $heading = format_string($header->assign->name, false, array('context' => $header->context)); 232 $o .= $this->output->heading($heading); 233 if ($header->preface) { 234 $o .= $header->preface; 235 } 236 237 if ($header->showintro) { 238 $o .= $this->output->box_start('generalbox boxaligncenter', 'intro'); 239 $o .= format_module_intro('assign', $header->assign, $header->coursemoduleid); 240 $o .= $header->postfix; 241 $o .= $this->output->box_end(); 242 } 243 244 return $o; 245 } 246 247 /** 248 * Render the header for an individual plugin. 249 * 250 * @param assign_plugin_header $header 251 * @return string 252 */ 253 public function render_assign_plugin_header(assign_plugin_header $header) { 254 $o = $header->plugin->view_header(); 255 return $o; 256 } 257 258 /** 259 * Render a table containing the current status of the grading process. 260 * 261 * @param assign_grading_summary $summary 262 * @return string 263 */ 264 public function render_assign_grading_summary(assign_grading_summary $summary) { 265 // Create a table for the data. 266 $o = ''; 267 $o .= $this->output->container_start('gradingsummary'); 268 $o .= $this->output->heading(get_string('gradingsummary', 'assign'), 3); 269 $o .= $this->output->box_start('boxaligncenter gradingsummarytable'); 270 $t = new html_table(); 271 272 // Status. 273 if ($summary->teamsubmission) { 274 $this->add_table_row_tuple($t, get_string('numberofteams', 'assign'), 275 $summary->participantcount); 276 } else { 277 $this->add_table_row_tuple($t, get_string('numberofparticipants', 'assign'), 278 $summary->participantcount); 279 } 280 281 // Drafts count and dont show drafts count when using offline assignment. 282 if ($summary->submissiondraftsenabled && $summary->submissionsenabled) { 283 $this->add_table_row_tuple($t, get_string('numberofdraftsubmissions', 'assign'), 284 $summary->submissiondraftscount); 285 } 286 287 // Submitted for grading. 288 if ($summary->submissionsenabled) { 289 $this->add_table_row_tuple($t, get_string('numberofsubmittedassignments', 'assign'), 290 $summary->submissionssubmittedcount); 291 if (!$summary->teamsubmission) { 292 $this->add_table_row_tuple($t, get_string('numberofsubmissionsneedgrading', 'assign'), 293 $summary->submissionsneedgradingcount); 294 } 295 } 296 297 $time = time(); 298 if ($summary->duedate) { 299 // Due date. 300 $duedate = $summary->duedate; 301 $this->add_table_row_tuple($t, get_string('duedate', 'assign'), 302 userdate($duedate)); 303 304 // Time remaining. 305 $due = ''; 306 if ($duedate - $time <= 0) { 307 $due = get_string('assignmentisdue', 'assign'); 308 } else { 309 $due = format_time($duedate - $time); 310 } 311 $this->add_table_row_tuple($t, get_string('timeremaining', 'assign'), $due); 312 313 if ($duedate < $time) { 314 $cutoffdate = $summary->cutoffdate; 315 if ($cutoffdate) { 316 if ($cutoffdate > $time) { 317 $late = get_string('latesubmissionsaccepted', 'assign'); 318 } else { 319 $late = get_string('nomoresubmissionsaccepted', 'assign'); 320 } 321 $this->add_table_row_tuple($t, get_string('latesubmissions', 'assign'), $late); 322 } 323 } 324 325 } 326 327 // All done - write the table. 328 $o .= html_writer::table($t); 329 $o .= $this->output->box_end(); 330 331 // Link to the grading page. 332 $o .= $this->output->container_start('submissionlinks'); 333 $urlparams = array('id' => $summary->coursemoduleid, 'action'=>'grading'); 334 $url = new moodle_url('/mod/assign/view.php', $urlparams); 335 $o .= $this->output->action_link($url, get_string('viewgrading', 'assign')); 336 $o .= $this->output->container_end(); 337 338 // Close the container and insert a spacer. 339 $o .= $this->output->container_end(); 340 341 return $o; 342 } 343 344 /** 345 * Render a table containing all the current grades and feedback. 346 * 347 * @param assign_feedback_status $status 348 * @return string 349 */ 350 public function render_assign_feedback_status(assign_feedback_status $status) { 351 global $DB, $CFG; 352 $o = ''; 353 354 $o .= $this->output->container_start('feedback'); 355 $o .= $this->output->heading(get_string('feedback', 'assign'), 3); 356 $o .= $this->output->box_start('boxaligncenter feedbacktable'); 357 $t = new html_table(); 358 359 // Grade. 360 if (isset($status->gradefordisplay)) { 361 $row = new html_table_row(); 362 $cell1 = new html_table_cell(get_string('grade')); 363 $cell2 = new html_table_cell($status->gradefordisplay); 364 $row->cells = array($cell1, $cell2); 365 $t->data[] = $row; 366 367 // Grade date. 368 $row = new html_table_row(); 369 $cell1 = new html_table_cell(get_string('gradedon', 'assign')); 370 $cell2 = new html_table_cell(userdate($status->gradeddate)); 371 $row->cells = array($cell1, $cell2); 372 $t->data[] = $row; 373 } 374 375 if ($status->grader) { 376 // Grader. 377 $row = new html_table_row(); 378 $cell1 = new html_table_cell(get_string('gradedby', 'assign')); 379 $userdescription = $this->output->user_picture($status->grader) . 380 $this->output->spacer(array('width'=>30)) . 381 fullname($status->grader); 382 $cell2 = new html_table_cell($userdescription); 383 $row->cells = array($cell1, $cell2); 384 $t->data[] = $row; 385 } 386 387 foreach ($status->feedbackplugins as $plugin) { 388 if ($plugin->is_enabled() && 389 $plugin->is_visible() && 390 $plugin->has_user_summary() && 391 !empty($status->grade) && 392 !$plugin->is_empty($status->grade)) { 393 394 $row = new html_table_row(); 395 $cell1 = new html_table_cell($plugin->get_name()); 396 $displaymode = assign_feedback_plugin_feedback::SUMMARY; 397 $pluginfeedback = new assign_feedback_plugin_feedback($plugin, 398 $status->grade, 399 $displaymode, 400 $status->coursemoduleid, 401 $status->returnaction, 402 $status->returnparams); 403 $cell2 = new html_table_cell($this->render($pluginfeedback)); 404 $row->cells = array($cell1, $cell2); 405 $t->data[] = $row; 406 } 407 } 408 409 $o .= html_writer::table($t); 410 $o .= $this->output->box_end(); 411 412 $o .= $this->output->container_end(); 413 return $o; 414 } 415 416 /** 417 * Render a table containing the current status of the submission. 418 * 419 * @param assign_submission_status $status 420 * @return string 421 */ 422 public function render_assign_submission_status(assign_submission_status $status) { 423 $o = ''; 424 $o .= $this->output->container_start('submissionstatustable'); 425 $o .= $this->output->heading(get_string('submissionstatusheading', 'assign'), 3); 426 $time = time(); 427 428 if ($status->allowsubmissionsfromdate && 429 $time <= $status->allowsubmissionsfromdate) { 430 $o .= $this->output->box_start('generalbox boxaligncenter submissionsalloweddates'); 431 if ($status->alwaysshowdescription) { 432 $date = userdate($status->allowsubmissionsfromdate); 433 $o .= get_string('allowsubmissionsfromdatesummary', 'assign', $date); 434 } else { 435 $date = userdate($status->allowsubmissionsfromdate); 436 $o .= get_string('allowsubmissionsanddescriptionfromdatesummary', 'assign', $date); 437 } 438 $o .= $this->output->box_end(); 439 } 440 $o .= $this->output->box_start('boxaligncenter submissionsummarytable'); 441 442 $t = new html_table(); 443 444 if ($status->teamsubmissionenabled) { 445 $row = new html_table_row(); 446 $cell1 = new html_table_cell(get_string('submissionteam', 'assign')); 447 $group = $status->submissiongroup; 448 if ($group) { 449 $cell2 = new html_table_cell(format_string($group->name, false, $status->context)); 450 } else { 451 $cell2 = new html_table_cell(get_string('defaultteam', 'assign')); 452 } 453 $row->cells = array($cell1, $cell2); 454 $t->data[] = $row; 455 } 456 457 if ($status->attemptreopenmethod != ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) { 458 $currentattempt = 1; 459 if (!$status->teamsubmissionenabled) { 460 if ($status->submission) { 461 $currentattempt = $status->submission->attemptnumber + 1; 462 } 463 } else { 464 if ($status->teamsubmission) { 465 $currentattempt = $status->teamsubmission->attemptnumber + 1; 466 } 467 } 468 469 $row = new html_table_row(); 470 $cell1 = new html_table_cell(get_string('attemptnumber', 'assign')); 471 $maxattempts = $status->maxattempts; 472 if ($maxattempts == ASSIGN_UNLIMITED_ATTEMPTS) { 473 $message = get_string('currentattempt', 'assign', $currentattempt); 474 } else { 475 $message = get_string('currentattemptof', 'assign', array('attemptnumber'=>$currentattempt, 476 'maxattempts'=>$maxattempts)); 477 } 478 $cell2 = new html_table_cell($message); 479 $row->cells = array($cell1, $cell2); 480 $t->data[] = $row; 481 } 482 483 $row = new html_table_row(); 484 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign')); 485 if (!$status->teamsubmissionenabled) { 486 if ($status->submission && $status->submission->status != ASSIGN_SUBMISSION_STATUS_NEW) { 487 $statusstr = get_string('submissionstatus_' . $status->submission->status, 'assign'); 488 $cell2 = new html_table_cell($statusstr); 489 $cell2->attributes = array('class'=>'submissionstatus' . $status->submission->status); 490 } else { 491 if (!$status->submissionsenabled) { 492 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign')); 493 } else { 494 $cell2 = new html_table_cell(get_string('noattempt', 'assign')); 495 } 496 } 497 $row->cells = array($cell1, $cell2); 498 $t->data[] = $row; 499 } else { 500 $row = new html_table_row(); 501 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign')); 502 if ($status->teamsubmission && $status->teamsubmission->status != ASSIGN_SUBMISSION_STATUS_NEW) { 503 $teamstatus = $status->teamsubmission->status; 504 $submissionsummary = get_string('submissionstatus_' . $teamstatus, 'assign'); 505 $groupid = 0; 506 if ($status->submissiongroup) { 507 $groupid = $status->submissiongroup->id; 508 } 509 510 $members = $status->submissiongroupmemberswhoneedtosubmit; 511 $userslist = array(); 512 foreach ($members as $member) { 513 $urlparams = array('id' => $member->id, 'course'=>$status->courseid); 514 $url = new moodle_url('/user/view.php', $urlparams); 515 if ($status->view == assign_submission_status::GRADER_VIEW && $status->blindmarking) { 516 $userslist[] = $member->alias; 517 } else { 518 $fullname = fullname($member, $status->canviewfullnames); 519 $userslist[] = $this->output->action_link($url, $fullname); 520 } 521 } 522 if (count($userslist) > 0) { 523 $userstr = join(', ', $userslist); 524 $formatteduserstr = get_string('userswhoneedtosubmit', 'assign', $userstr); 525 $submissionsummary .= $this->output->container($formatteduserstr); 526 } 527 528 $cell2 = new html_table_cell($submissionsummary); 529 $cell2->attributes = array('class'=>'submissionstatus' . $status->teamsubmission->status); 530 } else { 531 $cell2 = new html_table_cell(get_string('nosubmission', 'assign')); 532 if (!$status->submissionsenabled) { 533 $cell2 = new html_table_cell(get_string('noonlinesubmissions', 'assign')); 534 } else { 535 $cell2 = new html_table_cell(get_string('nosubmission', 'assign')); 536 } 537 } 538 $row->cells = array($cell1, $cell2); 539 $t->data[] = $row; 540 } 541 542 // Is locked? 543 if ($status->locked) { 544 $row = new html_table_row(); 545 $cell1 = new html_table_cell(); 546 $cell2 = new html_table_cell(get_string('submissionslocked', 'assign')); 547 $cell2->attributes = array('class'=>'submissionlocked'); 548 $row->cells = array($cell1, $cell2); 549 $t->data[] = $row; 550 } 551 552 // Grading status. 553 $row = new html_table_row(); 554 $cell1 = new html_table_cell(get_string('gradingstatus', 'assign')); 555 556 if ($status->graded) { 557 $cell2 = new html_table_cell(get_string('graded', 'assign')); 558 $cell2->attributes = array('class'=>'submissiongraded'); 559 } else { 560 $cell2 = new html_table_cell(get_string('notgraded', 'assign')); 561 $cell2->attributes = array('class'=>'submissionnotgraded'); 562 } 563 $row->cells = array($cell1, $cell2); 564 $t->data[] = $row; 565 566 $submission = $status->teamsubmission ? $status->teamsubmission : $status->submission; 567 $duedate = $status->duedate; 568 if ($duedate > 0) { 569 // Due date. 570 $row = new html_table_row(); 571 $cell1 = new html_table_cell(get_string('duedate', 'assign')); 572 $cell2 = new html_table_cell(userdate($duedate)); 573 $row->cells = array($cell1, $cell2); 574 $t->data[] = $row; 575 576 if ($status->view == assign_submission_status::GRADER_VIEW) { 577 if ($status->cutoffdate) { 578 // Cut off date. 579 $row = new html_table_row(); 580 $cell1 = new html_table_cell(get_string('cutoffdate', 'assign')); 581 $cell2 = new html_table_cell(userdate($status->cutoffdate)); 582 $row->cells = array($cell1, $cell2); 583 $t->data[] = $row; 584 } 585 } 586 587 if ($status->extensionduedate) { 588 // Extension date. 589 $row = new html_table_row(); 590 $cell1 = new html_table_cell(get_string('extensionduedate', 'assign')); 591 $cell2 = new html_table_cell(userdate($status->extensionduedate)); 592 $row->cells = array($cell1, $cell2); 593 $t->data[] = $row; 594 $duedate = $status->extensionduedate; 595 } 596 597 // Time remaining. 598 $row = new html_table_row(); 599 $cell1 = new html_table_cell(get_string('timeremaining', 'assign')); 600 if ($duedate - $time <= 0) { 601 if (!$submission || 602 $submission->status != ASSIGN_SUBMISSION_STATUS_SUBMITTED) { 603 if ($status->submissionsenabled) { 604 $overduestr = get_string('overdue', 'assign', format_time($time - $duedate)); 605 $cell2 = new html_table_cell($overduestr); 606 $cell2->attributes = array('class'=>'overdue'); 607 } else { 608 $cell2 = new html_table_cell(get_string('duedatereached', 'assign')); 609 } 610 } else { 611 if ($submission->timemodified > $duedate) { 612 $latestr = get_string('submittedlate', 613 'assign', 614 format_time($submission->timemodified - $duedate)); 615 $cell2 = new html_table_cell($latestr); 616 $cell2->attributes = array('class'=>'latesubmission'); 617 } else { 618 $earlystr = get_string('submittedearly', 619 'assign', 620 format_time($submission->timemodified - $duedate)); 621 $cell2 = new html_table_cell($earlystr); 622 $cell2->attributes = array('class'=>'earlysubmission'); 623 } 624 } 625 } else { 626 $cell2 = new html_table_cell(format_time($duedate - $time)); 627 } 628 $row->cells = array($cell1, $cell2); 629 $t->data[] = $row; 630 } 631 632 // Show graders whether this submission is editable by students. 633 if ($status->view == assign_submission_status::GRADER_VIEW) { 634 $row = new html_table_row(); 635 $cell1 = new html_table_cell(get_string('editingstatus', 'assign')); 636 if ($status->canedit) { 637 $cell2 = new html_table_cell(get_string('submissioneditable', 'assign')); 638 $cell2->attributes = array('class'=>'submissioneditable'); 639 } else { 640 $cell2 = new html_table_cell(get_string('submissionnoteditable', 'assign')); 641 $cell2->attributes = array('class'=>'submissionnoteditable'); 642 } 643 $row->cells = array($cell1, $cell2); 644 $t->data[] = $row; 645 } 646 647 // Grading criteria preview. 648 if (!empty($status->gradingcontrollerpreview)) { 649 $row = new html_table_row(); 650 $cell1 = new html_table_cell(get_string('gradingmethodpreview', 'assign')); 651 $cell2 = new html_table_cell($status->gradingcontrollerpreview); 652 $row->cells = array($cell1, $cell2); 653 $t->data[] = $row; 654 } 655 656 // Last modified. 657 if ($submission) { 658 $row = new html_table_row(); 659 $cell1 = new html_table_cell(get_string('timemodified', 'assign')); 660 $cell2 = new html_table_cell(userdate($submission->timemodified)); 661 $row->cells = array($cell1, $cell2); 662 $t->data[] = $row; 663 664 foreach ($status->submissionplugins as $plugin) { 665 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions(); 666 if ($plugin->is_enabled() && 667 $plugin->is_visible() && 668 $plugin->has_user_summary() && 669 $pluginshowsummary) { 670 671 $row = new html_table_row(); 672 $cell1 = new html_table_cell($plugin->get_name()); 673 $displaymode = assign_submission_plugin_submission::SUMMARY; 674 $pluginsubmission = new assign_submission_plugin_submission($plugin, 675 $submission, 676 $displaymode, 677 $status->coursemoduleid, 678 $status->returnaction, 679 $status->returnparams); 680 $cell2 = new html_table_cell($this->render($pluginsubmission)); 681 $row->cells = array($cell1, $cell2); 682 $t->data[] = $row; 683 } 684 } 685 } 686 687 $o .= html_writer::table($t); 688 $o .= $this->output->box_end(); 689 690 // Links. 691 if ($status->view == assign_submission_status::STUDENT_VIEW) { 692 if ($status->canedit) { 693 if (!$submission || $submission->status == ASSIGN_SUBMISSION_STATUS_NEW) { 694 $o .= $this->output->box_start('generalbox submissionaction'); 695 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission'); 696 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams), 697 get_string('addsubmission', 'assign'), 'get'); 698 $o .= $this->output->box_start('boxaligncenter submithelp'); 699 $o .= get_string('editsubmission_help', 'assign'); 700 $o .= $this->output->box_end(); 701 $o .= $this->output->box_end(); 702 } else if ($submission->status == ASSIGN_SUBMISSION_STATUS_REOPENED) { 703 $o .= $this->output->box_start('generalbox submissionaction'); 704 $urlparams = array('id' => $status->coursemoduleid, 705 'action' => 'editprevioussubmission', 706 'sesskey'=>sesskey()); 707 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams), 708 get_string('addnewattemptfromprevious', 'assign'), 'get'); 709 $o .= $this->output->box_start('boxaligncenter submithelp'); 710 $o .= get_string('addnewattemptfromprevious_help', 'assign'); 711 $o .= $this->output->box_end(); 712 $o .= $this->output->box_end(); 713 $o .= $this->output->box_start('generalbox submissionaction'); 714 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission'); 715 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams), 716 get_string('addnewattempt', 'assign'), 'get'); 717 $o .= $this->output->box_start('boxaligncenter submithelp'); 718 $o .= get_string('addnewattempt_help', 'assign'); 719 $o .= $this->output->box_end(); 720 $o .= $this->output->box_end(); 721 } else { 722 $o .= $this->output->box_start('generalbox submissionaction'); 723 $urlparams = array('id' => $status->coursemoduleid, 'action' => 'editsubmission'); 724 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams), 725 get_string('editsubmission', 'assign'), 'get'); 726 $o .= $this->output->box_start('boxaligncenter submithelp'); 727 $o .= get_string('editsubmission_help', 'assign'); 728 $o .= $this->output->box_end(); 729 $o .= $this->output->box_end(); 730 } 731 } 732 733 if ($status->cansubmit) { 734 $urlparams = array('id' => $status->coursemoduleid, 'action'=>'submit'); 735 $o .= $this->output->box_start('generalbox submissionaction'); 736 $o .= $this->output->single_button(new moodle_url('/mod/assign/view.php', $urlparams), 737 get_string('submitassignment', 'assign'), 'get'); 738 $o .= $this->output->box_start('boxaligncenter submithelp'); 739 $o .= get_string('submitassignment_help', 'assign'); 740 $o .= $this->output->box_end(); 741 $o .= $this->output->box_end(); 742 } 743 } 744 745 $o .= $this->output->container_end(); 746 return $o; 747 } 748 749 /** 750 * Output the attempt history for this assignment 751 * 752 * @param assign_attempt_history $history 753 * @return string 754 */ 755 public function render_assign_attempt_history(assign_attempt_history $history) { 756 $o = ''; 757 758 $submittedstr = get_string('submitted', 'assign'); 759 $gradestr = get_string('grade'); 760 $gradedonstr = get_string('gradedon', 'assign'); 761 $gradedbystr = get_string('gradedby', 'assign'); 762 763 // Don't show the last one because it is the current submission. 764 array_pop($history->submissions); 765 766 // Show newest to oldest. 767 $history->submissions = array_reverse($history->submissions); 768 769 if (empty($history->submissions)) { 770 return ''; 771 } 772 773 $containerid = 'attempthistory' . uniqid(); 774 $o .= $this->heading(get_string('attempthistory', 'assign'), 3); 775 $o .= $this->box_start('attempthistory', $containerid); 776 777 foreach ($history->submissions as $i => $submission) { 778 $grade = null; 779 foreach ($history->grades as $onegrade) { 780 if ($onegrade->attemptnumber == $submission->attemptnumber) { 781 $grade = $onegrade; 782 break; 783 } 784 } 785 786 $editbtn = ''; 787 788 if ($submission) { 789 $submissionsummary = userdate($submission->timemodified); 790 } else { 791 $submissionsummary = get_string('nosubmission', 'assign'); 792 } 793 794 $attemptsummaryparams = array('attemptnumber'=>$submission->attemptnumber+1, 795 'submissionsummary'=>$submissionsummary); 796 $o .= $this->heading(get_string('attemptheading', 'assign', $attemptsummaryparams), 4); 797 798 $t = new html_table(); 799 800 if ($submission) { 801 $cell1 = new html_table_cell(get_string('submissionstatus', 'assign')); 802 $cell2 = new html_table_cell(get_string('submissionstatus_' . $submission->status, 'assign')); 803 $t->data[] = new html_table_row(array($cell1, $cell2)); 804 805 foreach ($history->submissionplugins as $plugin) { 806 $pluginshowsummary = !$plugin->is_empty($submission) || !$plugin->allow_submissions(); 807 if ($plugin->is_enabled() && 808 $plugin->is_visible() && 809 $plugin->has_user_summary() && 810 $pluginshowsummary) { 811 812 $cell1 = new html_table_cell($plugin->get_name()); 813 $pluginsubmission = new assign_submission_plugin_submission($plugin, 814 $submission, 815 assign_submission_plugin_submission::SUMMARY, 816 $history->coursemoduleid, 817 $history->returnaction, 818 $history->returnparams); 819 $cell2 = new html_table_cell($this->render($pluginsubmission)); 820 821 $t->data[] = new html_table_row(array($cell1, $cell2)); 822 } 823 } 824 } 825 826 if ($grade) { 827 // Heading 'feedback'. 828 $title = get_string('feedback', 'assign', $i); 829 $title .= $this->output->spacer(array('width'=>10)); 830 if ($history->cangrade) { 831 // Edit previous feedback. 832 $returnparams = http_build_query($history->returnparams); 833 $urlparams = array('id' => $history->coursemoduleid, 834 'rownum'=>$history->rownum, 835 'useridlistid'=>$history->useridlistid, 836 'attemptnumber'=>$grade->attemptnumber, 837 'action'=>'grade', 838 'returnaction'=>$history->returnaction, 839 'returnparams'=>$returnparams); 840 $url = new moodle_url('/mod/assign/view.php', $urlparams); 841 $icon = new pix_icon('gradefeedback', 842 get_string('editattemptfeedback', 'assign', $grade->attemptnumber+1), 843 'mod_assign'); 844 $title .= $this->output->action_icon($url, $icon); 845 } 846 $cell = new html_table_cell($title); 847 $cell->attributes['class'] = 'feedbacktitle'; 848 $cell->colspan = 2; 849 $t->data[] = new html_table_row(array($cell)); 850 851 // Grade. 852 $cell1 = new html_table_cell($gradestr); 853 $cell2 = $grade->gradefordisplay; 854 $t->data[] = new html_table_row(array($cell1, $cell2)); 855 856 // Graded on. 857 $cell1 = new html_table_cell($gradedonstr); 858 $cell2 = new html_table_cell(userdate($grade->timemodified)); 859 $t->data[] = new html_table_row(array($cell1, $cell2)); 860 861 // Graded by. 862 $cell1 = new html_table_cell($gradedbystr); 863 $cell2 = new html_table_cell($this->output->user_picture($grade->grader) . 864 $this->output->spacer(array('width'=>30)) . fullname($grade->grader)); 865 $t->data[] = new html_table_row(array($cell1, $cell2)); 866 867 // Feedback from plugins. 868 foreach ($history->feedbackplugins as $plugin) { 869 if ($plugin->is_enabled() && 870 $plugin->is_visible() && 871 $plugin->has_user_summary() && 872 !$plugin->is_empty($grade)) { 873 874 $cell1 = new html_table_cell($plugin->get_name()); 875 $pluginfeedback = new assign_feedback_plugin_feedback( 876 $plugin, $grade, assign_feedback_plugin_feedback::SUMMARY, $history->coursemoduleid, 877 $history->returnaction, $history->returnparams 878 ); 879 $cell2 = new html_table_cell($this->render($pluginfeedback)); 880 $t->data[] = new html_table_row(array($cell1, $cell2)); 881 } 882 883 } 884 885 } 886 887 $o .= html_writer::table($t); 888 } 889 $o .= $this->box_end(); 890 $jsparams = array($containerid); 891 892 $this->page->requires->yui_module('moodle-mod_assign-history', 'Y.one("#' . $containerid . '").history'); 893 894 return $o; 895 } 896 897 /** 898 * Render a submission plugin submission 899 * 900 * @param assign_submission_plugin_submission $submissionplugin 901 * @return string 902 */ 903 public function render_assign_submission_plugin_submission(assign_submission_plugin_submission $submissionplugin) { 904 $o = ''; 905 906 if ($submissionplugin->view == assign_submission_plugin_submission::SUMMARY) { 907 $showviewlink = false; 908 $summary = $submissionplugin->plugin->view_summary($submissionplugin->submission, 909 $showviewlink); 910 911 $classsuffix = $submissionplugin->plugin->get_subtype() . 912 '_' . 913 $submissionplugin->plugin->get_type() . 914 '_' . 915 $submissionplugin->submission->id; 916 917 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix); 918 919 $link = ''; 920 if ($showviewlink) { 921 $previewstr = get_string('viewsubmission', 'assign'); 922 $icon = $this->output->pix_icon('t/preview', $previewstr); 923 924 $expandstr = get_string('viewfull', 'assign'); 925 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix); 926 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options); 927 928 $jsparams = array($submissionplugin->plugin->get_subtype(), 929 $submissionplugin->plugin->get_type(), 930 $submissionplugin->submission->id); 931 932 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams); 933 934 $action = 'viewplugin' . $submissionplugin->plugin->get_subtype(); 935 $returnparams = http_build_query($submissionplugin->returnparams); 936 $link .= '<noscript>'; 937 $urlparams = array('id' => $submissionplugin->coursemoduleid, 938 'sid'=>$submissionplugin->submission->id, 939 'plugin'=>$submissionplugin->plugin->get_type(), 940 'action'=>$action, 941 'returnaction'=>$submissionplugin->returnaction, 942 'returnparams'=>$returnparams); 943 $url = new moodle_url('/mod/assign/view.php', $urlparams); 944 $link .= $this->output->action_link($url, $icon); 945 $link .= '</noscript>'; 946 947 $link .= $this->output->spacer(array('width'=>15)); 948 } 949 950 $o .= $link . $summary; 951 $o .= $this->output->box_end(); 952 if ($showviewlink) { 953 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix); 954 $classes = 'expandsummaryicon contract_' . $classsuffix; 955 $o .= $this->output->pix_icon('t/switch_minus', 956 get_string('viewsummary', 'assign'), 957 null, 958 array('class'=>$classes)); 959 $o .= $submissionplugin->plugin->view($submissionplugin->submission); 960 $o .= $this->output->box_end(); 961 } 962 } else if ($submissionplugin->view == assign_submission_plugin_submission::FULL) { 963 $o .= $this->output->box_start('boxaligncenter submissionfull'); 964 $o .= $submissionplugin->plugin->view($submissionplugin->submission); 965 $o .= $this->output->box_end(); 966 } 967 968 return $o; 969 } 970 971 /** 972 * Render the grading table. 973 * 974 * @param assign_grading_table $table 975 * @return string 976 */ 977 public function render_assign_grading_table(assign_grading_table $table) { 978 $o = ''; 979 $o .= $this->output->box_start('boxaligncenter gradingtable'); 980 981 $this->page->requires->js_init_call('M.mod_assign.init_grading_table', array()); 982 $this->page->requires->string_for_js('nousersselected', 'assign'); 983 $this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign'); 984 $this->page->requires->string_for_js('batchoperationconfirmlock', 'assign'); 985 $this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign'); 986 $this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign'); 987 $this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign'); 988 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign'); 989 $this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign'); 990 $this->page->requires->string_for_js('editaction', 'assign'); 991 foreach ($table->plugingradingbatchoperations as $plugin => $operations) { 992 foreach ($operations as $operation => $description) { 993 $this->page->requires->string_for_js('batchoperationconfirm' . $operation, 994 'assignfeedback_' . $plugin); 995 } 996 } 997 $o .= $this->flexible_table($table, $table->get_rows_per_page(), true); 998 $o .= $this->output->box_end(); 999 1000 return $o; 1001 } 1002 1003 /** 1004 * Render a feedback plugin feedback 1005 * 1006 * @param assign_feedback_plugin_feedback $feedbackplugin 1007 * @return string 1008 */ 1009 public function render_assign_feedback_plugin_feedback(assign_feedback_plugin_feedback $feedbackplugin) { 1010 $o = ''; 1011 1012 if ($feedbackplugin->view == assign_feedback_plugin_feedback::SUMMARY) { 1013 $showviewlink = false; 1014 $summary = $feedbackplugin->plugin->view_summary($feedbackplugin->grade, $showviewlink); 1015 1016 $classsuffix = $feedbackplugin->plugin->get_subtype() . 1017 '_' . 1018 $feedbackplugin->plugin->get_type() . 1019 '_' . 1020 $feedbackplugin->grade->id; 1021 $o .= $this->output->box_start('boxaligncenter plugincontentsummary summary_' . $classsuffix); 1022 1023 $link = ''; 1024 if ($showviewlink) { 1025 $previewstr = get_string('viewfeedback', 'assign'); 1026 $icon = $this->output->pix_icon('t/preview', $previewstr); 1027 1028 $expandstr = get_string('viewfull', 'assign'); 1029 $options = array('class'=>'expandsummaryicon expand_' . $classsuffix); 1030 $o .= $this->output->pix_icon('t/switch_plus', $expandstr, null, $options); 1031 1032 $jsparams = array($feedbackplugin->plugin->get_subtype(), 1033 $feedbackplugin->plugin->get_type(), 1034 $feedbackplugin->grade->id); 1035 $this->page->requires->js_init_call('M.mod_assign.init_plugin_summary', $jsparams); 1036 1037 $urlparams = array('id' => $feedbackplugin->coursemoduleid, 1038 'gid'=>$feedbackplugin->grade->id, 1039 'plugin'=>$feedbackplugin->plugin->get_type(), 1040 'action'=>'viewplugin' . $feedbackplugin->plugin->get_subtype(), 1041 'returnaction'=>$feedbackplugin->returnaction, 1042 'returnparams'=>http_build_query($feedbackplugin->returnparams)); 1043 $url = new moodle_url('/mod/assign/view.php', $urlparams); 1044 $link .= '<noscript>'; 1045 $link .= $this->output->action_link($url, $icon); 1046 $link .= '</noscript>'; 1047 1048 $link .= $this->output->spacer(array('width'=>15)); 1049 } 1050 1051 $o .= $link . $summary; 1052 $o .= $this->output->box_end(); 1053 if ($showviewlink) { 1054 $o .= $this->output->box_start('boxaligncenter hidefull full_' . $classsuffix); 1055 $classes = 'expandsummaryicon contract_' . $classsuffix; 1056 $o .= $this->output->pix_icon('t/switch_minus', 1057 get_string('viewsummary', 'assign'), 1058 null, 1059 array('class'=>$classes)); 1060 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade); 1061 $o .= $this->output->box_end(); 1062 } 1063 } else if ($feedbackplugin->view == assign_feedback_plugin_feedback::FULL) { 1064 $o .= $this->output->box_start('boxaligncenter feedbackfull'); 1065 $o .= $feedbackplugin->plugin->view($feedbackplugin->grade); 1066 $o .= $this->output->box_end(); 1067 } 1068 1069 return $o; 1070 } 1071 1072 /** 1073 * Render a course index summary 1074 * 1075 * @param assign_course_index_summary $indexsummary 1076 * @return string 1077 */ 1078 public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) { 1079 $o = ''; 1080 1081 $strplural = get_string('modulenameplural', 'assign'); 1082 $strsectionname = $indexsummary->courseformatname; 1083 $strduedate = get_string('duedate', 'assign'); 1084 $strsubmission = get_string('submission', 'assign'); 1085 $strgrade = get_string('grade'); 1086 1087 $table = new html_table(); 1088 if ($indexsummary->usesections) { 1089 $table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade); 1090 $table->align = array ('left', 'left', 'center', 'right', 'right'); 1091 } else { 1092 $table->head = array ($strplural, $strduedate, $strsubmission, $strgrade); 1093 $table->align = array ('left', 'left', 'center', 'right'); 1094 } 1095 $table->data = array(); 1096 1097 $currentsection = ''; 1098 foreach ($indexsummary->assignments as $info) { 1099 $params = array('id' => $info['cmid']); 1100 $link = html_writer::link(new moodle_url('/mod/assign/view.php', $params), 1101 $info['cmname']); 1102 $due = $info['timedue'] ? userdate($info['timedue']) : '-'; 1103 1104 $printsection = ''; 1105 if ($indexsummary->usesections) { 1106 if ($info['sectionname'] !== $currentsection) { 1107 if ($info['sectionname']) { 1108 $printsection = $info['sectionname']; 1109 } 1110 if ($currentsection !== '') { 1111 $table->data[] = 'hr'; 1112 } 1113 $currentsection = $info['sectionname']; 1114 } 1115 } 1116 1117 if ($indexsummary->usesections) { 1118 $row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']); 1119 } else { 1120 $row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']); 1121 } 1122 $table->data[] = $row; 1123 } 1124 1125 $o .= html_writer::table($table); 1126 1127 return $o; 1128 } 1129 1130 1131 1132 /** 1133 * Internal function - creates htmls structure suitable for YUI tree. 1134 * 1135 * @param assign_files $tree 1136 * @param array $dir 1137 * @return string 1138 */ 1139 protected function htmllize_tree(assign_files $tree, $dir) { 1140 global $CFG; 1141 $yuiconfig = array(); 1142 $yuiconfig['type'] = 'html'; 1143 1144 if (empty($dir['subdirs']) and empty($dir['files'])) { 1145 return ''; 1146 } 1147 1148 $result = '<ul>'; 1149 foreach ($dir['subdirs'] as $subdir) { 1150 $image = $this->output->pix_icon(file_folder_icon(), 1151 $subdir['dirname'], 1152 'moodle', 1153 array('class'=>'icon')); 1154 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' . 1155 '<div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' . 1156 $this->htmllize_tree($tree, $subdir) . 1157 '</li>'; 1158 } 1159 1160 foreach ($dir['files'] as $file) { 1161 $filename = $file->get_filename(); 1162 if ($CFG->enableplagiarism) { 1163 require_once($CFG->libdir.'/plagiarismlib.php'); 1164 $plagiarismlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 1165 'file'=>$file, 1166 'cmid'=>$tree->cm->id, 1167 'course'=>$tree->course)); 1168 } else { 1169 $plagiarismlinks = ''; 1170 } 1171 $image = $this->output->pix_icon(file_file_icon($file), 1172 $filename, 1173 'moodle', 1174 array('class'=>'icon')); 1175 $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'>' . 1176 '<div>' . $image . ' ' . 1177 $file->fileurl . ' ' . 1178 $plagiarismlinks . 1179 $file->portfoliobutton . '</div>' . 1180 '</li>'; 1181 } 1182 1183 $result .= '</ul>'; 1184 1185 return $result; 1186 } 1187 1188 /** 1189 * Helper method dealing with the fact we can not just fetch the output of flexible_table 1190 * 1191 * @param flexible_table $table The table to render 1192 * @param int $rowsperpage How many assignments to render in a page 1193 * @param bool $displaylinks - Whether to render links in the table 1194 * (e.g. downloads would not enable this) 1195 * @return string HTML 1196 */ 1197 protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) { 1198 1199 $o = ''; 1200 ob_start(); 1201 $table->out($rowsperpage, $displaylinks); 1202 $o = ob_get_contents(); 1203 ob_end_clean(); 1204 1205 return $o; 1206 } 1207 1208 /** 1209 * Helper method dealing with the fact we can not just fetch the output of moodleforms 1210 * 1211 * @param moodleform $mform 1212 * @return string HTML 1213 */ 1214 protected function moodleform(moodleform $mform) { 1215 1216 $o = ''; 1217 ob_start(); 1218 $mform->display(); 1219 $o = ob_get_contents(); 1220 ob_end_clean(); 1221 1222 return $o; 1223 } 1224 1225 } 1226
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |