Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 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 assessment 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 all assessment forms
  31   *
  32   * This defines the common fields that all assessment 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_assessment_form extends moodleform {
  39  
  40      /**
  41       * Add the fields that are common for all grading strategies.
  42       *
  43       * If the strategy does not support all these fields, then you can override
  44       * this method and remove the ones you don't want with
  45       * $mform->removeElement().
  46       * Strategy subclassess should define their own fields in definition_inner()
  47       *
  48       * @return void
  49       */
  50      public function definition() {
  51          global $CFG;
  52  
  53          $mform          = $this->_form;
  54          $this->mode     = $this->_customdata['mode'];       // influences the save buttons
  55          $this->strategy = $this->_customdata['strategy'];   // instance of the strategy api class
  56          $this->workshop = $this->_customdata['workshop'];   // instance of the workshop api class
  57          $this->options  = $this->_customdata['options'];    // array with addiotional options
  58  
  59          // Disable shortforms
  60          $mform->setDisableShortforms();
  61  
  62          // add the strategy-specific fields
  63          $this->definition_inner($mform);
  64  
  65          // add the data common for all subplugins
  66          $mform->addElement('hidden', 'strategy', $this->workshop->strategy);
  67          $mform->setType('strategy', PARAM_PLUGIN);
  68  
  69          if ($this->workshop->overallfeedbackmode and $this->is_editable()) {
  70              $mform->addElement('header', 'overallfeedbacksection', get_string('overallfeedback', 'mod_workshop'));
  71              $mform->addElement('editor', 'feedbackauthor_editor', get_string('feedbackauthor', 'mod_workshop'), null,
  72                  $this->workshop->overall_feedback_content_options());
  73              if ($this->workshop->overallfeedbackmode == 2) {
  74                  $mform->addRule('feedbackauthor_editor', null, 'required', null, 'client');
  75              }
  76              if ($this->workshop->overallfeedbackfiles) {
  77                  $mform->addElement('filemanager', 'feedbackauthorattachment_filemanager',
  78                      get_string('feedbackauthorattachment', 'mod_workshop'), null,
  79                      $this->workshop->overall_feedback_attachment_options());
  80              }
  81          }
  82  
  83          if (!empty($this->options['editableweight']) and $this->is_editable()) {
  84              $mform->addElement('header', 'assessmentsettings', get_string('assessmentweight', 'workshop'));
  85              $mform->addElement('select', 'weight',
  86                      get_string('assessmentweight', 'workshop'), workshop::available_assessment_weights_list());
  87              $mform->setDefault('weight', 1);
  88          }
  89  
  90          $buttonarray = array();
  91          if ($this->mode == 'preview') {
  92              $buttonarray[] = $mform->createElement('cancel', 'backtoeditform', get_string('backtoeditform', 'workshop'));
  93          }
  94          if ($this->mode == 'assessment') {
  95              if (!empty($this->options['pending'])) {
  96                  $buttonarray[] = $mform->createElement('submit', 'saveandshownext', get_string('saveandshownext', 'workshop'));
  97              }
  98              $buttonarray[] = $mform->createElement('submit', 'saveandclose', get_string('saveandclose', 'workshop'));
  99              $buttonarray[] = $mform->createElement('submit', 'saveandcontinue', get_string('saveandcontinue', 'workshop'));
 100              $buttonarray[] = $mform->createElement('cancel');
 101          }
 102          $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
 103          $mform->closeHeaderBefore('buttonar');
 104      }
 105  
 106      /**
 107       * Add any strategy specific form fields.
 108       *
 109       * @param stdClass $mform the form being built.
 110       */
 111      protected function definition_inner(&$mform) {
 112          // By default, do nothing.
 113      }
 114  
 115      /**
 116       * Is the form frozen (read-only)?
 117       *
 118       * @return boolean
 119       */
 120      public function is_editable() {
 121          return !$this->_form->isFrozen();
 122      }
 123  
 124      /**
 125       * Return the form custom data.
 126       *
 127       * @return array an array containing the custom data
 128       * @since  Moodle 3.4
 129       */
 130      public function get_customdata() {
 131          return $this->_customdata;
 132      }
 133  }