Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.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   * This file defines mforms to assess a submission by rubric grading strategy
  20   *
  21   * Rubric can be displayed in two possible layouts - list or grid. This file defines
  22   * therefore defines two classes, respectively.
  23   *
  24   * @package    workshopform_rubric
  25   * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
  26   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27   */
  28  
  29  defined('MOODLE_INTERNAL') || die();
  30  
  31  require_once (__DIR__ . '/../assessment_form.php');    // parent class definition
  32  
  33  /**
  34   * Base class representing a form for assessing submissions by rubric grading strategy
  35   */
  36  abstract class workshop_rubric_assessment_form extends workshop_assessment_form {
  37  
  38      public function validation($data, $files) {
  39  
  40          $errors = parent::validation($data, $files);
  41          for ($i = 0; isset($data['dimensionid__idx_'.$i]); $i++) {
  42              if (empty($data['chosenlevelid__idx_'.$i])) {
  43                  $errors['chosenlevelid__idx_'.$i] = get_string('mustchooseone', 'workshopform_rubric'); // used in grid
  44                  $errors['levelgrp__idx_'.$i] = get_string('mustchooseone', 'workshopform_rubric');      // used in list
  45              }
  46          }
  47          return $errors;
  48      }
  49  }
  50  
  51  /**
  52   * Class representing a form for assessing submissions by rubric grading strategy - list layout
  53   */
  54  class workshop_rubric_list_assessment_form extends workshop_rubric_assessment_form {
  55  
  56      /**
  57       * Define the elements to be displayed at the form
  58       *
  59       * Called by the parent::definition()
  60       *
  61       * @return void
  62       */
  63      protected function definition_inner(&$mform) {
  64          $workshop   = $this->_customdata['workshop'];
  65          $fields     = $this->_customdata['fields'];
  66          $current    = $this->_customdata['current'];
  67          $nodims     = $this->_customdata['nodims'];     // number of assessment dimensions
  68  
  69          for ($i = 0; $i < $nodims; $i++) {
  70              // dimension header
  71              $dimtitle = get_string('dimensionnumber', 'workshopform_rubric', $i+1);
  72              $mform->addElement('header', 'dimensionhdr__idx_'.$i, $dimtitle);
  73  
  74              // dimension id
  75              $mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields->{'dimensionid__idx_'.$i});
  76              $mform->setType('dimensionid__idx_'.$i, PARAM_INT);
  77  
  78              // grade id
  79              $mform->addElement('hidden', 'gradeid__idx_'.$i);   // value set by set_data() later
  80              $mform->setType('gradeid__idx_'.$i, PARAM_INT);
  81  
  82              // dimension description
  83              $desc = '<div id="id_dim_'.$fields->{'dimensionid__idx_'.$i}.'_desc" class="fitem description rubric">'."\n";
  84              $desc .= format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'});
  85              $desc .= "\n</div>";
  86              $mform->addElement('html', $desc);
  87  
  88              $numoflevels = $fields->{'numoflevels__idx_'.$i};
  89              $levelgrp   = array();
  90              for ($j = 0; $j < $numoflevels; $j++) {
  91                  $levelid = $fields->{'levelid__idx_'.$i.'__idy_'.$j};
  92                  $definition = $fields->{'definition__idx_'.$i.'__idy_'.$j};
  93                  $definitionformat = $fields->{'definition__idx_'.$i.'__idy_'.$j.'format'};
  94                  $levelgrp[] = $mform->createElement('radio', 'chosenlevelid__idx_'.$i, '',
  95                          format_text($definition, $definitionformat, null, $workshop->course->id), $levelid);
  96              }
  97              $mform->addGroup($levelgrp, 'levelgrp__idx_'.$i, '', "<br />\n", false);
  98          }
  99          $this->set_data($current);
 100      }
 101  }
 102  
 103  /**
 104   * Class representing a form for assessing submissions by rubric grading strategy - grid layout
 105   */
 106  class workshop_rubric_grid_assessment_form extends workshop_rubric_assessment_form {
 107  
 108      /**
 109       * Define the elements to be displayed at the form
 110       *
 111       * Called by the parent::definition()
 112       *
 113       * @return void
 114       */
 115      protected function definition_inner(&$mform) {
 116          $workshop   = $this->_customdata['workshop'];
 117          $fields     = $this->_customdata['fields'];
 118          $current    = $this->_customdata['current'];
 119          $nodims     = $this->_customdata['nodims'];     // number of assessment dimensions
 120  
 121          // get the number of required grid columns
 122          $levelcounts = array();
 123          for ($i = 0; $i < $nodims; $i++) {
 124              if ($fields->{'numoflevels__idx_'.$i} > 0) {
 125                  $levelcounts[] = $fields->{'numoflevels__idx_'.$i};
 126              }
 127          }
 128          $numofcolumns = array_reduce($levelcounts, 'workshop::lcm', 1);
 129  
 130          $mform->addElement('header', 'rubric-grid-wrapper', get_string('layoutgrid', 'workshopform_rubric'));
 131  
 132          $mform->addElement('html', '<table class="rubric-grid">' . "\n");
 133          $mform->addElement('html', '<th class="header">' . get_string('criteria', 'workshopform_rubric') . '</th>');
 134          $mform->addElement('html', '<th class="header" colspan="'.$numofcolumns.'">'.get_string('levels', 'workshopform_rubric').'</th>');
 135  
 136          for ($i = 0; $i < $nodims; $i++) {
 137  
 138              $mform->addElement('html', '<tr class="r'. $i % 2  .'"><td class="criterion">' . "\n");
 139  
 140              // dimension id
 141              $mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields->{'dimensionid__idx_'.$i});
 142              $mform->setType('dimensionid__idx_'.$i, PARAM_INT);
 143  
 144              // given grade id
 145              $mform->addElement('hidden', 'gradeid__idx_'.$i);   // value set by set_data() later
 146              $mform->setType('gradeid__idx_'.$i, PARAM_INT);
 147  
 148              // dimension description
 149              $desc = format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'});
 150              $desc .= "</td>\n";
 151              $mform->addElement('html', $desc);
 152  
 153              $numoflevels = $fields->{'numoflevels__idx_'.$i};
 154              for ($j = 0; $j < $numoflevels; $j++) {
 155                  $colspan = $numofcolumns / $numoflevels;
 156                  $mform->addElement('html', '<td class="level c' . $j % 2  . '" colspan="' . $colspan . '">' . "\n");
 157                  $levelid = $fields->{'levelid__idx_'.$i.'__idy_'.$j};
 158                  $definition = $fields->{'definition__idx_'.$i.'__idy_'.$j};
 159                  $definitionformat = $fields->{'definition__idx_'.$i.'__idy_'.$j.'format'};
 160                  $mform->addElement('radio', 'chosenlevelid__idx_'.$i, '',
 161                          format_text($definition, $definitionformat, null, $workshop->course->id), $levelid);
 162                  $mform->addElement('html', '</td>' . "\n");
 163              }
 164              $mform->addElement('html', '</tr>' . "\n");
 165          }
 166          $mform->addElement('html', '</table>' . "\n");
 167  
 168          $this->set_data($current);
 169      }
 170  }