[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/grade/grading/form/guide/ -> renderer.php (source)

   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   * Contains the Guide grading form renderer in all of its glory
  19   *
  20   * @package    gradingform_guide
  21   * @copyright  2012 Dan Marsden <[email protected]>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  /**
  28   * Grading method plugin renderer
  29   *
  30   * @package    gradingform_guide
  31   * @copyright  2012 Dan Marsden <[email protected]>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class gradingform_guide_renderer extends plugin_renderer_base {
  35  
  36      /**
  37       * This function returns html code for displaying criterion. Depending on $mode it may be the
  38       * code to edit guide, to preview the guide, to evaluate somebody or to review the evaluation.
  39       *
  40       * This function may be called from display_guide() to display the whole guide, or it can be
  41       * called by itself to return a template used by JavaScript to add new empty criteria to the
  42       * guide being designed.
  43       * In this case it will use macros like {NAME}, {LEVELS}, {CRITERION-id}, etc.
  44       *
  45       * When overriding this function it is very important to remember that all elements of html
  46       * form (in edit or evaluate mode) must have the name $elementname.
  47       *
  48       * Also JavaScript relies on the class names of elements and when developer changes them
  49       * script might stop working.
  50       *
  51       * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller()}
  52       * @param array $options An array of options.
  53       *      showmarkspercriterionstudents (bool) If true adds the current score to the display
  54       * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
  55       * @param array $criterion criterion data
  56       * @param array $value (only in view mode) teacher's feedback on this criterion
  57       * @param array $validationerrors An array containing validation errors to be shown
  58       * @return string
  59       */
  60      public function criterion_template($mode, $options, $elementname = '{NAME}', $criterion = null, $value = null,
  61                                         $validationerrors = null) {
  62          if ($criterion === null || !is_array($criterion) || !array_key_exists('id', $criterion)) {
  63              $criterion = array('id' => '{CRITERION-id}',
  64                                 'description' => '{CRITERION-description}',
  65                                 'sortorder' => '{CRITERION-sortorder}',
  66                                 'class' => '{CRITERION-class}',
  67                                 'descriptionmarkers' => '{CRITERION-descriptionmarkers}',
  68                                 'shortname' => '{CRITERION-shortname}',
  69                                 'maxscore' => '{CRITERION-maxscore}');
  70          } else {
  71              foreach (array('sortorder', 'description', 'class', 'shortname', 'descriptionmarkers', 'maxscore') as $key) {
  72                  // Set missing array elements to empty strings to avoid warnings.
  73                  if (!array_key_exists($key, $criterion)) {
  74                      $criterion[$key] = '';
  75                  }
  76              }
  77          }
  78  
  79          $criteriontemplate = html_writer::start_tag('tr', array('class' => 'criterion'. $criterion['class'],
  80              'id' => '{NAME}-criteria-{CRITERION-id}'));
  81          $descriptionclass = 'description';
  82          if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FULL) {
  83              $criteriontemplate .= html_writer::start_tag('td', array('class' => 'controls'));
  84              foreach (array('moveup', 'delete', 'movedown') as $key) {
  85                  $value = get_string('criterion'.$key, 'gradingform_guide');
  86                  $button = html_writer::empty_tag('input', array('type' => 'submit',
  87                      'name' => '{NAME}[criteria][{CRITERION-id}]['.$key.']',
  88                      'id' => '{NAME}-criteria-{CRITERION-id}-'.$key, 'value' => $value, 'title' => $value, 'tabindex' => -1));
  89                  $criteriontemplate .= html_writer::tag('div', $button, array('class' => $key));
  90              }
  91              $criteriontemplate .= html_writer::end_tag('td'); // Controls.
  92              $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
  93                  'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder']));
  94  
  95              $shortname = html_writer::empty_tag('input', array('type'=> 'text',
  96                  'name' => '{NAME}[criteria][{CRITERION-id}][shortname]',  'value' => $criterion['shortname'],
  97                  'id ' => '{NAME}[criteria][{CRITERION-id}][shortname]'));
  98              $shortname = html_writer::tag('div', $shortname, array('class'=>'criterionname'));
  99              $description = html_writer::tag('textarea', s($criterion['description']),
 100                  array('name' => '{NAME}[criteria][{CRITERION-id}][description]', 'cols' => '65', 'rows' => '5'));
 101              $description = html_writer::tag('div', $description, array('class'=>'criteriondesc'));
 102  
 103              $descriptionmarkers = html_writer::tag('textarea', s($criterion['descriptionmarkers']),
 104                  array('name' => '{NAME}[criteria][{CRITERION-id}][descriptionmarkers]', 'cols' => '65', 'rows' => '5'));
 105              $descriptionmarkers = html_writer::tag('div', $descriptionmarkers, array('class'=>'criteriondescmarkers'));
 106  
 107              $maxscore = html_writer::empty_tag('input', array('type'=> 'text',
 108                  'name' => '{NAME}[criteria][{CRITERION-id}][maxscore]', 'size' => '3',
 109                  'value' => $criterion['maxscore'],
 110                  'id' => '{NAME}[criteria][{CRITERION-id}][maxscore]'));
 111              $maxscore = html_writer::tag('div', $maxscore, array('class'=>'criterionmaxscore'));
 112          } else {
 113              if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FROZEN) {
 114                  $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
 115                      'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder']));
 116                  $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
 117                      'name' => '{NAME}[criteria][{CRITERION-id}][shortname]', 'value' => $criterion['shortname']));
 118                  $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
 119                      'name' => '{NAME}[criteria][{CRITERION-id}][description]', 'value' => $criterion['description']));
 120                  $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
 121                      'name' => '{NAME}[criteria][{CRITERION-id}][descriptionmarkers]', 'value' => $criterion['descriptionmarkers']));
 122                  $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
 123                      'name' => '{NAME}[criteria][{CRITERION-id}][maxscore]', 'value' => $criterion['maxscore']));
 124              } else if ($mode == gradingform_guide_controller::DISPLAY_EVAL ||
 125                         $mode == gradingform_guide_controller::DISPLAY_VIEW) {
 126                  $descriptionclass = 'descriptionreadonly';
 127              }
 128              $shortname   = html_writer::tag('div', s($criterion['shortname']),
 129                  array('class'=>'criterionshortname', 'name' => '{NAME}[criteria][{CRITERION-id}][shortname]'));
 130              $descmarkerclass = '';
 131              $descstudentclass = '';
 132              if ($mode == gradingform_guide_controller::DISPLAY_EVAL) {
 133                  if (!get_user_preferences('gradingform_guide-showmarkerdesc', true)) {
 134                      $descmarkerclass = ' hide';
 135                  }
 136                  if (!get_user_preferences('gradingform_guide-showstudentdesc', true)) {
 137                      $descstudentclass = ' hide';
 138                  }
 139              }
 140              $description = html_writer::tag('div', s($criterion['description']),
 141                  array('class'=>'criteriondescription'.$descstudentclass,
 142                        'name' => '{NAME}[criteria][{CRITERION-id}][descriptionmarkers]'));
 143              $descriptionmarkers   = html_writer::tag('div', s($criterion['descriptionmarkers']),
 144                  array('class'=>'criteriondescriptionmarkers'.$descmarkerclass,
 145                        'name' => '{NAME}[criteria][{CRITERION-id}][descriptionmarkers]'));
 146              $maxscore   = html_writer::tag('div', s($criterion['maxscore']),
 147                  array('class'=>'criteriondescriptionscore', 'name' => '{NAME}[criteria][{CRITERION-id}][maxscore]'));
 148          }
 149  
 150          if (isset($criterion['error_description'])) {
 151              $descriptionclass .= ' error';
 152          }
 153  
 154          $title = html_writer::tag('label', get_string('criterion', 'gradingform_guide'),
 155              array('for'=>'{NAME}[criteria][{CRITERION-id}][shortname]', 'class' => 'criterionnamelabel'));
 156          $title .= $shortname;
 157          if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FULL ||
 158              $mode == gradingform_guide_controller::DISPLAY_PREVIEW) {
 159              $title .= html_writer::tag('label', get_string('descriptionstudents', 'gradingform_guide'),
 160                  array('for'=>'{NAME}[criteria][{CRITERION-id}][description]'));
 161              $title .= $description;
 162              $title .= html_writer::tag('label', get_string('descriptionmarkers', 'gradingform_guide'),
 163                  array('for'=>'{NAME}[criteria][{CRITERION-id}][descriptionmarkers]'));
 164              $title .= $descriptionmarkers;
 165              $title .=  html_writer::tag('label', get_string('maxscore', 'gradingform_guide'),
 166                  array('for'=>'{NAME}[criteria][{CRITERION-id}][maxscore]'));
 167              $title .= $maxscore;
 168          } else if ($mode == gradingform_guide_controller::DISPLAY_PREVIEW_GRADED ||
 169                     $mode == gradingform_guide_controller::DISPLAY_VIEW) {
 170              $title .= $description;
 171              if (!empty($options['showmarkspercriterionstudents'])) {
 172                  $title .=  html_writer::tag('label', get_string('maxscore', 'gradingform_guide'),
 173                      array('for' => '{NAME}[criteria][{CRITERION-id}][maxscore]'));
 174                  $title .= $maxscore;
 175              }
 176          } else {
 177              $title .= $description . $descriptionmarkers;
 178          }
 179          $criteriontemplate .= html_writer::tag('td', $title, array('class' => $descriptionclass,
 180              'id' => '{NAME}-criteria-{CRITERION-id}-shortname'));
 181  
 182          $currentremark = '';
 183          $currentscore = '';
 184          if (isset($value['remark'])) {
 185              $currentremark = $value['remark'];
 186          }
 187          if (isset($value['score'])) {
 188              $currentscore = $value['score'];
 189          }
 190          if ($mode == gradingform_guide_controller::DISPLAY_EVAL) {
 191              $scoreclass = '';
 192              if (!empty($validationerrors[$criterion['id']]['score'])) {
 193                  $scoreclass = 'error';
 194                  $currentscore = $validationerrors[$criterion['id']]['score']; // Show invalid score in form.
 195              }
 196              $input = html_writer::tag('textarea', s($currentremark),
 197                  array('name' => '{NAME}[criteria][{CRITERION-id}][remark]', 'cols' => '65', 'rows' => '5',
 198                        'class' => 'markingguideremark'));
 199              $criteriontemplate .= html_writer::tag('td', $input, array('class' => 'remark'));
 200              $score = html_writer::tag('label', get_string('score', 'gradingform_guide'),
 201                  array('for'=>'{NAME}[criteria][{CRITERION-id}][score]', 'class' => $scoreclass));
 202              $score .= html_writer::empty_tag('input', array('type'=> 'text',
 203                  'name' => '{NAME}[criteria][{CRITERION-id}][score]', 'class' => $scoreclass,
 204                  'id' => '{NAME}[criteria][{CRITERION-id}][score]',
 205                  'size' => '3', 'value' => $currentscore));
 206              $score .= '/'.$maxscore;
 207  
 208              $criteriontemplate .= html_writer::tag('td', $score, array('class' => 'score'));
 209          } else if ($mode == gradingform_guide_controller::DISPLAY_EVAL_FROZEN) {
 210              $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
 211                  'name' => '{NAME}[criteria][{CRITERION-id}][remark]', 'value' => $currentremark));
 212          } else if ($mode == gradingform_guide_controller::DISPLAY_REVIEW ||
 213              $mode == gradingform_guide_controller::DISPLAY_VIEW) {
 214              $criteriontemplate .= html_writer::tag('td', s($currentremark), array('class' => 'remark'));
 215              if (!empty($options['showmarkspercriterionstudents'])) {
 216                  $criteriontemplate .= html_writer::tag('td', s($currentscore). ' / '.$maxscore,
 217                      array('class' => 'score'));
 218              }
 219          }
 220          $criteriontemplate .= html_writer::end_tag('tr'); // Criterion.
 221  
 222          $criteriontemplate = str_replace('{NAME}', $elementname, $criteriontemplate);
 223          $criteriontemplate = str_replace('{CRITERION-id}', $criterion['id'], $criteriontemplate);
 224          return $criteriontemplate;
 225      }
 226  
 227      /**
 228       * This function returns html code for displaying criterion. Depending on $mode it may be the
 229       * code to edit guide, to preview the guide, to evaluate somebody or to review the evaluation.
 230       *
 231       * This function may be called from display_guide() to display the whole guide, or it can be
 232       * called by itself to return a template used by JavaScript to add new empty criteria to the
 233       * guide being designed.
 234       * In this case it will use macros like {NAME}, {LEVELS}, {CRITERION-id}, etc.
 235       *
 236       * When overriding this function it is very important to remember that all elements of html
 237       * form (in edit or evaluate mode) must have the name $elementname.
 238       *
 239       * Also JavaScript relies on the class names of elements and when developer changes them
 240       * script might stop working.
 241       *
 242       * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller}
 243       * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
 244       * @param array $comment
 245       * @return string
 246       */
 247      public function comment_template($mode, $elementname = '{NAME}', $comment = null) {
 248          if ($comment === null || !is_array($comment) || !array_key_exists('id', $comment)) {
 249              $comment = array('id' => '{COMMENT-id}',
 250                  'description' => '{COMMENT-description}',
 251                  'sortorder' => '{COMMENT-sortorder}',
 252                  'class' => '{COMMENT-class}');
 253          } else {
 254              foreach (array('sortorder', 'description', 'class') as $key) {
 255                  // Set missing array elements to empty strings to avoid warnings.
 256                  if (!array_key_exists($key, $comment)) {
 257                      $criterion[$key] = '';
 258                  }
 259              }
 260          }
 261          $criteriontemplate = html_writer::start_tag('tr', array('class' => 'criterion'. $comment['class'],
 262              'id' => '{NAME}-comments-{COMMENT-id}'));
 263          if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FULL) {
 264              $criteriontemplate .= html_writer::start_tag('td', array('class' => 'controls'));
 265              foreach (array('moveup', 'delete', 'movedown') as $key) {
 266                  $value = get_string('comments'.$key, 'gradingform_guide');
 267                  $button = html_writer::empty_tag('input', array('type' => 'submit',
 268                      'name' => '{NAME}[comments][{COMMENT-id}]['.$key.']', 'id' => '{NAME}-comments-{COMMENT-id}-'.$key,
 269                      'value' => $value, 'title' => $value, 'tabindex' => -1));
 270                  $criteriontemplate .= html_writer::tag('div', $button, array('class' => $key));
 271              }
 272              $criteriontemplate .= html_writer::end_tag('td'); // Controls.
 273              $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
 274                  'name' => '{NAME}[comments][{COMMENT-id}][sortorder]', 'value' => $comment['sortorder']));
 275              $description = html_writer::tag('textarea', s($comment['description']),
 276                  array('name' => '{NAME}[comments][{COMMENT-id}][description]', 'cols' => '65', 'rows' => '5'));
 277              $description = html_writer::tag('div', $description, array('class'=>'criteriondesc'));
 278          } else {
 279              if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FROZEN) {
 280                  $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
 281                      'name' => '{NAME}[comments][{COMMENT-id}][sortorder]', 'value' => $comment['sortorder']));
 282                  $criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden',
 283                      'name' => '{NAME}[comments][{COMMENT-id}][description]', 'value' => $comment['description']));
 284              }
 285              if ($mode == gradingform_guide_controller::DISPLAY_EVAL) {
 286                  $description = html_writer::tag('span', s($comment['description']),
 287                      array('name' => '{NAME}[comments][{COMMENT-id}][description]',
 288                            'title' => get_string('clicktocopy', 'gradingform_guide'),
 289                            'id' => '{NAME}[comments][{COMMENT-id}]', 'class'=>'markingguidecomment'));
 290              } else {
 291                  $description = s($comment['description']);
 292              }
 293          }
 294          $descriptionclass = 'description';
 295          if (isset($comment['error_description'])) {
 296              $descriptionclass .= ' error';
 297          }
 298          $criteriontemplate .= html_writer::tag('td', $description, array('class' => $descriptionclass,
 299              'id' => '{NAME}-comments-{COMMENT-id}-description'));
 300          $criteriontemplate .= html_writer::end_tag('tr'); // Criterion.
 301  
 302          $criteriontemplate = str_replace('{NAME}', $elementname, $criteriontemplate);
 303          $criteriontemplate = str_replace('{COMMENT-id}', $comment['id'], $criteriontemplate);
 304          return $criteriontemplate;
 305      }
 306      /**
 307       * This function returns html code for displaying guide template (content before and after
 308       * criteria list). Depending on $mode it may be the code to edit guide, to preview the guide,
 309       * to evaluate somebody or to review the evaluation.
 310       *
 311       * This function is called from display_guide() to display the whole guide.
 312       *
 313       * When overriding this function it is very important to remember that all elements of html
 314       * form (in edit or evaluate mode) must have the name $elementname.
 315       *
 316       * Also JavaScript relies on the class names of elements and when developer changes them
 317       * script might stop working.
 318       *
 319       * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller}
 320       * @param array $options An array of options provided to {@link gradingform_guide_renderer::guide_edit_options()}
 321       * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
 322       * @param string $criteriastr evaluated templates for this guide's criteria
 323       * @param string $commentstr
 324       * @return string
 325       */
 326      protected function guide_template($mode, $options, $elementname, $criteriastr, $commentstr) {
 327          $classsuffix = ''; // CSS suffix for class of the main div. Depends on the mode.
 328          switch ($mode) {
 329              case gradingform_guide_controller::DISPLAY_EDIT_FULL:
 330                  $classsuffix = ' editor editable';
 331                  break;
 332              case gradingform_guide_controller::DISPLAY_EDIT_FROZEN:
 333                  $classsuffix = ' editor frozen';
 334                  break;
 335              case gradingform_guide_controller::DISPLAY_PREVIEW:
 336              case gradingform_guide_controller::DISPLAY_PREVIEW_GRADED:
 337                  $classsuffix = ' editor preview';
 338                  break;
 339              case gradingform_guide_controller::DISPLAY_EVAL:
 340                  $classsuffix = ' evaluate editable';
 341                  break;
 342              case gradingform_guide_controller::DISPLAY_EVAL_FROZEN:
 343                  $classsuffix = ' evaluate frozen';
 344                  break;
 345              case gradingform_guide_controller::DISPLAY_REVIEW:
 346                  $classsuffix = ' review';
 347                  break;
 348              case gradingform_guide_controller::DISPLAY_VIEW:
 349                  $classsuffix = ' view';
 350                  break;
 351          }
 352  
 353          $guidetemplate = html_writer::start_tag('div', array('id' => 'guide-{NAME}',
 354              'class' => 'clearfix gradingform_guide'.$classsuffix));
 355          $guidetemplate .= html_writer::tag('table', $criteriastr, array('class' => 'criteria', 'id' => '{NAME}-criteria'));
 356          if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FULL) {
 357              $value = get_string('addcriterion', 'gradingform_guide');
 358              $input = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][addcriterion]',
 359                  'id' => '{NAME}-criteria-addcriterion', 'value' => $value, 'title' => $value));
 360              $guidetemplate .= html_writer::tag('div', $input, array('class' => 'addcriterion'));
 361          }
 362  
 363          if (!empty($commentstr)) {
 364              $guidetemplate .= html_writer::tag('label', get_string('comments', 'gradingform_guide'),
 365                  array('for' => '{NAME}-comments', 'class' => 'commentheader'));
 366              $guidetemplate .= html_writer::tag('table', $commentstr, array('class' => 'comments', 'id' => '{NAME}-comments'));
 367          }
 368          if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FULL) {
 369              $value = get_string('addcomment', 'gradingform_guide');
 370              $input = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[comments][addcomment]',
 371                  'id' => '{NAME}-comments-addcomment', 'value' => $value, 'title' => $value));
 372              $guidetemplate .= html_writer::tag('div', $input, array('class' => 'addcomment'));
 373          }
 374  
 375          $guidetemplate .= $this->guide_edit_options($mode, $options);
 376          $guidetemplate .= html_writer::end_tag('div');
 377  
 378          return str_replace('{NAME}', $elementname, $guidetemplate);
 379      }
 380  
 381      /**
 382       * Generates html template to view/edit the guide options. Expression {NAME} is used in
 383       * template for the form element name
 384       *
 385       * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller}
 386       * @param array $options
 387       * @return string
 388       */
 389      protected function guide_edit_options($mode, $options) {
 390          if ($mode != gradingform_guide_controller::DISPLAY_EDIT_FULL
 391              && $mode != gradingform_guide_controller::DISPLAY_EDIT_FROZEN
 392              && $mode != gradingform_guide_controller::DISPLAY_PREVIEW) {
 393              // Options are displayed only for people who can manage.
 394              return;
 395          }
 396          $html = html_writer::start_tag('div', array('class' => 'options'));
 397          $html .= html_writer::tag('div', get_string('guideoptions', 'gradingform_guide'), array('class' => 'optionsheading'));
 398          $attrs = array('type' => 'hidden', 'name' => '{NAME}[options][optionsset]', 'value' => 1);
 399          $html .= html_writer::empty_tag('input', $attrs);
 400          foreach ($options as $option => $value) {
 401              $html .= html_writer::start_tag('div', array('class' => 'option '.$option));
 402              $attrs = array('name' => '{NAME}[options]['.$option.']', 'id' => '{NAME}-options-'.$option);
 403              switch ($option) {
 404                  case 'sortlevelsasc':
 405                      // Display option as dropdown.
 406                      $html .= html_writer::tag('span', get_string($option, 'gradingform_guide'), array('class' => 'label'));
 407                      $value = (int)(!!$value); // Make sure $value is either 0 or 1.
 408                      if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FULL) {
 409                          $selectoptions = array(0 => get_string($option.'0', 'gradingform_guide'),
 410                              1 => get_string($option.'1', 'gradingform_guide'));
 411                          $valuestr = html_writer::select($selectoptions, $attrs['name'], $value, false, array('id' => $attrs['id']));
 412                          $html .= html_writer::tag('span', $valuestr, array('class' => 'value'));
 413                          // TODO add here button 'Sort levels'.
 414                      } else {
 415                          $html .= html_writer::tag('span', get_string($option.$value, 'gradingform_guide'),
 416                              array('class' => 'value'));
 417                          if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FROZEN) {
 418                              $html .= html_writer::empty_tag('input', $attrs + array('type' => 'hidden', 'value' => $value));
 419                          }
 420                      }
 421                      break;
 422                  default:
 423                      if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FROZEN && $value) {
 424                          $html .= html_writer::empty_tag('input', $attrs + array('type' => 'hidden', 'value' => $value));
 425                      }
 426                      // Display option as checkbox.
 427                      $attrs['type'] = 'checkbox';
 428                      $attrs['value'] = 1;
 429                      if ($value) {
 430                          $attrs['checked'] = 'checked';
 431                      }
 432                      if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FROZEN ||
 433                          $mode == gradingform_guide_controller::DISPLAY_PREVIEW) {
 434                          $attrs['disabled'] = 'disabled';
 435                          unset($attrs['name']);
 436                      }
 437                      $html .= html_writer::empty_tag('input', $attrs);
 438                      $html .= html_writer::tag('label', get_string($option, 'gradingform_guide'), array('for' => $attrs['id']));
 439                      break;
 440              }
 441              $html .= html_writer::end_tag('div'); // Option.
 442          }
 443          $html .= html_writer::end_tag('div'); // Options.
 444          return $html;
 445      }
 446  
 447      /**
 448       * This function returns html code for displaying guide. Depending on $mode it may be the code
 449       * to edit guide, to preview the guide, to evaluate somebody or to review the evaluation.
 450       *
 451       * It is very unlikely that this function needs to be overriden by theme. It does not produce
 452       * any html code, it just prepares data about guide design and evaluation, adds the CSS
 453       * class to elements and calls the functions level_template, criterion_template and
 454       * guide_template
 455       *
 456       * @param array $criteria data about the guide design
 457       * @param array $comments
 458       * @param array $options
 459       * @param int $mode guide display mode, one of gradingform_guide_controller::DISPLAY_* {@link gradingform_guide_controller}
 460       * @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
 461       * @param array $values evaluation result
 462       * @param array $validationerrors
 463       * @return string
 464       */
 465      public function display_guide($criteria, $comments, $options, $mode, $elementname = null, $values = null,
 466                                    $validationerrors = null) {
 467          $criteriastr = '';
 468          $cnt = 0;
 469          foreach ($criteria as $id => $criterion) {
 470              $criterion['class'] = $this->get_css_class_suffix($cnt++, count($criteria) -1);
 471              $criterion['id'] = $id;
 472              if (isset($values['criteria'][$id])) {
 473                  $criterionvalue = $values['criteria'][$id];
 474              } else {
 475                  $criterionvalue = null;
 476              }
 477              $criteriastr .= $this->criterion_template($mode, $options, $elementname, $criterion, $criterionvalue,
 478                                                        $validationerrors);
 479          }
 480          $cnt = 0;
 481          $commentstr = '';
 482          // Check if comments should be displayed.
 483          if ($mode == gradingform_guide_controller::DISPLAY_EDIT_FULL ||
 484              $mode == gradingform_guide_controller::DISPLAY_EDIT_FROZEN ||
 485              $mode == gradingform_guide_controller::DISPLAY_PREVIEW ||
 486              $mode == gradingform_guide_controller::DISPLAY_EVAL ||
 487              $mode == gradingform_guide_controller::DISPLAY_EVAL_FROZEN) {
 488  
 489              foreach ($comments as $id => $comment) {
 490                  $comment['id'] = $id;
 491                  $comment['class'] = $this->get_css_class_suffix($cnt++, count($comments) -1);
 492                  $commentstr  .= $this->comment_template($mode, $elementname, $comment);
 493              }
 494          }
 495          $output = $this->guide_template($mode, $options, $elementname, $criteriastr, $commentstr);
 496          if ($mode == gradingform_guide_controller::DISPLAY_EVAL) {
 497              $showdesc = get_user_preferences('gradingform_guide-showmarkerdesc', true);
 498              $showdescstud = get_user_preferences('gradingform_guide-showstudentdesc', true);
 499              $checked1 = array();
 500              $checked2 = array();
 501              $checked_s1 = array();
 502              $checked_s2 = array();
 503              $checked = array('checked' => 'checked');
 504              if ($showdesc) {
 505                  $checked1 = $checked;
 506              } else {
 507                  $checked2 = $checked;
 508              }
 509              if ($showdescstud) {
 510                  $checked_s1 = $checked;
 511              } else {
 512                  $checked_s2 = $checked;
 513              }
 514  
 515              $radio = html_writer::tag('input', get_string('showmarkerdesc', 'gradingform_guide'), array('type' => 'radio',
 516                  'name' => 'showmarkerdesc',
 517                  'value' => "true")+$checked1);
 518              $radio .= html_writer::tag('input', get_string('hidemarkerdesc', 'gradingform_guide'), array('type' => 'radio',
 519                  'name' => 'showmarkerdesc',
 520                  'value' => "false")+$checked2);
 521              $output .= html_writer::tag('div', $radio, array('class' => 'showmarkerdesc'));
 522  
 523              $radio = html_writer::tag('input', get_string('showstudentdesc', 'gradingform_guide'), array('type' => 'radio',
 524                  'name' => 'showstudentdesc',
 525                  'value' => "true")+$checked_s1);
 526              $radio .= html_writer::tag('input', get_string('hidestudentdesc', 'gradingform_guide'), array('type' => 'radio',
 527                  'name' => 'showstudentdesc',
 528                  'value' => "false")+$checked_s2);
 529              $output .= html_writer::tag('div', $radio, array('class' => 'showstudentdesc'));
 530          }
 531          return $output;
 532      }
 533  
 534      /**
 535       * Help function to return CSS class names for element (first/last/even/odd) with leading space
 536       *
 537       * @param int $idx index of this element in the row/column
 538       * @param int $maxidx maximum index of the element in the row/column
 539       * @return string
 540       */
 541      protected function get_css_class_suffix($idx, $maxidx) {
 542          $class = '';
 543          if ($idx == 0) {
 544              $class .= ' first';
 545          }
 546          if ($idx == $maxidx) {
 547              $class .= ' last';
 548          }
 549          if ($idx % 2) {
 550              $class .= ' odd';
 551          } else {
 552              $class .= ' even';
 553          }
 554          return $class;
 555      }
 556  
 557      /**
 558       * Displays for the student the list of instances or default content if no instances found
 559       *
 560       * @param array $instances array of objects of type gradingform_guide_instance
 561       * @param string $defaultcontent default string that would be displayed without advanced grading
 562       * @param bool $cangrade whether current user has capability to grade in this context
 563       * @return string
 564       */
 565      public function display_instances($instances, $defaultcontent, $cangrade) {
 566          $return = '';
 567          if (count($instances)) {
 568              $return .= html_writer::start_tag('div', array('class' => 'advancedgrade'));
 569              $idx = 0;
 570              foreach ($instances as $instance) {
 571                  $return .= $this->display_instance($instance, $idx++, $cangrade);
 572              }
 573              $return .= html_writer::end_tag('div');
 574          }
 575          return $return. $defaultcontent;
 576      }
 577  
 578      /**
 579       * Displays one grading instance
 580       *
 581       * @param gradingform_guide_instance $instance
 582       * @param int $idx unique number of instance on page
 583       * @param bool $cangrade whether current user has capability to grade in this context
 584       */
 585      public function display_instance(gradingform_guide_instance $instance, $idx, $cangrade) {
 586          $criteria = $instance->get_controller()->get_definition()->guide_criteria;
 587          $options = $instance->get_controller()->get_options();
 588          $values = $instance->get_guide_filling();
 589          if ($cangrade) {
 590              $mode = gradingform_guide_controller::DISPLAY_REVIEW;
 591          } else {
 592              $mode = gradingform_guide_controller::DISPLAY_VIEW;
 593          }
 594  
 595          $output = $this->box($instance->get_controller()->get_formatted_description(), 'gradingform_guide-description').
 596                    $this->display_guide($criteria, array(), $options, $mode, 'guide'.$idx, $values);
 597          return $output;
 598      }
 599  
 600  
 601      /**
 602       * Displays a confirmation message after a regrade has occured
 603       *
 604       * @param string $elementname
 605       * @param int $changelevel
 606       * @param int $value The regrade option that was used
 607       * @return string
 608       */
 609      public function display_regrade_confirmation($elementname, $changelevel, $value) {
 610          $html = html_writer::start_tag('div', array('class' => 'gradingform_guide-regrade'));
 611          if ($changelevel<=2) {
 612              $html .= get_string('regrademessage1', 'gradingform_guide');
 613              $selectoptions = array(
 614                  0 => get_string('regradeoption0', 'gradingform_guide'),
 615                  1 => get_string('regradeoption1', 'gradingform_guide')
 616              );
 617              $html .= html_writer::select($selectoptions, $elementname.'[regrade]', $value, false);
 618          } else {
 619              $html .= get_string('regrademessage5', 'gradingform_guide');
 620              $html .= html_writer::empty_tag('input', array('name' => $elementname.'[regrade]', 'value' => 1, 'type' => 'hidden'));
 621          }
 622          $html .= html_writer::end_tag('div');
 623          return $html;
 624      }
 625      /**
 626       * Generates and returns HTML code to display information box about how guide score is converted to the grade
 627       *
 628       * @param array $scores
 629       * @return string
 630       */
 631      public function display_guide_mapping_explained($scores) {
 632          $html = '';
 633          if (!$scores) {
 634              return $html;
 635          }
 636          if (isset($scores['modulegrade']) && $scores['maxscore'] != $scores['modulegrade']) {
 637              $html .= $this->box(html_writer::tag('div', get_string('guidemappingexplained', 'gradingform_guide', (object)$scores))
 638                  , 'generalbox gradingform_guide-error');
 639          }
 640  
 641          return $html;
 642      }
 643  }


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