Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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 an mform to edit "Number of errors" grading strategy forms.
  20   *
  21   * @package    workshopform_numerrors
  22   * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once (__DIR__ . '/../../lib.php');   // module library
  29  require_once (__DIR__ . '/../edit_form.php');    // parent class definition
  30  
  31  /**
  32   * Class for editing "Number of errors" grading strategy forms.
  33   *
  34   * @uses moodleform
  35   */
  36  class workshop_edit_numerrors_strategy_form extends workshop_edit_strategy_form {
  37  
  38      /**
  39       * Define the elements to be displayed at the form
  40       *
  41       * Called by the parent::definition()
  42       *
  43       * @return void
  44       */
  45      protected function definition_inner(&$mform) {
  46  
  47          $plugindefaults     = get_config('workshopform_numerrors');
  48          $nodimensions       = $this->_customdata['nodimensions'];       // number of currently filled dimensions
  49          $norepeats          = $this->_customdata['norepeats'];          // number of dimensions to display
  50          $descriptionopts    = $this->_customdata['descriptionopts'];    // wysiwyg fields options
  51          $current            = $this->_customdata['current'];            // current data to be set
  52  
  53          $mform->addElement('hidden', 'norepeats', $norepeats);
  54          $mform->setType('norepeats', PARAM_INT);
  55          // value not to be overridden by submitted value
  56          $mform->setConstants(array('norepeats' => $norepeats));
  57  
  58          for ($i = 0; $i < $norepeats; $i++) {
  59              $mform->addElement('header', 'dimension'.$i, get_string('dimensionnumber', 'workshopform_numerrors', $i+1));
  60              $mform->addElement('hidden', 'dimensionid__idx_'.$i);   // the id in workshop_forms
  61              $mform->setType('dimensionid__idx_'.$i, PARAM_INT);
  62              $mform->addElement('editor', 'description__idx_'.$i.'_editor',
  63                      get_string('dimensiondescription', 'workshopform_numerrors'), '', $descriptionopts);
  64              $mform->addElement('text', 'grade0__idx_'.$i, get_string('grade0', 'workshopform_numerrors'), array('size'=>'15'));
  65              $mform->setDefault('grade0__idx_'.$i, $plugindefaults->grade0);
  66              $mform->setType('grade0__idx_'.$i, PARAM_TEXT);
  67              $mform->addElement('text', 'grade1__idx_'.$i, get_string('grade1', 'workshopform_numerrors'), array('size'=>'15'));
  68              $mform->setDefault('grade1__idx_'.$i, $plugindefaults->grade1);
  69              $mform->setType('grade1__idx_'.$i, PARAM_TEXT);
  70              $mform->addElement('select', 'weight__idx_'.$i,
  71                      get_string('dimensionweight', 'workshopform_numerrors'), workshop::available_dimension_weights_list());
  72              $mform->setDefault('weight__idx_'.$i, 1);
  73          }
  74  
  75          $mform->addElement('header', 'mappingheader', get_string('grademapping', 'workshopform_numerrors'));
  76          $mform->addElement('static', 'mappinginfo', get_string('maperror', 'workshopform_numerrors'),
  77                                                              get_string('mapgrade', 'workshopform_numerrors'));
  78  
  79          // get the total weight of all items == maximum weighted number of errors
  80          $totalweight = 0;
  81          for ($i = 0; $i < $norepeats; $i++) {
  82              if (!empty($current->{'weight__idx_'.$i})) {
  83                  $totalweight += $current->{'weight__idx_'.$i};
  84              }
  85          }
  86          $totalweight = max($totalweight, $nodimensions);
  87  
  88          $percents = array();
  89          $percents[''] = '';
  90          for ($i = 100; $i >= 0; $i--) {
  91              $percents[$i] = get_string('percents', 'moodle', $i);
  92          }
  93          $mform->addElement('static', 'mappingzero', 0, get_string('percents', 'moodle', 100));
  94          for ($i = 1; $i <= $totalweight; $i++) {
  95              $selects = array();
  96              $selects[] = $mform->createElement('select', 'map__idx_'.$i, $i, $percents);
  97              $selects[] = $mform->createElement('static', 'mapdefault__idx_'.$i, '',
  98                                          get_string('percents', 'moodle', floor(100 - $i * 100 / $totalweight)));
  99              $mform->addGroup($selects, 'grademapping'.$i, $i, array(' '), false);
 100              $mform->setDefault('map__idx_'.$i, '');
 101          }
 102  
 103          $mform->registerNoSubmitButton('noadddims');
 104          $mform->addElement('submit', 'noadddims', get_string('addmoredimensions', 'workshopform_numerrors',
 105                  workshop_numerrors_strategy::ADDDIMS));
 106          $mform->closeHeaderBefore('noadddims');
 107          $this->set_data($current);
 108  
 109      }
 110  
 111  }