Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   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   * Random allocator settings form
  20   *
  21   * @package    workshopallocation
  22   * @subpackage random
  23   * @copyright  2009 David Mudrak <david.mudrak@gmail.com>
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  require_once($CFG->dirroot.'/lib/formslib.php');
  30  
  31  /**
  32   * Allocator settings form
  33   *
  34   * This is used by {@see workshop_random_allocator::ui()} to set up allocation parameters.
  35   *
  36   * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
  37   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class workshop_random_allocator_form extends moodleform {
  40  
  41      /**
  42       * Definition of the setting form elements
  43       */
  44      public function definition() {
  45          $mform          = $this->_form;
  46          $workshop       = $this->_customdata['workshop'];
  47          $plugindefaults = get_config('workshopallocation_random');
  48  
  49          $mform->addElement('header', 'randomallocationsettings', get_string('allocationsettings', 'workshopallocation_random'));
  50  
  51          $gmode = groups_get_activity_groupmode($workshop->cm, $workshop->course);
  52          switch ($gmode) {
  53          case NOGROUPS:
  54              $grouplabel = get_string('groupsnone', 'group');
  55              break;
  56          case VISIBLEGROUPS:
  57              $grouplabel = get_string('groupsvisible', 'group');
  58              break;
  59          case SEPARATEGROUPS:
  60              $grouplabel = get_string('groupsseparate', 'group');
  61              break;
  62          }
  63          $mform->addElement('static', 'groupmode', get_string('groupmode', 'group'), $grouplabel);
  64  
  65          $options_numper = array(
  66              workshop_random_allocator_setting::NUMPER_SUBMISSION => get_string('numperauthor', 'workshopallocation_random'),
  67              workshop_random_allocator_setting::NUMPER_REVIEWER   => get_string('numperreviewer', 'workshopallocation_random')
  68          );
  69          $grpnumofreviews = array();
  70          $grpnumofreviews[] = $mform->createElement('text', 'numofreviews', '', array('size' => 5, 'maxlength' => 20));
  71          $mform->setType('numofreviews', PARAM_INT);
  72          $mform->setDefault('numofreviews', $plugindefaults->numofreviews);
  73          $grpnumofreviews[] = $mform->createElement('select', 'numper', '', $options_numper);
  74          $mform->setDefault('numper', workshop_random_allocator_setting::NUMPER_SUBMISSION);
  75          $mform->addGroup($grpnumofreviews, 'grpnumofreviews', get_string('numofreviews', 'workshopallocation_random'),
  76                  array(' '), false);
  77  
  78          if (VISIBLEGROUPS == $gmode) {
  79              $mform->addElement('checkbox', 'excludesamegroup', get_string('excludesamegroup', 'workshopallocation_random'));
  80              $mform->setDefault('excludesamegroup', 0);
  81          } else {
  82              $mform->addElement('hidden', 'excludesamegroup', 0);
  83              $mform->setType('excludesamegroup', PARAM_BOOL);
  84          }
  85  
  86          $mform->addElement('checkbox', 'removecurrent', get_string('removecurrentallocations', 'workshopallocation_random'));
  87          $mform->setDefault('removecurrent', 0);
  88  
  89          $mform->addElement('checkbox', 'assesswosubmission', get_string('assesswosubmission', 'workshopallocation_random'));
  90          $mform->setDefault('assesswosubmission', 0);
  91  
  92          if (empty($workshop->useselfassessment)) {
  93              $mform->addElement('static', 'addselfassessment', get_string('addselfassessment', 'workshopallocation_random'),
  94                                                                   get_string('selfassessmentdisabled', 'workshop'));
  95          } else {
  96              $mform->addElement('checkbox', 'addselfassessment', get_string('addselfassessment', 'workshopallocation_random'));
  97          }
  98  
  99          $this->add_action_buttons();
 100      }
 101  
 102      /**
 103       * Validate the allocation settings.
 104       *
 105       * @param array $data
 106       * @param array $files
 107       * @return array
 108       */
 109      public function validation($data, $files): array {
 110  
 111          $errors = parent::validation($data, $files);
 112  
 113          if ($data['numofreviews'] < 0) {
 114              $errors['grpnumofreviews'] = get_string('invalidnum', 'core_error');
 115          }
 116  
 117          return $errors;
 118      }
 119  }