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

/mod/feedback/item/feedback_item_form_class.php

https://bitbucket.org/ngmares/moodle
PHP | 110 lines | 68 code | 20 blank | 22 comment | 4 complexity | 4a6191a3c1afb77eab41fded44f436c3 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, GPL-3.0, Apache-2.0, 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 ($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. } else {
  46. $mform->addElement('hidden', 'dependitem', 0);
  47. $mform->setType('dependitem', PARAM_INT);
  48. $mform->addElement('hidden', 'dependvalue', '');
  49. $mform->setType('dependitem', PARAM_ALPHA);
  50. }
  51. $position_select = $mform->addElement('select',
  52. 'position',
  53. get_string('position', 'feedback').'&nbsp;',
  54. $positionlist);
  55. $position_select->setValue($position);
  56. $mform->addElement('hidden', 'cmid', $common['cmid']);
  57. $mform->setType('cmid', PARAM_INT);
  58. $mform->addElement('hidden', 'id', $common['id']);
  59. $mform->setType('id', PARAM_INT);
  60. $mform->addElement('hidden', 'feedback', $common['feedback']);
  61. $mform->setType('feedback', PARAM_INT);
  62. $mform->addElement('hidden', 'template', 0);
  63. $mform->setType('template', PARAM_INT);
  64. $mform->setType('name', PARAM_RAW);
  65. $mform->setType('label', PARAM_ALPHANUM);
  66. $mform->addElement('hidden', 'typ', $this->type);
  67. $mform->setType('typ', PARAM_ALPHA);
  68. $mform->addElement('hidden', 'hasvalue', 0);
  69. $mform->setType('hasvalue', PARAM_INT);
  70. $mform->addElement('hidden', 'options', '');
  71. $mform->setType('options', PARAM_ALPHA);
  72. $buttonarray = array();
  73. if (!empty($item->id)) {
  74. $buttonarray[] = &$mform->createElement('submit',
  75. 'update_item',
  76. get_string('update_item', 'feedback'));
  77. $buttonarray[] = &$mform->createElement('submit',
  78. 'clone_item',
  79. get_string('save_as_new_item', 'feedback'));
  80. } else {
  81. $mform->addElement('hidden', 'clone_item', 0);
  82. $mform->setType('clone_item', PARAM_INT);
  83. $buttonarray[] = &$mform->createElement('submit',
  84. 'save_item',
  85. get_string('save_item', 'feedback'));
  86. }
  87. $buttonarray[] = &$mform->createElement('cancel');
  88. $mform->addGroup($buttonarray, 'buttonar', '&nbsp;', array(' '), false);
  89. }
  90. }