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.
   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   * File containing the base import form.
  19   *
  20   * @package    tool_uploadcourse
  21   * @copyright  2013 Frédéric Massart
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  require_once($CFG->libdir.'/formslib.php');
  27  
  28  /**
  29   * Base import form.
  30   *
  31   * @package    tool_uploadcourse
  32   * @copyright  2013 Frédéric Massart
  33   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class tool_uploadcourse_base_form extends moodleform {
  36  
  37      /**
  38       * Empty definition.
  39       *
  40       * @return void
  41       */
  42      public function definition() {
  43      }
  44  
  45      /**
  46       * Adds the import settings part.
  47       *
  48       * @return void
  49       */
  50      public function add_import_options() {
  51          $mform = $this->_form;
  52  
  53          // Upload settings and file.
  54          $mform->addElement('header', 'importoptionshdr', get_string('importoptions', 'tool_uploadcourse'));
  55          $mform->setExpanded('importoptionshdr', true);
  56  
  57          $choices = array(
  58              tool_uploadcourse_processor::MODE_CREATE_NEW => get_string('createnew', 'tool_uploadcourse'),
  59              tool_uploadcourse_processor::MODE_CREATE_ALL => get_string('createall', 'tool_uploadcourse'),
  60              tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE => get_string('createorupdate', 'tool_uploadcourse'),
  61              tool_uploadcourse_processor::MODE_UPDATE_ONLY => get_string('updateonly', 'tool_uploadcourse')
  62          );
  63          $mform->addElement('select', 'options[mode]', get_string('mode', 'tool_uploadcourse'), $choices);
  64          $mform->addHelpButton('options[mode]', 'mode', 'tool_uploadcourse');
  65  
  66          $choices = array(
  67              tool_uploadcourse_processor::UPDATE_NOTHING => get_string('nochanges', 'tool_uploadcourse'),
  68              tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY => get_string('updatewithdataonly', 'tool_uploadcourse'),
  69              tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_OR_DEFAUTLS =>
  70                  get_string('updatewithdataordefaults', 'tool_uploadcourse'),
  71              tool_uploadcourse_processor::UPDATE_MISSING_WITH_DATA_OR_DEFAUTLS => get_string('updatemissing', 'tool_uploadcourse')
  72          );
  73          $mform->addElement('select', 'options[updatemode]', get_string('updatemode', 'tool_uploadcourse'), $choices);
  74          $mform->setDefault('options[updatemode]', tool_uploadcourse_processor::UPDATE_NOTHING);
  75          $mform->hideIf('options[updatemode]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
  76          $mform->hideIf('options[updatemode]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
  77          $mform->addHelpButton('options[updatemode]', 'updatemode', 'tool_uploadcourse');
  78  
  79          $mform->addElement('selectyesno', 'options[allowdeletes]', get_string('allowdeletes', 'tool_uploadcourse'));
  80          $mform->setDefault('options[allowdeletes]', 0);
  81          $mform->hideIf('options[allowdeletes]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
  82          $mform->hideIf('options[allowdeletes]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
  83          $mform->addHelpButton('options[allowdeletes]', 'allowdeletes', 'tool_uploadcourse');
  84  
  85          $mform->addElement('selectyesno', 'options[allowrenames]', get_string('allowrenames', 'tool_uploadcourse'));
  86          $mform->setDefault('options[allowrenames]', 0);
  87          $mform->hideIf('options[allowrenames]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
  88          $mform->hideIf('options[allowrenames]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
  89          $mform->addHelpButton('options[allowrenames]', 'allowrenames', 'tool_uploadcourse');
  90  
  91          $mform->addElement('selectyesno', 'options[allowresets]', get_string('allowresets', 'tool_uploadcourse'));
  92          $mform->setDefault('options[allowresets]', 0);
  93          $mform->hideIf('options[allowresets]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW);
  94          $mform->hideIf('options[allowresets]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL);
  95          $mform->addHelpButton('options[allowresets]', 'allowresets', 'tool_uploadcourse');
  96      }
  97  
  98  }