PageRenderTime 52ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/feedback/item/feedback_item_form_class.php

http://github.com/moodle/moodle
PHP | 127 lines | 77 code | 22 blank | 28 comment | 6 complexity | c096eaffa8942a3a2a7f82334e6c8ff5 MD5 | raw file
Possible License(s): MIT, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, Apache-2.0, LGPL-2.1, BSD-3-Clause
  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. require_once($CFG->libdir.'/formslib.php');
  17. define('FEEDBACK_ITEM_NAME_TEXTBOX_SIZE', 80);
  18. define('FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE', 20);
  19. abstract class feedback_item_form extends moodleform {
  20. public function definition() {
  21. $item = $this->_customdata['item']; //the item object
  22. //common is an array like:
  23. // array('cmid'=>$cm->id,
  24. // 'id'=>isset($item->id) ? $item->id : NULL,
  25. // 'typ'=>$item->typ,
  26. // 'items'=>$feedbackitems,
  27. // 'feedback'=>$feedback->id);
  28. $common = $this->_customdata['common'];
  29. //positionlist is an array with possible positions for the item location
  30. $positionlist = $this->_customdata['positionlist'];
  31. //the current position of the item
  32. $position = $this->_customdata['position'];
  33. $mform =& $this->_form;
  34. if (array_filter(array_keys($common['items']))) {
  35. $mform->addElement('select',
  36. 'dependitem',
  37. get_string('dependitem', 'feedback').'&nbsp;',
  38. $common['items']
  39. );
  40. $mform->addHelpButton('dependitem', 'depending', 'feedback');
  41. $mform->addElement('text',
  42. 'dependvalue',
  43. get_string('dependvalue', 'feedback'),
  44. array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255));
  45. $mform->hideIf('dependvalue', 'dependitem', 'eq', '0');
  46. } else {
  47. $mform->addElement('hidden', 'dependitem', 0);
  48. $mform->addElement('hidden', 'dependvalue', '');
  49. }
  50. $mform->setType('dependitem', PARAM_INT);
  51. $mform->setType('dependvalue', PARAM_RAW);
  52. $position_select = $mform->addElement('select',
  53. 'position',
  54. get_string('position', 'feedback').'&nbsp;',
  55. $positionlist);
  56. $position_select->setValue($position);
  57. $mform->addElement('hidden', 'cmid', $common['cmid']);
  58. $mform->setType('cmid', PARAM_INT);
  59. $mform->addElement('hidden', 'id', $common['id']);
  60. $mform->setType('id', PARAM_INT);
  61. $mform->addElement('hidden', 'feedback', $common['feedback']);
  62. $mform->setType('feedback', PARAM_INT);
  63. $mform->addElement('hidden', 'template', 0);
  64. $mform->setType('template', PARAM_INT);
  65. $mform->setType('name', PARAM_RAW);
  66. $mform->setType('label', PARAM_NOTAGS);
  67. $mform->addElement('hidden', 'typ', $this->type);
  68. $mform->setType('typ', PARAM_ALPHA);
  69. $mform->addElement('hidden', 'hasvalue', 0);
  70. $mform->setType('hasvalue', PARAM_INT);
  71. $mform->addElement('hidden', 'options', '');
  72. $mform->setType('options', PARAM_ALPHA);
  73. $buttonarray = array();
  74. if (!empty($item->id)) {
  75. $buttonarray[] = &$mform->createElement('submit',
  76. 'update_item',
  77. get_string('update_item', 'feedback'));
  78. $buttonarray[] = &$mform->createElement('submit',
  79. 'clone_item',
  80. get_string('save_as_new_item', 'feedback'));
  81. } else {
  82. $mform->addElement('hidden', 'clone_item', 0);
  83. $mform->setType('clone_item', PARAM_INT);
  84. $buttonarray[] = &$mform->createElement('submit',
  85. 'save_item',
  86. get_string('save_item', 'feedback'));
  87. }
  88. $buttonarray[] = &$mform->createElement('cancel');
  89. $mform->addGroup($buttonarray, 'buttonar', '&nbsp;', array(' '), false);
  90. }
  91. /**
  92. * Return submitted data if properly submitted or returns NULL if validation fails or
  93. * if there is no submitted data.
  94. *
  95. * @return object submitted data; NULL if not valid or not submitted or cancelled
  96. */
  97. public function get_data() {
  98. if ($item = parent::get_data()) {
  99. if (!isset($item->dependvalue)) {
  100. $item->dependvalue = '';
  101. }
  102. }
  103. return $item;
  104. }
  105. }