Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are 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   * The MongoDB plugin form for adding an instance.
  19   *
  20   * The following settings are provided:
  21   *      - server
  22   *      - username
  23   *      - password
  24   *      - database
  25   *      - replicaset
  26   *      - usesafe
  27   *      - extendedmode
  28   *
  29   * @package    cachestore_mongodb
  30   * @copyright  2012 Sam Hemelryk
  31   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  
  34  defined('MOODLE_INTERNAL') || die();
  35  
  36  // Include the necessary evils.
  37  require_once($CFG->dirroot.'/cache/forms.php');
  38  
  39  /**
  40   * The form to add an instance of the MongoDB store to the system.
  41   *
  42   * @copyright  2012 Sam Hemelryk
  43   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  44   */
  45  class cachestore_mongodb_addinstance_form extends cachestore_addinstance_form {
  46  
  47      /**
  48       * The forms custom definitions.
  49       */
  50      protected function configuration_definition() {
  51          global $OUTPUT;
  52          $form = $this->_form;
  53  
  54          if (!version_compare(phpversion('mongodb'), '1.5', 'ge')) {
  55              $form->addElement('html', $OUTPUT->notification(get_string('pleaseupgrademongo', 'cachestore_mongodb')));
  56          }
  57  
  58          $form->addElement('text', 'server', get_string('server', 'cachestore_mongodb'), array('size' => 72));
  59          $form->addHelpButton('server', 'server', 'cachestore_mongodb');
  60          $form->addRule('server', get_string('required'), 'required');
  61          $form->setDefault('server', 'mongodb://127.0.0.1:27017');
  62          $form->setType('server', PARAM_RAW);
  63  
  64          $form->addElement('text', 'database', get_string('database', 'cachestore_mongodb'));
  65          $form->addHelpButton('database', 'database', 'cachestore_mongodb');
  66          $form->addRule('database', get_string('required'), 'required');
  67          $form->setType('database', PARAM_ALPHANUMEXT);
  68          $form->setDefault('database', 'mcache');
  69  
  70          $form->addElement('text', 'username', get_string('username', 'cachestore_mongodb'));
  71          $form->addHelpButton('username', 'username', 'cachestore_mongodb');
  72          $form->setType('username', PARAM_ALPHANUMEXT);
  73  
  74          $form->addElement('passwordunmask', 'password', get_string('password', 'cachestore_mongodb'));
  75          $form->addHelpButton('password', 'password', 'cachestore_mongodb');
  76          $form->setType('password', PARAM_TEXT);
  77  
  78          $form->addElement('text', 'replicaset', get_string('replicaset', 'cachestore_mongodb'));
  79          $form->addHelpButton('replicaset', 'replicaset', 'cachestore_mongodb');
  80          $form->setType('replicaset', PARAM_ALPHANUMEXT);
  81          $form->setAdvanced('replicaset');
  82  
  83          $form->addElement('checkbox', 'usesafe', get_string('usesafe', 'cachestore_mongodb'));
  84          $form->addHelpButton('usesafe', 'usesafe', 'cachestore_mongodb');
  85          $form->setDefault('usesafe', 1);
  86          $form->setAdvanced('usesafe');
  87          $form->setType('usesafe', PARAM_BOOL);
  88  
  89          $form->addElement('text', 'usesafevalue', get_string('usesafevalue', 'cachestore_mongodb'));
  90          $form->addHelpButton('usesafevalue', 'usesafevalue', 'cachestore_mongodb');
  91          $form->disabledIf('usesafevalue', 'usesafe', 'notchecked');
  92          $form->setType('usesafevalue', PARAM_INT);
  93          $form->setAdvanced('usesafevalue');
  94  
  95          $form->addElement('checkbox', 'extendedmode', get_string('extendedmode', 'cachestore_mongodb'));
  96          $form->addHelpButton('extendedmode', 'extendedmode', 'cachestore_mongodb');
  97          $form->setDefault('extendedmode', 0);
  98          $form->setAdvanced('extendedmode');
  99          $form->setType('extendedmode', PARAM_BOOL);
 100      }
 101  }