Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   * Renderer class for the manual allocation UI is defined here
  20   *
  21   * @package    workshopallocation
  22   * @subpackage manual
  23   * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Manual allocation renderer class
  31   */
  32  class workshopallocation_manual_renderer extends mod_workshop_renderer  {
  33  
  34      /** @var workshop module instance */
  35      protected $workshop;
  36  
  37      ////////////////////////////////////////////////////////////////////////////
  38      // External rendering API
  39      ////////////////////////////////////////////////////////////////////////////
  40  
  41      /**
  42       * Display the table of all current allocations and widgets to modify them
  43       *
  44       * @param workshopallocation_manual_allocations $data to be displayed
  45       * @return string html code
  46       */
  47      protected function render_workshopallocation_manual_allocations(workshopallocation_manual_allocations $data) {
  48  
  49          $this->workshop     = $data->workshop;
  50  
  51          $allocations        = $data->allocations;       // array prepared array of all allocations data
  52          $userinfo           = $data->userinfo;          // names and pictures of all required users
  53          $authors            = $data->authors;           // array potential reviewees
  54          $reviewers          = $data->reviewers;         // array potential submission reviewers
  55          $hlauthorid         = $data->hlauthorid;        // int id of the author to highlight
  56          $hlreviewerid       = $data->hlreviewerid;      // int id of the reviewer to highlight
  57          $selfassessment     = $data->selfassessment;    // bool is the self-assessment allowed in this workshop?
  58  
  59          if (empty($allocations)) {
  60              return '';
  61          }
  62  
  63          // convert user collections into drop down menus
  64          $authors    = array_map('fullname', $authors);
  65          $reviewers  =  array_map('fullname', $reviewers);
  66  
  67          $table              = new html_table();
  68          $table->attributes['class'] = 'allocations';
  69          $table->head        = array(get_string('participantreviewedby', 'workshop'),
  70                                      get_string('participant', 'workshop'),
  71                                      get_string('participantrevierof', 'workshop'));
  72          $table->rowclasses  = array();
  73          $table->colclasses  = array('reviewedby', 'peer', 'reviewerof');
  74          $table->data        = array();
  75          foreach ($allocations as $allocation) {
  76              $row = array();
  77              $row[] = $this->helper_reviewers_of_participant($allocation, $userinfo, $reviewers, $selfassessment);
  78              $row[] = $this->helper_participant($allocation, $userinfo);
  79              $row[] = $this->helper_reviewees_of_participant($allocation, $userinfo, $authors, $selfassessment);
  80              $thisrowclasses = array();
  81              if ($allocation->userid == $hlauthorid) {
  82                  $thisrowclasses[] = 'highlightreviewedby';
  83              }
  84              if ($allocation->userid == $hlreviewerid) {
  85                  $thisrowclasses[] = 'highlightreviewerof';
  86              }
  87              $table->rowclasses[] = implode(' ', $thisrowclasses);
  88              $table->data[] = $row;
  89          }
  90  
  91          return $this->output->container(html_writer::table($table), 'manual-allocator');
  92      }
  93  
  94      ////////////////////////////////////////////////////////////////////////////
  95      // Internal helper methods
  96      ////////////////////////////////////////////////////////////////////////////
  97  
  98      /**
  99       * Returns information about the workshop participant
 100       *
 101       * @return string HTML code
 102       */
 103      protected function helper_participant(stdclass $allocation, array $userinfo) {
 104          $o  = $this->output->user_picture($userinfo[$allocation->userid], array('courseid' => $this->page->course->id));
 105          $o .= fullname($userinfo[$allocation->userid]);
 106          $o .= $this->output->container_start(array('submission'));
 107          if (is_null($allocation->submissionid)) {
 108              $o .= $this->output->container(get_string('nosubmissionfound', 'workshop'), 'info');
 109          } else {
 110              $link = $this->workshop->submission_url($allocation->submissionid);
 111              $o .= $this->output->container(html_writer::link($link, format_string($allocation->submissiontitle)), 'title');
 112              if (is_null($allocation->submissiongrade)) {
 113                  $o .= $this->output->container(get_string('nogradeyet', 'workshop'), array('grade', 'missing'));
 114              } else {
 115                  $o .= $this->output->container(get_string('alreadygraded', 'workshop'), array('grade', 'missing'));
 116              }
 117          }
 118          $o .= $this->output->container_end();
 119          return $o;
 120      }
 121  
 122      /**
 123       * Returns information about the current reviewers of the given participant and a selector do add new one
 124       *
 125       * @return string html code
 126       */
 127      protected function helper_reviewers_of_participant(stdclass $allocation, array $userinfo, array $reviewers, $selfassessment) {
 128          $o = '';
 129          if (is_null($allocation->submissionid)) {
 130              $o .= $this->output->container(get_string('nothingtoreview', 'workshop'), 'info');
 131          } else {
 132              $exclude = array();
 133              if (! $selfassessment) {
 134                  $exclude[$allocation->userid] = true;
 135              }
 136              // todo add an option to exclude users without own submission
 137              $options = array_diff_key($reviewers, $exclude);
 138              if ($options) {
 139                  $handler = new moodle_url($this->page->url, array('mode' => 'new', 'of' => $allocation->userid, 'sesskey' => sesskey()));
 140                  $select = new single_select($handler, 'by', $options, '', array(''=>get_string('chooseuser', 'workshop')), 'addreviewof' . $allocation->userid);
 141                  $select->set_label(get_string('addreviewer', 'workshopallocation_manual'));
 142                  $o .= $this->output->render($select);
 143              }
 144          }
 145          $o .= html_writer::start_tag('ul', array());
 146          foreach ($allocation->reviewedby as $reviewerid => $assessmentid) {
 147              $o .= html_writer::start_tag('li', array());
 148              $o .= $this->output->user_picture($userinfo[$reviewerid], array('courseid' => $this->page->course->id, 'size' => 16));
 149              $o .= fullname($userinfo[$reviewerid]);
 150  
 151              // delete icon
 152              $handler = new moodle_url($this->page->url, array('mode' => 'del', 'what' => $assessmentid, 'sesskey' => sesskey()));
 153              $o .= $this->helper_remove_allocation_icon($handler);
 154  
 155              $o .= html_writer::end_tag('li');
 156          }
 157          $o .= html_writer::end_tag('ul');
 158          return $o;
 159      }
 160  
 161      /**
 162       * Returns information about the current reviewees of the given participant and a selector do add new one
 163       *
 164       * @return string html code
 165       */
 166      protected function helper_reviewees_of_participant(stdclass $allocation, array $userinfo, array $authors, $selfassessment) {
 167          $o = '';
 168          if (is_null($allocation->submissionid)) {
 169              $o .= $this->output->container(get_string('withoutsubmission', 'workshop'), 'info');
 170          }
 171          $exclude = array();
 172          if (! $selfassessment) {
 173              $exclude[$allocation->userid] = true;
 174              $o .= $this->output->container(get_string('selfassessmentdisabled', 'workshop'), 'info');
 175          }
 176          // todo add an option to exclude users without own submission
 177          $options = array_diff_key($authors, $exclude);
 178          if ($options) {
 179              $handler = new moodle_url($this->page->url, array('mode' => 'new', 'by' => $allocation->userid, 'sesskey' => sesskey()));
 180              $select = new single_select($handler, 'of', $options, '', array(''=>get_string('chooseuser', 'workshop')), 'addreviewby' . $allocation->userid);
 181              $select->set_label(get_string('addreviewee', 'workshopallocation_manual'));
 182              $o .= $this->output->render($select);
 183          } else {
 184              $o .= $this->output->container(get_string('nothingtoreview', 'workshop'), 'info');
 185          }
 186          $o .= html_writer::start_tag('ul', array());
 187          foreach ($allocation->reviewerof as $authorid => $assessmentid) {
 188              $o .= html_writer::start_tag('li', array());
 189              $o .= $this->output->user_picture($userinfo[$authorid], array('courseid' => $this->page->course->id, 'size' => 16));
 190              $o .= fullname($userinfo[$authorid]);
 191  
 192              // delete icon
 193              $handler = new moodle_url($this->page->url, array('mode' => 'del', 'what' => $assessmentid, 'sesskey' => sesskey()));
 194              $o .= $this->helper_remove_allocation_icon($handler);
 195  
 196              $o .= html_writer::end_tag('li');
 197          }
 198          $o .= html_writer::end_tag('ul');
 199          return $o;
 200      }
 201  
 202      /**
 203       * Generates an icon link to remove the allocation
 204       *
 205       * @param moodle_url $link to the action
 206       * @return html code to be displayed
 207       */
 208      protected function helper_remove_allocation_icon($link) {
 209          return $this->output->action_icon($link, new pix_icon('t/delete', 'X'));
 210      }
 211  }