PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/mod/wiki/create_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 90 lines | 55 code | 12 blank | 23 comment | 10 complexity | 4f54405aa80d9667e32e61c87b4a92f0 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-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-2.0
  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. require_once($CFG->libdir.'/formslib.php');
  25. class mod_wiki_create_form extends moodleform {
  26. protected function definition() {
  27. $mform = $this->_form;
  28. $formats = $this->_customdata['formats'];
  29. $defaultformat = $this->_customdata['defaultformat'];
  30. $forceformat = $this->_customdata['forceformat'];
  31. $mform->addElement('header', 'general', get_string('newpagehdr', 'wiki'));
  32. $textoptions = array();
  33. if (!empty($this->_customdata['disable_pagetitle'])) {
  34. $textoptions = array('readonly'=>'readonly');
  35. }
  36. $mform->addElement('text', 'pagetitle', get_string('newpagetitle', 'wiki'), $textoptions);
  37. $mform->setType('pagetitle', PARAM_TEXT);
  38. $mform->addRule('pagetitle', get_string('required'), 'required', null, 'client');
  39. if ($forceformat) {
  40. $mform->addElement('hidden', 'pageformat', $defaultformat);
  41. } else {
  42. $mform->addElement('static', 'format', get_string('format', 'wiki'));
  43. $mform->addHelpButton('format', 'format', 'wiki');
  44. foreach ($formats as $format) {
  45. if ($format == $defaultformat) {
  46. $attr = array('checked'=>'checked');
  47. }else if (!empty($forceformat)){
  48. $attr = array('disabled'=>'disabled');
  49. } else {
  50. $attr = array();
  51. }
  52. $mform->addElement('radio', 'pageformat', '', get_string('format'.$format, 'wiki'), $format, $attr);
  53. }
  54. }
  55. $mform->setType('pageformat', PARAM_ALPHANUMEXT);
  56. $mform->addRule('pageformat', get_string('required'), 'required', null, 'client');
  57. if (!empty($this->_customdata['groups']->availablegroups)) {
  58. foreach ($this->_customdata['groups']->availablegroups as $groupdata) {
  59. $groupinfo[$groupdata->id] = $groupdata->name;
  60. }
  61. if (count($groupinfo) > 1) {
  62. $mform->addElement('select', 'groupinfo', get_string('group'), $groupinfo);
  63. $mform->setDefault('groupinfo', $this->_customdata['groups']->currentgroup);
  64. $mform->setType('groupinfo', PARAM_INT);
  65. } else {
  66. $groupid = key($groupinfo);
  67. $groupname = $groupinfo[$groupid];
  68. $mform->addElement('static', 'groupdesciption', get_string('group'), $groupname);
  69. $mform->addElement('hidden', 'groupinfo', $groupid);
  70. $mform->setType('groupinfo', PARAM_INT);
  71. }
  72. }
  73. //hiddens
  74. $mform->addElement('hidden', 'action', 'create');
  75. $mform->setType('action', PARAM_ALPHA);
  76. $this->add_action_buttons(false, get_string('createpage', 'wiki'));
  77. }
  78. }