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.
   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   * Test form repeat elements + defaults
  19   *
  20   * @copyright 2020 Davo Smith, Synergy Learning
  21   * @package   core_form
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__.'/../../../../../config.php');
  26  
  27  defined('BEHAT_SITE_RUNNING') || die();
  28  
  29  global $CFG, $PAGE, $OUTPUT;
  30  require_once($CFG->libdir.'/formslib.php');
  31  $PAGE->set_url('/lib/form/tests/behat/fixtures/repeat_defaults_form.php');
  32  require_login();
  33  $PAGE->set_context(context_system::instance());
  34  
  35  /**
  36   * Class repeat_defaults_form
  37   * @package core_form
  38   */
  39  class repeat_defaults_form extends moodleform {
  40      /**
  41       * Form definition
  42       */
  43      public function definition() {
  44          $mform = $this->_form;
  45          $repeatcount = $this->_customdata['repeatcount'];
  46  
  47          $repeat = array();
  48          $repeatopts = array();
  49  
  50          $repeat[] = $mform->createElement('header', 'testheading', 'Heading {no}');
  51  
  52          $repeat[] = $mform->createElement('checkbox', 'testcheckbox', 'Test checkbox (default checked)');
  53          $repeatopts['testcheckbox']['default'] = 1;
  54  
  55          $repeat[] = $mform->createElement('advcheckbox', 'testadvcheckbox', 'Test advcheckbox (default checked)');
  56          $repeatopts['testadvcheckbox']['default'] = 1;
  57  
  58          $repeat[] = $mform->createElement('date_selector', 'testdate', 'Test date (default 8th Sept 2013)');
  59          $repeatopts['testdate']['default'] = mktime(0, 0, 0, 9, 8, 2013);
  60  
  61          $repeat[] = $mform->createElement('date_time_selector', 'testdatetime', 'Test datetime (default 8th Sept 2013, 10:30am)');
  62          $repeatopts['testdatetime']['default'] = mktime(10, 30, 0, 9, 8, 2013);
  63  
  64          $repeat[] = $mform->createElement('duration', 'testduration', 'Test duration (default 3 hours)');
  65          $repeatopts['testduration']['default'] = 3 * HOURSECS;
  66  
  67          $repeat[] = $mform->createElement('select', 'testselect', 'Test select (default B)', array(1 => 'A', 2 => 'B', 3 => 'C'));
  68          $repeatopts['testselect']['default'] = 2;
  69  
  70          $repeat[] = $mform->createElement('selectyesno', 'testselectyes', 'Test selectyesno (default yes)');
  71          $repeatopts['testselectyes']['default'] = 1;
  72  
  73          $repeat[] = $mform->createElement('selectyesno', 'testselectno', 'Test selectyesno (default no)');
  74          $repeatopts['testselectno']['default'] = 0;
  75  
  76          $repeat[] = $mform->createElement('text', 'testtext', 'Test text (default \'Testing 123\')');
  77          $repeatopts['testtext']['default'] = 'Testing 123';
  78          $repeatopts['testtext']['type'] = PARAM_TEXT;
  79  
  80          $this->repeat_elements($repeat, $repeatcount, $repeatopts, 'test_repeat', 'test_repeat_add', 1, 'Add repeats', true);
  81  
  82          $this->add_action_buttons();
  83      }
  84  }
  85  
  86  $repeatcount = optional_param('test_repeat', 1, PARAM_INT);
  87  $form = new repeat_defaults_form(null, array('repeatcount' => $repeatcount));
  88  
  89  echo $OUTPUT->header();
  90  $form->display();
  91  echo $OUTPUT->footer();