Search moodle.org's
Developer Documentation

   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   * This file contains all necessary code to define and process an edit form
  20   *
  21   * @package mod_wiki
  22   * @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
  23   *
  24   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  require_once($CFG->libdir.'/formslib.php');
  28  
  29  class mod_wiki_create_form extends moodleform {
  30  
  31      protected function definition() {
  32          $mform = $this->_form;
  33  
  34          $formats = $this->_customdata['formats'];
  35          $defaultformat = $this->_customdata['defaultformat'];
  36          $forceformat = $this->_customdata['forceformat'];
  37  
  38          $mform->addElement('header', 'general', get_string('newpagehdr', 'wiki'));
  39  
  40          $textoptions = array();
  41          if (!empty($this->_customdata['disable_pagetitle'])) {
  42              $textoptions = array('readonly'=>'readonly');
  43          }
  44          $mform->addElement('text', 'pagetitle', get_string('newpagetitle', 'wiki'), $textoptions);
  45          $mform->setType('pagetitle', PARAM_TEXT);
  46          $mform->addRule('pagetitle', get_string('required'), 'required', null, 'client');
  47  
  48          if ($forceformat) {
  49              $mform->addElement('hidden', 'pageformat', $defaultformat);
  50          } else {
  51              $mform->addElement('static', 'format', get_string('format', 'wiki'));
  52              $mform->addHelpButton('format', 'format', 'wiki');
  53              foreach ($formats as $format) {
  54                  if ($format == $defaultformat) {
  55                      $attr = array('checked'=>'checked');
  56                  }else if (!empty($forceformat)){
  57                      $attr = array('disabled'=>'disabled');
  58                  } else {
  59                      $attr = array();
  60                  }
  61                  $mform->addElement('radio', 'pageformat', '', get_string('format'.$format, 'wiki'), $format, $attr);
  62              }
  63          }
  64          $mform->setType('pageformat', PARAM_ALPHANUMEXT);
  65          $mform->addRule('pageformat', get_string('required'), 'required', null, 'client');
  66  
  67          if (!empty($this->_customdata['groups']->availablegroups)) {
  68              foreach ($this->_customdata['groups']->availablegroups as $groupdata) {
  69                  $groupinfo[$groupdata->id] = $groupdata->name;
  70              }
  71              if (count($groupinfo) > 1) {
  72                  $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
  73                  $mform->setDefault('groupinfo', $this->_customdata['groups']->currentgroup);
  74                  $mform->setType('groupinfo', PARAM_INT);
  75              } else {
  76                  $groupid = key($groupinfo);
  77                  $groupname = $groupinfo[$groupid];
  78                  $mform->addElement('static', 'groupdesciption', get_string('group'), $groupname);
  79                  $mform->addElement('hidden', 'groupinfo', $groupid);
  80                  $mform->setType('groupinfo', PARAM_INT);
  81              }
  82          }
  83  
  84          //hiddens
  85          $mform->addElement('hidden', 'action', 'create');
  86          $mform->setType('action', PARAM_ALPHA);
  87  
  88          $this->add_action_buttons(false, get_string('createpage', 'wiki'));
  89      }
  90  }

Search This Site: