PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/wiki/create_form.php

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