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.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   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   * This file defines a base class for all grading strategy editing forms.
  19   *
  20   * @package    mod_workshop
  21   * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  require_once($CFG->libdir . '/formslib.php'); // parent class definition
  28  
  29  /**
  30   * Base class for editing all the strategy grading forms.
  31   *
  32   * This defines the common fields that all strategy grading forms need.
  33   * Strategies should define their own  class that inherits from this one, and
  34   * implements the definition_inner() method.
  35   *
  36   * @uses moodleform
  37   */
  38  class workshop_edit_strategy_form extends moodleform {
  39  
  40      /** strategy logic instance that this class is editor of */
  41      protected $strategy;
  42  
  43      /**
  44       * Add the fields that are common for all grading strategies.
  45       *
  46       * If the strategy does not support all these fields, then you can override
  47       * this method and remove the ones you don't want with
  48       * $mform->removeElement().
  49       * Stretegy subclassess should define their own fields in definition_inner()
  50       *
  51       * @return void
  52       */
  53      public function definition() {
  54          global $CFG;
  55  
  56          $mform = $this->_form;
  57          $this->workshop = $this->_customdata['workshop'];
  58          $this->strategy = $this->_customdata['strategy'];
  59  
  60          $mform->addElement('hidden', 'workshopid', $this->workshop->id);        // workshopid
  61          $mform->setType('workshopid', PARAM_INT);
  62  
  63          $mform->addElement('hidden', 'strategy', $this->workshop->strategy);    // strategy name
  64          $mform->setType('strategy', PARAM_PLUGIN);
  65  
  66          $this->definition_inner($mform);
  67  
  68          // todo - tags support
  69          //if (!empty($CFG->usetags)) {
  70          //    $mform->addElement('header', 'tagsheader', get_string('tags'));
  71          //    $mform->addElement('tags', 'tags', get_string('tags'));
  72          //}
  73  
  74          $buttonarray = array();
  75          $buttonarray[] = $mform->createElement('submit', 'saveandcontinue', get_string('saveandcontinue', 'workshop'));
  76          $buttonarray[] = $mform->createElement('submit', 'saveandpreview', get_string('saveandpreview', 'workshop'));
  77          $buttonarray[] = $mform->createElement('submit', 'saveandclose', get_string('saveandclose', 'workshop'));
  78          $buttonarray[] = $mform->createElement('cancel');
  79          $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
  80          $mform->closeHeaderBefore('buttonar');
  81      }
  82  
  83      /**
  84       * Validate the submitted form data.
  85       *
  86       * Grading strategy plugins can provide their own validation rules by
  87       * overriding the {@link self::validation_inner()} method.
  88       *
  89       * @param array $data
  90       * @param array $files
  91       * @return array
  92       */
  93      final public function validation($data, $files) {
  94          return array_merge(
  95              parent::validation($data, $files),
  96              $this->validation_inner($data, $files)
  97          );
  98      }
  99  
 100      /**
 101       * Add any strategy specific form fields.
 102       *
 103       * @param stdClass $mform the form being built.
 104       */
 105      protected function definition_inner(&$mform) {
 106          // By default, do nothing.
 107      }
 108  
 109      /**
 110       * Add strategy specific validation rules.
 111       *
 112       * @param array $data
 113       * @param array $files
 114       * @return array
 115       */
 116      protected function validation_inner($data, $files) {
 117          return array();
 118      }
 119  }