[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/workshop/ -> renderer.php (source)

   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Workshop module renderering methods are defined here
  20   *
  21   * @package    mod_workshop
  22   * @copyright  2009 David Mudrak <[email protected]>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Workshop module renderer class
  30   *
  31   * @copyright 2009 David Mudrak <[email protected]>
  32   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class mod_workshop_renderer extends plugin_renderer_base {
  35  
  36      ////////////////////////////////////////////////////////////////////////////
  37      // External API - methods to render workshop renderable components
  38      ////////////////////////////////////////////////////////////////////////////
  39  
  40      /**
  41       * Renders workshop message
  42       *
  43       * @param workshop_message $message to display
  44       * @return string html code
  45       */
  46      protected function render_workshop_message(workshop_message $message) {
  47  
  48          $text   = $message->get_message();
  49          $url    = $message->get_action_url();
  50          $label  = $message->get_action_label();
  51  
  52          if (empty($text) and empty($label)) {
  53              return '';
  54          }
  55  
  56          switch ($message->get_type()) {
  57          case workshop_message::TYPE_OK:
  58              $sty = 'ok';
  59              break;
  60          case workshop_message::TYPE_ERROR:
  61              $sty = 'error';
  62              break;
  63          default:
  64              $sty = 'info';
  65          }
  66  
  67          $o = html_writer::tag('span', $message->get_message());
  68  
  69          if (!is_null($url) and !is_null($label)) {
  70              $o .= $this->output->single_button($url, $label, 'get');
  71          }
  72  
  73          return $this->output->container($o, array('message', $sty));
  74      }
  75  
  76  
  77      /**
  78       * Renders full workshop submission
  79       *
  80       * @param workshop_submission $submission
  81       * @return string HTML
  82       */
  83      protected function render_workshop_submission(workshop_submission $submission) {
  84          global $CFG;
  85  
  86          $o  = '';    // output HTML code
  87          $anonymous = $submission->is_anonymous();
  88          $classes = 'submission-full';
  89          if ($anonymous) {
  90              $classes .= ' anonymous';
  91          }
  92          $o .= $this->output->container_start($classes);
  93          $o .= $this->output->container_start('header');
  94  
  95          $title = format_string($submission->title);
  96  
  97          if ($this->page->url != $submission->url) {
  98              $title = html_writer::link($submission->url, $title);
  99          }
 100  
 101          $o .= $this->output->heading($title, 3, 'title');
 102  
 103          if (!$anonymous) {
 104              $author = new stdclass();
 105              $additionalfields = explode(',', user_picture::fields());
 106              $author = username_load_fields_from_object($author, $submission, 'author', $additionalfields);
 107              $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 64));
 108              $userurl            = new moodle_url('/user/view.php',
 109                                              array('id' => $author->id, 'course' => $this->page->course->id));
 110              $a                  = new stdclass();
 111              $a->name            = fullname($author);
 112              $a->url             = $userurl->out();
 113              $byfullname         = get_string('byfullname', 'workshop', $a);
 114              $oo  = $this->output->container($userpic, 'picture');
 115              $oo .= $this->output->container($byfullname, 'fullname');
 116  
 117              $o .= $this->output->container($oo, 'author');
 118          }
 119  
 120          $created = get_string('userdatecreated', 'workshop', userdate($submission->timecreated));
 121          $o .= $this->output->container($created, 'userdate created');
 122  
 123          if ($submission->timemodified > $submission->timecreated) {
 124              $modified = get_string('userdatemodified', 'workshop', userdate($submission->timemodified));
 125              $o .= $this->output->container($modified, 'userdate modified');
 126          }
 127  
 128          $o .= $this->output->container_end(); // end of header
 129  
 130          $content = file_rewrite_pluginfile_urls($submission->content, 'pluginfile.php', $this->page->context->id,
 131                                                          'mod_workshop', 'submission_content', $submission->id);
 132          $content = format_text($content, $submission->contentformat, array('overflowdiv'=>true));
 133          if (!empty($content)) {
 134              if (!empty($CFG->enableplagiarism)) {
 135                  require_once($CFG->libdir.'/plagiarismlib.php');
 136                  $content .= plagiarism_get_links(array('userid' => $submission->authorid,
 137                      'content' => $submission->content,
 138                      'cmid' => $this->page->cm->id,
 139                      'course' => $this->page->course));
 140              }
 141          }
 142          $o .= $this->output->container($content, 'content');
 143  
 144          $o .= $this->helper_submission_attachments($submission->id, 'html');
 145  
 146          $o .= $this->output->container_end(); // end of submission-full
 147  
 148          return $o;
 149      }
 150  
 151      /**
 152       * Renders short summary of the submission
 153       *
 154       * @param workshop_submission_summary $summary
 155       * @return string text to be echo'ed
 156       */
 157      protected function render_workshop_submission_summary(workshop_submission_summary $summary) {
 158  
 159          $o  = '';    // output HTML code
 160          $anonymous = $summary->is_anonymous();
 161          $classes = 'submission-summary';
 162  
 163          if ($anonymous) {
 164              $classes .= ' anonymous';
 165          }
 166  
 167          $gradestatus = '';
 168  
 169          if ($summary->status == 'notgraded') {
 170              $classes    .= ' notgraded';
 171              $gradestatus = $this->output->container(get_string('nogradeyet', 'workshop'), 'grade-status');
 172  
 173          } else if ($summary->status == 'graded') {
 174              $classes    .= ' graded';
 175              $gradestatus = $this->output->container(get_string('alreadygraded', 'workshop'), 'grade-status');
 176          }
 177  
 178          $o .= $this->output->container_start($classes);  // main wrapper
 179          $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title'));
 180  
 181          if (!$anonymous) {
 182              $author             = new stdClass();
 183              $additionalfields = explode(',', user_picture::fields());
 184              $author = username_load_fields_from_object($author, $summary, 'author', $additionalfields);
 185              $userpic            = $this->output->user_picture($author, array('courseid' => $this->page->course->id, 'size' => 35));
 186              $userurl            = new moodle_url('/user/view.php',
 187                                              array('id' => $author->id, 'course' => $this->page->course->id));
 188              $a                  = new stdClass();
 189              $a->name            = fullname($author);
 190              $a->url             = $userurl->out();
 191              $byfullname         = get_string('byfullname', 'workshop', $a);
 192  
 193              $oo  = $this->output->container($userpic, 'picture');
 194              $oo .= $this->output->container($byfullname, 'fullname');
 195              $o  .= $this->output->container($oo, 'author');
 196          }
 197  
 198          $created = get_string('userdatecreated', 'workshop', userdate($summary->timecreated));
 199          $o .= $this->output->container($created, 'userdate created');
 200  
 201          if ($summary->timemodified > $summary->timecreated) {
 202              $modified = get_string('userdatemodified', 'workshop', userdate($summary->timemodified));
 203              $o .= $this->output->container($modified, 'userdate modified');
 204          }
 205  
 206          $o .= $gradestatus;
 207          $o .= $this->output->container_end(); // end of the main wrapper
 208          return $o;
 209      }
 210  
 211      /**
 212       * Renders full workshop example submission
 213       *
 214       * @param workshop_example_submission $example
 215       * @return string HTML
 216       */
 217      protected function render_workshop_example_submission(workshop_example_submission $example) {
 218  
 219          $o  = '';    // output HTML code
 220          $classes = 'submission-full example';
 221          $o .= $this->output->container_start($classes);
 222          $o .= $this->output->container_start('header');
 223          $o .= $this->output->container(format_string($example->title), array('class' => 'title'));
 224          $o .= $this->output->container_end(); // end of header
 225  
 226          $content = file_rewrite_pluginfile_urls($example->content, 'pluginfile.php', $this->page->context->id,
 227                                                          'mod_workshop', 'submission_content', $example->id);
 228          $content = format_text($content, $example->contentformat, array('overflowdiv'=>true));
 229          $o .= $this->output->container($content, 'content');
 230  
 231          $o .= $this->helper_submission_attachments($example->id, 'html');
 232  
 233          $o .= $this->output->container_end(); // end of submission-full
 234  
 235          return $o;
 236      }
 237  
 238      /**
 239       * Renders short summary of the example submission
 240       *
 241       * @param workshop_example_submission_summary $summary
 242       * @return string text to be echo'ed
 243       */
 244      protected function render_workshop_example_submission_summary(workshop_example_submission_summary $summary) {
 245  
 246          $o  = '';    // output HTML code
 247  
 248          // wrapping box
 249          $o .= $this->output->box_start('generalbox example-summary ' . $summary->status);
 250  
 251          // title
 252          $o .= $this->output->container_start('example-title');
 253          $o .= html_writer::link($summary->url, format_string($summary->title), array('class' => 'title'));
 254  
 255          if ($summary->editable) {
 256              $o .= $this->output->action_icon($summary->editurl, new pix_icon('i/edit', get_string('edit')));
 257          }
 258          $o .= $this->output->container_end();
 259  
 260          // additional info
 261          if ($summary->status == 'notgraded') {
 262              $o .= $this->output->container(get_string('nogradeyet', 'workshop'), 'example-info nograde');
 263          } else {
 264              $o .= $this->output->container(get_string('gradeinfo', 'workshop' , $summary->gradeinfo), 'example-info grade');
 265          }
 266  
 267          // button to assess
 268          $button = new single_button($summary->assessurl, $summary->assesslabel, 'get');
 269          $o .= $this->output->container($this->output->render($button), 'example-actions');
 270  
 271          // end of wrapping box
 272          $o .= $this->output->box_end();
 273  
 274          return $o;
 275      }
 276  
 277      /**
 278       * Renders the user plannner tool
 279       *
 280       * @param workshop_user_plan $plan prepared for the user
 281       * @return string html code to be displayed
 282       */
 283      protected function render_workshop_user_plan(workshop_user_plan $plan) {
 284          $table = new html_table();
 285          $table->attributes['class'] = 'userplan';
 286          $table->head = array();
 287          $table->colclasses = array();
 288          $row = new html_table_row();
 289          $row->attributes['class'] = 'phasetasks';
 290          foreach ($plan->phases as $phasecode => $phase) {
 291              $title = html_writer::tag('span', $phase->title);
 292              $actions = '';
 293              foreach ($phase->actions as $action) {
 294                  switch ($action->type) {
 295                  case 'switchphase':
 296                      $icon = 'i/marker';
 297                      if ($phasecode == workshop::PHASE_ASSESSMENT
 298                              and $plan->workshop->phase == workshop::PHASE_SUBMISSION
 299                              and $plan->workshop->phaseswitchassessment) {
 300                          $icon = 'i/scheduled';
 301                      }
 302                      $actions .= $this->output->action_icon($action->url, new pix_icon($icon, get_string('switchphase', 'workshop')));
 303                      break;
 304                  }
 305              }
 306              if (!empty($actions)) {
 307                  $actions = $this->output->container($actions, 'actions');
 308              }
 309              $table->head[] = $this->output->container($title . $actions);
 310              $classes = 'phase' . $phasecode;
 311              if ($phase->active) {
 312                  $classes .= ' active';
 313              } else {
 314                  $classes .= ' nonactive';
 315              }
 316              $table->colclasses[] = $classes;
 317              $cell = new html_table_cell();
 318              $cell->text = $this->helper_user_plan_tasks($phase->tasks);
 319              $row->cells[] = $cell;
 320          }
 321          $table->data = array($row);
 322  
 323          return html_writer::table($table);
 324      }
 325  
 326      /**
 327       * Renders the result of the submissions allocation process
 328       *
 329       * @param workshop_allocation_result $result as returned by the allocator's init() method
 330       * @return string HTML to be echoed
 331       */
 332      protected function render_workshop_allocation_result(workshop_allocation_result $result) {
 333          global $CFG;
 334  
 335          $status = $result->get_status();
 336  
 337          if (is_null($status) or $status == workshop_allocation_result::STATUS_VOID) {
 338              debugging('Attempt to render workshop_allocation_result with empty status', DEBUG_DEVELOPER);
 339              return '';
 340          }
 341  
 342          switch ($status) {
 343          case workshop_allocation_result::STATUS_FAILED:
 344              if ($message = $result->get_message()) {
 345                  $message = new workshop_message($message, workshop_message::TYPE_ERROR);
 346              } else {
 347                  $message = new workshop_message(get_string('allocationerror', 'workshop'), workshop_message::TYPE_ERROR);
 348              }
 349              break;
 350  
 351          case workshop_allocation_result::STATUS_CONFIGURED:
 352              if ($message = $result->get_message()) {
 353                  $message = new workshop_message($message, workshop_message::TYPE_INFO);
 354              } else {
 355                  $message = new workshop_message(get_string('allocationconfigured', 'workshop'), workshop_message::TYPE_INFO);
 356              }
 357              break;
 358  
 359          case workshop_allocation_result::STATUS_EXECUTED:
 360              if ($message = $result->get_message()) {
 361                  $message = new workshop_message($message, workshop_message::TYPE_OK);
 362              } else {
 363                  $message = new workshop_message(get_string('allocationdone', 'workshop'), workshop_message::TYPE_OK);
 364              }
 365              break;
 366  
 367          default:
 368              throw new coding_exception('Unknown allocation result status', $status);
 369          }
 370  
 371          // start with the message
 372          $o = $this->render($message);
 373  
 374          // display the details about the process if available
 375          $logs = $result->get_logs();
 376          if (is_array($logs) and !empty($logs)) {
 377              $o .= html_writer::start_tag('ul', array('class' => 'allocation-init-results'));
 378              foreach ($logs as $log) {
 379                  if ($log->type == 'debug' and !$CFG->debugdeveloper) {
 380                      // display allocation debugging messages for developers only
 381                      continue;
 382                  }
 383                  $class = $log->type;
 384                  if ($log->indent) {
 385                      $class .= ' indent';
 386                  }
 387                  $o .= html_writer::tag('li', $log->message, array('class' => $class)).PHP_EOL;
 388              }
 389              $o .= html_writer::end_tag('ul');
 390          }
 391  
 392          return $o;
 393      }
 394  
 395      /**
 396       * Renders the workshop grading report
 397       *
 398       * @param workshop_grading_report $gradingreport
 399       * @return string html code
 400       */
 401      protected function render_workshop_grading_report(workshop_grading_report $gradingreport) {
 402  
 403          $data       = $gradingreport->get_data();
 404          $options    = $gradingreport->get_options();
 405          $grades     = $data->grades;
 406          $userinfo   = $data->userinfo;
 407  
 408          if (empty($grades)) {
 409              return '';
 410          }
 411  
 412          $table = new html_table();
 413          $table->attributes['class'] = 'grading-report';
 414  
 415          $sortbyfirstname = $this->helper_sortable_heading(get_string('firstname'), 'firstname', $options->sortby, $options->sorthow);
 416          $sortbylastname = $this->helper_sortable_heading(get_string('lastname'), 'lastname', $options->sortby, $options->sorthow);
 417          if (self::fullname_format() == 'lf') {
 418              $sortbyname = $sortbylastname . ' / ' . $sortbyfirstname;
 419          } else {
 420              $sortbyname = $sortbyfirstname . ' / ' . $sortbylastname;
 421          }
 422  
 423          $table->head = array();
 424          $table->head[] = $sortbyname;
 425          $table->head[] = $this->helper_sortable_heading(get_string('submission', 'workshop'), 'submissiontitle',
 426                  $options->sortby, $options->sorthow);
 427          $table->head[] = $this->helper_sortable_heading(get_string('receivedgrades', 'workshop'));
 428          if ($options->showsubmissiongrade) {
 429              $table->head[] = $this->helper_sortable_heading(get_string('submissiongradeof', 'workshop', $data->maxgrade),
 430                      'submissiongrade', $options->sortby, $options->sorthow);
 431          }
 432          $table->head[] = $this->helper_sortable_heading(get_string('givengrades', 'workshop'));
 433          if ($options->showgradinggrade) {
 434              $table->head[] = $this->helper_sortable_heading(get_string('gradinggradeof', 'workshop', $data->maxgradinggrade),
 435                      'gradinggrade', $options->sortby, $options->sorthow);
 436          }
 437  
 438          $table->rowclasses  = array();
 439          $table->colclasses  = array();
 440          $table->data        = array();
 441  
 442          foreach ($grades as $participant) {
 443              $numofreceived  = count($participant->reviewedby);
 444              $numofgiven     = count($participant->reviewerof);
 445              $published      = $participant->submissionpublished;
 446  
 447              // compute the number of <tr> table rows needed to display this participant
 448              if ($numofreceived > 0 and $numofgiven > 0) {
 449                  $numoftrs       = workshop::lcm($numofreceived, $numofgiven);
 450                  $spanreceived   = $numoftrs / $numofreceived;
 451                  $spangiven      = $numoftrs / $numofgiven;
 452              } elseif ($numofreceived == 0 and $numofgiven > 0) {
 453                  $numoftrs       = $numofgiven;
 454                  $spanreceived   = $numoftrs;
 455                  $spangiven      = $numoftrs / $numofgiven;
 456              } elseif ($numofreceived > 0 and $numofgiven == 0) {
 457                  $numoftrs       = $numofreceived;
 458                  $spanreceived   = $numoftrs / $numofreceived;
 459                  $spangiven      = $numoftrs;
 460              } else {
 461                  $numoftrs       = 1;
 462                  $spanreceived   = 1;
 463                  $spangiven      = 1;
 464              }
 465  
 466              for ($tr = 0; $tr < $numoftrs; $tr++) {
 467                  $row = new html_table_row();
 468                  if ($published) {
 469                      $row->attributes['class'] = 'published';
 470                  }
 471                  // column #1 - participant - spans over all rows
 472                  if ($tr == 0) {
 473                      $cell = new html_table_cell();
 474                      $cell->text = $this->helper_grading_report_participant($participant, $userinfo);
 475                      $cell->rowspan = $numoftrs;
 476                      $cell->attributes['class'] = 'participant';
 477                      $row->cells[] = $cell;
 478                  }
 479                  // column #2 - submission - spans over all rows
 480                  if ($tr == 0) {
 481                      $cell = new html_table_cell();
 482                      $cell->text = $this->helper_grading_report_submission($participant);
 483                      $cell->rowspan = $numoftrs;
 484                      $cell->attributes['class'] = 'submission';
 485                      $row->cells[] = $cell;
 486                  }
 487                  // column #3 - received grades
 488                  if ($tr % $spanreceived == 0) {
 489                      $idx = intval($tr / $spanreceived);
 490                      $assessment = self::array_nth($participant->reviewedby, $idx);
 491                      $cell = new html_table_cell();
 492                      $cell->text = $this->helper_grading_report_assessment($assessment, $options->showreviewernames, $userinfo,
 493                              get_string('gradereceivedfrom', 'workshop'));
 494                      $cell->rowspan = $spanreceived;
 495                      $cell->attributes['class'] = 'receivedgrade';
 496                      if (is_null($assessment) or is_null($assessment->grade)) {
 497                          $cell->attributes['class'] .= ' null';
 498                      } else {
 499                          $cell->attributes['class'] .= ' notnull';
 500                      }
 501                      $row->cells[] = $cell;
 502                  }
 503                  // column #4 - total grade for submission
 504                  if ($options->showsubmissiongrade and $tr == 0) {
 505                      $cell = new html_table_cell();
 506                      $cell->text = $this->helper_grading_report_grade($participant->submissiongrade, $participant->submissiongradeover);
 507                      $cell->rowspan = $numoftrs;
 508                      $cell->attributes['class'] = 'submissiongrade';
 509                      $row->cells[] = $cell;
 510                  }
 511                  // column #5 - given grades
 512                  if ($tr % $spangiven == 0) {
 513                      $idx = intval($tr / $spangiven);
 514                      $assessment = self::array_nth($participant->reviewerof, $idx);
 515                      $cell = new html_table_cell();
 516                      $cell->text = $this->helper_grading_report_assessment($assessment, $options->showauthornames, $userinfo,
 517                              get_string('gradegivento', 'workshop'));
 518                      $cell->rowspan = $spangiven;
 519                      $cell->attributes['class'] = 'givengrade';
 520                      if (is_null($assessment) or is_null($assessment->grade)) {
 521                          $cell->attributes['class'] .= ' null';
 522                      } else {
 523                          $cell->attributes['class'] .= ' notnull';
 524                      }
 525                      $row->cells[] = $cell;
 526                  }
 527                  // column #6 - total grade for assessment
 528                  if ($options->showgradinggrade and $tr == 0) {
 529                      $cell = new html_table_cell();
 530                      $cell->text = $this->helper_grading_report_grade($participant->gradinggrade);
 531                      $cell->rowspan = $numoftrs;
 532                      $cell->attributes['class'] = 'gradinggrade';
 533                      $row->cells[] = $cell;
 534                  }
 535  
 536                  $table->data[] = $row;
 537              }
 538          }
 539  
 540          return html_writer::table($table);
 541      }
 542  
 543      /**
 544       * Renders the feedback for the author of the submission
 545       *
 546       * @param workshop_feedback_author $feedback
 547       * @return string HTML
 548       */
 549      protected function render_workshop_feedback_author(workshop_feedback_author $feedback) {
 550          return $this->helper_render_feedback($feedback);
 551      }
 552  
 553      /**
 554       * Renders the feedback for the reviewer of the submission
 555       *
 556       * @param workshop_feedback_reviewer $feedback
 557       * @return string HTML
 558       */
 559      protected function render_workshop_feedback_reviewer(workshop_feedback_reviewer $feedback) {
 560          return $this->helper_render_feedback($feedback);
 561      }
 562  
 563      /**
 564       * Helper method to rendering feedback
 565       *
 566       * @param workshop_feedback_author|workshop_feedback_reviewer $feedback
 567       * @return string HTML
 568       */
 569      private function helper_render_feedback($feedback) {
 570  
 571          $o  = '';    // output HTML code
 572          $o .= $this->output->container_start('feedback feedbackforauthor');
 573          $o .= $this->output->container_start('header');
 574          $o .= $this->output->heading(get_string('feedbackby', 'workshop', s(fullname($feedback->get_provider()))), 3, 'title');
 575  
 576          $userpic = $this->output->user_picture($feedback->get_provider(), array('courseid' => $this->page->course->id, 'size' => 32));
 577          $o .= $this->output->container($userpic, 'picture');
 578          $o .= $this->output->container_end(); // end of header
 579  
 580          $content = format_text($feedback->get_content(), $feedback->get_format(), array('overflowdiv' => true));
 581          $o .= $this->output->container($content, 'content');
 582  
 583          $o .= $this->output->container_end();
 584  
 585          return $o;
 586      }
 587  
 588      /**
 589       * Renders the full assessment
 590       *
 591       * @param workshop_assessment $assessment
 592       * @return string HTML
 593       */
 594      protected function render_workshop_assessment(workshop_assessment $assessment) {
 595  
 596          $o = ''; // output HTML code
 597          $anonymous = is_null($assessment->reviewer);
 598          $classes = 'assessment-full';
 599          if ($anonymous) {
 600              $classes .= ' anonymous';
 601          }
 602  
 603          $o .= $this->output->container_start($classes);
 604          $o .= $this->output->container_start('header');
 605  
 606          if (!empty($assessment->title)) {
 607              $title = s($assessment->title);
 608          } else {
 609              $title = get_string('assessment', 'workshop');
 610          }
 611          if (($assessment->url instanceof moodle_url) and ($this->page->url != $assessment->url)) {
 612              $o .= $this->output->container(html_writer::link($assessment->url, $title), 'title');
 613          } else {
 614              $o .= $this->output->container($title, 'title');
 615          }
 616  
 617          if (!$anonymous) {
 618              $reviewer   = $assessment->reviewer;
 619              $userpic    = $this->output->user_picture($reviewer, array('courseid' => $this->page->course->id, 'size' => 32));
 620  
 621              $userurl    = new moodle_url('/user/view.php',
 622                                         array('id' => $reviewer->id, 'course' => $this->page->course->id));
 623              $a          = new stdClass();
 624              $a->name    = fullname($reviewer);
 625              $a->url     = $userurl->out();
 626              $byfullname = get_string('assessmentby', 'workshop', $a);
 627              $oo         = $this->output->container($userpic, 'picture');
 628              $oo        .= $this->output->container($byfullname, 'fullname');
 629  
 630              $o .= $this->output->container($oo, 'reviewer');
 631          }
 632  
 633          if (is_null($assessment->realgrade)) {
 634              $o .= $this->output->container(
 635                  get_string('notassessed', 'workshop'),
 636                  'grade nograde'
 637              );
 638          } else {
 639              $a              = new stdClass();
 640              $a->max         = $assessment->maxgrade;
 641              $a->received    = $assessment->realgrade;
 642              $o .= $this->output->container(
 643                  get_string('gradeinfo', 'workshop', $a),
 644                  'grade'
 645              );
 646  
 647              if (!is_null($assessment->weight) and $assessment->weight != 1) {
 648                  $o .= $this->output->container(
 649                      get_string('weightinfo', 'workshop', $assessment->weight),
 650                      'weight'
 651                  );
 652              }
 653          }
 654  
 655          $o .= $this->output->container_start('actions');
 656          foreach ($assessment->actions as $action) {
 657              $o .= $this->output->single_button($action->url, $action->label, $action->method);
 658          }
 659          $o .= $this->output->container_end(); // actions
 660  
 661          $o .= $this->output->container_end(); // header
 662  
 663          if (!is_null($assessment->form)) {
 664              $o .= print_collapsible_region_start('assessment-form-wrapper', uniqid('workshop-assessment'),
 665                      get_string('assessmentform', 'workshop'), '', false, true);
 666              $o .= $this->output->container(self::moodleform($assessment->form), 'assessment-form');
 667              $o .= print_collapsible_region_end(true);
 668  
 669              if (!$assessment->form->is_editable()) {
 670                  $o .= $this->overall_feedback($assessment);
 671              }
 672          }
 673  
 674          $o .= $this->output->container_end(); // main wrapper
 675  
 676          return $o;
 677      }
 678  
 679      /**
 680       * Renders the assessment of an example submission
 681       *
 682       * @param workshop_example_assessment $assessment
 683       * @return string HTML
 684       */
 685      protected function render_workshop_example_assessment(workshop_example_assessment $assessment) {
 686          return $this->render_workshop_assessment($assessment);
 687      }
 688  
 689      /**
 690       * Renders the reference assessment of an example submission
 691       *
 692       * @param workshop_example_reference_assessment $assessment
 693       * @return string HTML
 694       */
 695      protected function render_workshop_example_reference_assessment(workshop_example_reference_assessment $assessment) {
 696          return $this->render_workshop_assessment($assessment);
 697      }
 698  
 699      /**
 700       * Renders the overall feedback for the author of the submission
 701       *
 702       * @param workshop_assessment $assessment
 703       * @return string HTML
 704       */
 705      protected function overall_feedback(workshop_assessment $assessment) {
 706  
 707          $content = $assessment->get_overall_feedback_content();
 708  
 709          if ($content === false) {
 710              return '';
 711          }
 712  
 713          $o = '';
 714  
 715          if (!is_null($content)) {
 716              $o .= $this->output->container($content, 'content');
 717          }
 718  
 719          $attachments = $assessment->get_overall_feedback_attachments();
 720  
 721          if (!empty($attachments)) {
 722              $o .= $this->output->container_start('attachments');
 723              $images = '';
 724              $files = '';
 725              foreach ($attachments as $attachment) {
 726                  $icon = $this->output->pix_icon(file_file_icon($attachment), get_mimetype_description($attachment),
 727                      'moodle', array('class' => 'icon'));
 728                  $link = html_writer::link($attachment->fileurl, $icon.' '.substr($attachment->filepath.$attachment->filename, 1));
 729                  if (file_mimetype_in_typegroup($attachment->mimetype, 'web_image')) {
 730                      $preview = html_writer::empty_tag('img', array('src' => $attachment->previewurl, 'alt' => '', 'class' => 'preview'));
 731                      $preview = html_writer::tag('a', $preview, array('href' => $attachment->fileurl));
 732                      $images .= $this->output->container($preview);
 733                  } else {
 734                      $files .= html_writer::tag('li', $link, array('class' => $attachment->mimetype));
 735                  }
 736              }
 737              if ($images) {
 738                  $images = $this->output->container($images, 'images');
 739              }
 740  
 741              if ($files) {
 742                  $files = html_writer::tag('ul', $files, array('class' => 'files'));
 743              }
 744  
 745              $o .= $images.$files;
 746              $o .= $this->output->container_end();
 747          }
 748  
 749          if ($o === '') {
 750              return '';
 751          }
 752  
 753          $o = $this->output->box($o, 'overallfeedback');
 754          $o = print_collapsible_region($o, 'overall-feedback-wrapper', uniqid('workshop-overall-feedback'),
 755              get_string('overallfeedback', 'workshop'), '', false, true);
 756  
 757          return $o;
 758      }
 759  
 760      /**
 761       * Renders a perpage selector for workshop listings
 762       *
 763       * The scripts using this have to define the $PAGE->url prior to calling this
 764       * and deal with eventually submitted value themselves.
 765       *
 766       * @param int $current current value of the perpage parameter
 767       * @return string HTML
 768       */
 769      public function perpage_selector($current=10) {
 770  
 771          $options = array();
 772          foreach (array(10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 500, 1000) as $option) {
 773              if ($option != $current) {
 774                  $options[$option] = $option;
 775              }
 776          }
 777          $select = new single_select($this->page->url, 'perpage', $options, '', array('' => get_string('showingperpagechange', 'mod_workshop')));
 778          $select->label = get_string('showingperpage', 'mod_workshop', $current);
 779          $select->method = 'post';
 780  
 781          return $this->output->container($this->output->render($select), 'perpagewidget');
 782      }
 783  
 784      /**
 785       * Renders the user's final grades
 786       *
 787       * @param workshop_final_grades $grades with the info about grades in the gradebook
 788       * @return string HTML
 789       */
 790      protected function render_workshop_final_grades(workshop_final_grades $grades) {
 791  
 792          $out = html_writer::start_tag('div', array('class' => 'finalgrades'));
 793  
 794          if (!empty($grades->submissiongrade)) {
 795              $cssclass = 'grade submissiongrade';
 796              if ($grades->submissiongrade->hidden) {
 797                  $cssclass .= ' hiddengrade';
 798              }
 799              $out .= html_writer::tag(
 800                  'div',
 801                  html_writer::tag('div', get_string('submissiongrade', 'mod_workshop'), array('class' => 'gradetype')) .
 802                  html_writer::tag('div', $grades->submissiongrade->str_long_grade, array('class' => 'gradevalue')),
 803                  array('class' => $cssclass)
 804              );
 805          }
 806  
 807          if (!empty($grades->assessmentgrade)) {
 808              $cssclass = 'grade assessmentgrade';
 809              if ($grades->assessmentgrade->hidden) {
 810                  $cssclass .= ' hiddengrade';
 811              }
 812              $out .= html_writer::tag(
 813                  'div',
 814                  html_writer::tag('div', get_string('gradinggrade', 'mod_workshop'), array('class' => 'gradetype')) .
 815                  html_writer::tag('div', $grades->assessmentgrade->str_long_grade, array('class' => 'gradevalue')),
 816                  array('class' => $cssclass)
 817              );
 818          }
 819  
 820          $out .= html_writer::end_tag('div');
 821  
 822          return $out;
 823      }
 824  
 825      ////////////////////////////////////////////////////////////////////////////
 826      // Internal rendering helper methods
 827      ////////////////////////////////////////////////////////////////////////////
 828  
 829      /**
 830       * Renders a list of files attached to the submission
 831       *
 832       * If format==html, then format a html string. If format==text, then format a text-only string.
 833       * Otherwise, returns html for non-images and html to display the image inline.
 834       *
 835       * @param int $submissionid submission identifier
 836       * @param string format the format of the returned string - html|text
 837       * @return string formatted text to be echoed
 838       */
 839      protected function helper_submission_attachments($submissionid, $format = 'html') {
 840          global $CFG;
 841          require_once($CFG->libdir.'/filelib.php');
 842  
 843          $fs     = get_file_storage();
 844          $ctx    = $this->page->context;
 845          $files  = $fs->get_area_files($ctx->id, 'mod_workshop', 'submission_attachment', $submissionid);
 846  
 847          $outputimgs     = '';   // images to be displayed inline
 848          $outputfiles    = '';   // list of attachment files
 849  
 850          foreach ($files as $file) {
 851              if ($file->is_directory()) {
 852                  continue;
 853              }
 854  
 855              $filepath   = $file->get_filepath();
 856              $filename   = $file->get_filename();
 857              $fileurl    = moodle_url::make_pluginfile_url($ctx->id, 'mod_workshop', 'submission_attachment',
 858                              $submissionid, $filepath, $filename, true);
 859              $embedurl   = moodle_url::make_pluginfile_url($ctx->id, 'mod_workshop', 'submission_attachment',
 860                              $submissionid, $filepath, $filename, false);
 861              $embedurl   = new moodle_url($embedurl, array('preview' => 'bigthumb'));
 862              $type       = $file->get_mimetype();
 863              $image      = $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon'));
 864  
 865              $linkhtml   = html_writer::link($fileurl, $image) . substr($filepath, 1) . html_writer::link($fileurl, $filename);
 866              $linktxt    = "$filename [$fileurl]";
 867  
 868              if ($format == 'html') {
 869                  if (file_mimetype_in_typegroup($type, 'web_image')) {
 870                      $preview     = html_writer::empty_tag('img', array('src' => $embedurl, 'alt' => '', 'class' => 'preview'));
 871                      $preview     = html_writer::tag('a', $preview, array('href' => $fileurl));
 872                      $outputimgs .= $this->output->container($preview);
 873  
 874                  } else {
 875                      $outputfiles .= html_writer::tag('li', $linkhtml, array('class' => $type));
 876                  }
 877  
 878              } else if ($format == 'text') {
 879                  $outputfiles .= $linktxt . PHP_EOL;
 880              }
 881  
 882              if (!empty($CFG->enableplagiarism)) {
 883                  require_once($CFG->libdir.'/plagiarismlib.php');
 884                  $outputfiles .= plagiarism_get_links(array('userid' => $file->get_userid(),
 885                      'file' => $file,
 886                      'cmid' => $this->page->cm->id,
 887                      'course' => $this->page->course->id));
 888              }
 889          }
 890  
 891          if ($format == 'html') {
 892              if ($outputimgs) {
 893                  $outputimgs = $this->output->container($outputimgs, 'images');
 894              }
 895  
 896              if ($outputfiles) {
 897                  $outputfiles = html_writer::tag('ul', $outputfiles, array('class' => 'files'));
 898              }
 899  
 900              return $this->output->container($outputimgs . $outputfiles, 'attachments');
 901  
 902          } else {
 903              return $outputfiles;
 904          }
 905      }
 906  
 907      /**
 908       * Renders the tasks for the single phase in the user plan
 909       *
 910       * @param stdClass $tasks
 911       * @return string html code
 912       */
 913      protected function helper_user_plan_tasks(array $tasks) {
 914          $out = '';
 915          foreach ($tasks as $taskcode => $task) {
 916              $classes = '';
 917              $icon = null;
 918              if ($task->completed === true) {
 919                  $classes .= ' completed';
 920              } elseif ($task->completed === false) {
 921                  $classes .= ' fail';
 922              } elseif ($task->completed === 'info') {
 923                  $classes .= ' info';
 924              }
 925              if (is_null($task->link)) {
 926                  $title = $task->title;
 927              } else {
 928                  $title = html_writer::link($task->link, $task->title);
 929              }
 930              $title = $this->output->container($title, 'title');
 931              $details = $this->output->container($task->details, 'details');
 932              $out .= html_writer::tag('li', $title . $details, array('class' => $classes));
 933          }
 934          if ($out) {
 935              $out = html_writer::tag('ul', $out, array('class' => 'tasks'));
 936          }
 937          return $out;
 938      }
 939  
 940      /**
 941       * Renders a text with icons to sort by the given column
 942       *
 943       * This is intended for table headings.
 944       *
 945       * @param string $text    The heading text
 946       * @param string $sortid  The column id used for sorting
 947       * @param string $sortby  Currently sorted by (column id)
 948       * @param string $sorthow Currently sorted how (ASC|DESC)
 949       *
 950       * @return string
 951       */
 952      protected function helper_sortable_heading($text, $sortid=null, $sortby=null, $sorthow=null) {
 953          global $PAGE;
 954  
 955          $out = html_writer::tag('span', $text, array('class'=>'text'));
 956  
 957          if (!is_null($sortid)) {
 958              if ($sortby !== $sortid or $sorthow !== 'ASC') {
 959                  $url = new moodle_url($PAGE->url);
 960                  $url->params(array('sortby' => $sortid, 'sorthow' => 'ASC'));
 961                  $out .= $this->output->action_icon($url, new pix_icon('t/sort_asc', get_string('sortasc', 'workshop')),
 962                      null, array('class' => 'iconsort sort asc'));
 963              }
 964              if ($sortby !== $sortid or $sorthow !== 'DESC') {
 965                  $url = new moodle_url($PAGE->url);
 966                  $url->params(array('sortby' => $sortid, 'sorthow' => 'DESC'));
 967                  $out .= $this->output->action_icon($url, new pix_icon('t/sort_desc', get_string('sortdesc', 'workshop')),
 968                      null, array('class' => 'iconsort sort desc'));
 969              }
 970          }
 971          return $out;
 972  }
 973  
 974      /**
 975       * @param stdClass $participant
 976       * @param array $userinfo
 977       * @return string
 978       */
 979      protected function helper_grading_report_participant(stdclass $participant, array $userinfo) {
 980          $userid = $participant->userid;
 981          $out  = $this->output->user_picture($userinfo[$userid], array('courseid' => $this->page->course->id, 'size' => 35));
 982          $out .= html_writer::tag('span', fullname($userinfo[$userid]));
 983  
 984          return $out;
 985      }
 986  
 987      /**
 988       * @param stdClass $participant
 989       * @return string
 990       */
 991      protected function helper_grading_report_submission(stdclass $participant) {
 992          global $CFG;
 993  
 994          if (is_null($participant->submissionid)) {
 995              $out = $this->output->container(get_string('nosubmissionfound', 'workshop'), 'info');
 996          } else {
 997              $url = new moodle_url('/mod/workshop/submission.php',
 998                                    array('cmid' => $this->page->context->instanceid, 'id' => $participant->submissionid));
 999              $out = html_writer::link($url, format_string($participant->submissiontitle), array('class'=>'title'));
1000          }
1001  
1002          return $out;
1003      }
1004  
1005      /**
1006       * @todo Highlight the nulls
1007       * @param stdClass|null $assessment
1008       * @param bool $shownames
1009       * @param string $separator between the grade and the reviewer/author
1010       * @return string
1011       */
1012      protected function helper_grading_report_assessment($assessment, $shownames, array $userinfo, $separator) {
1013          global $CFG;
1014  
1015          if (is_null($assessment)) {
1016              return get_string('nullgrade', 'workshop');
1017          }
1018          $a = new stdclass();
1019          $a->grade = is_null($assessment->grade) ? get_string('nullgrade', 'workshop') : $assessment->grade;
1020          $a->gradinggrade = is_null($assessment->gradinggrade) ? get_string('nullgrade', 'workshop') : $assessment->gradinggrade;
1021          $a->weight = $assessment->weight;
1022          // grrr the following logic should really be handled by a future language pack feature
1023          if (is_null($assessment->gradinggradeover)) {
1024              if ($a->weight == 1) {
1025                  $grade = get_string('formatpeergrade', 'workshop', $a);
1026              } else {
1027                  $grade = get_string('formatpeergradeweighted', 'workshop', $a);
1028              }
1029          } else {
1030              $a->gradinggradeover = $assessment->gradinggradeover;
1031              if ($a->weight == 1) {
1032                  $grade = get_string('formatpeergradeover', 'workshop', $a);
1033              } else {
1034                  $grade = get_string('formatpeergradeoverweighted', 'workshop', $a);
1035              }
1036          }
1037          $url = new moodle_url('/mod/workshop/assessment.php',
1038                                array('asid' => $assessment->assessmentid));
1039          $grade = html_writer::link($url, $grade, array('class'=>'grade'));
1040  
1041          if ($shownames) {
1042              $userid = $assessment->userid;
1043              $name   = $this->output->user_picture($userinfo[$userid], array('courseid' => $this->page->course->id, 'size' => 16));
1044              $name  .= html_writer::tag('span', fullname($userinfo[$userid]), array('class' => 'fullname'));
1045              $name   = $separator . html_writer::tag('span', $name, array('class' => 'user'));
1046          } else {
1047              $name   = '';
1048          }
1049  
1050          return $this->output->container($grade . $name, 'assessmentdetails');
1051      }
1052  
1053      /**
1054       * Formats the aggreagated grades
1055       */
1056      protected function helper_grading_report_grade($grade, $over=null) {
1057          $a = new stdclass();
1058          $a->grade = is_null($grade) ? get_string('nullgrade', 'workshop') : $grade;
1059          if (is_null($over)) {
1060              $text = get_string('formataggregatedgrade', 'workshop', $a);
1061          } else {
1062              $a->over = is_null($over) ? get_string('nullgrade', 'workshop') : $over;
1063              $text = get_string('formataggregatedgradeover', 'workshop', $a);
1064          }
1065          return $text;
1066      }
1067  
1068      ////////////////////////////////////////////////////////////////////////////
1069      // Static helpers
1070      ////////////////////////////////////////////////////////////////////////////
1071  
1072      /**
1073       * Helper method dealing with the fact we can not just fetch the output of moodleforms
1074       *
1075       * @param moodleform $mform
1076       * @return string HTML
1077       */
1078      protected static function moodleform(moodleform $mform) {
1079  
1080          ob_start();
1081          $mform->display();
1082          $o = ob_get_contents();
1083          ob_end_clean();
1084  
1085          return $o;
1086      }
1087  
1088      /**
1089       * Helper function returning the n-th item of the array
1090       *
1091       * @param array $a
1092       * @param int   $n from 0 to m, where m is th number of items in the array
1093       * @return mixed the $n-th element of $a
1094       */
1095      protected static function array_nth(array $a, $n) {
1096          $keys = array_keys($a);
1097          if ($n < 0 or $n > count($keys) - 1) {
1098              return null;
1099          }
1100          $key = $keys[$n];
1101          return $a[$key];
1102      }
1103  
1104      /**
1105       * Tries to guess the fullname format set at the site
1106       *
1107       * @return string fl|lf
1108       */
1109      protected static function fullname_format() {
1110          $fake = new stdclass(); // fake user
1111          $fake->lastname = 'LLLL';
1112          $fake->firstname = 'FFFF';
1113          $fullname = get_string('fullnamedisplay', '', $fake);
1114          if (strpos($fullname, 'LLLL') < strpos($fullname, 'FFFF')) {
1115              return 'lf';
1116          } else {
1117              return 'fl';
1118          }
1119      }
1120  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1