Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]
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 require_once($CFG->libdir.'/formslib.php'); 18 19 define('FEEDBACK_ITEM_NAME_TEXTBOX_SIZE', 80); 20 define('FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE', 20); 21 abstract class feedback_item_form extends moodleform { 22 23 /** @var string type value in the hidden element. */ 24 protected $type; 25 26 public function definition() { 27 $item = $this->_customdata['item']; //the item object 28 29 //common is an array like: 30 // array('cmid'=>$cm->id, 31 // 'id'=>isset($item->id) ? $item->id : NULL, 32 // 'typ'=>$item->typ, 33 // 'items'=>$feedbackitems, 34 // 'feedback'=>$feedback->id); 35 $common = $this->_customdata['common']; 36 37 //positionlist is an array with possible positions for the item location 38 $positionlist = $this->_customdata['positionlist']; 39 40 //the current position of the item 41 $position = $this->_customdata['position']; 42 43 $mform =& $this->_form; 44 45 if (array_filter(array_keys($common['items']))) { 46 $mform->addElement('select', 47 'dependitem', 48 get_string('dependitem', 'feedback').' ', 49 $common['items'] 50 ); 51 $mform->addHelpButton('dependitem', 'depending', 'feedback'); 52 $mform->addElement('text', 53 'dependvalue', 54 get_string('dependvalue', 'feedback'), 55 array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255)); 56 $mform->hideIf('dependvalue', 'dependitem', 'eq', '0'); 57 } else { 58 $mform->addElement('hidden', 'dependitem', 0); 59 $mform->addElement('hidden', 'dependvalue', ''); 60 } 61 62 $mform->setType('dependitem', PARAM_INT); 63 $mform->setType('dependvalue', PARAM_RAW); 64 65 $position_select = $mform->addElement('select', 66 'position', 67 get_string('position', 'feedback').' ', 68 $positionlist); 69 $position_select->setValue($position); 70 71 $mform->addElement('hidden', 'cmid', $common['cmid']); 72 $mform->setType('cmid', PARAM_INT); 73 74 $mform->addElement('hidden', 'id', $common['id']); 75 $mform->setType('id', PARAM_INT); 76 77 $mform->addElement('hidden', 'feedback', $common['feedback']); 78 $mform->setType('feedback', PARAM_INT); 79 80 $mform->addElement('hidden', 'template', 0); 81 $mform->setType('template', PARAM_INT); 82 83 $mform->setType('name', PARAM_RAW); 84 $mform->setType('label', PARAM_NOTAGS); 85 86 $mform->addElement('hidden', 'typ', $this->type); 87 $mform->setType('typ', PARAM_ALPHA); 88 89 $mform->addElement('hidden', 'hasvalue', 0); 90 $mform->setType('hasvalue', PARAM_INT); 91 92 $mform->addElement('hidden', 'options', ''); 93 $mform->setType('options', PARAM_ALPHA); 94 95 $buttonarray = array(); 96 if (!empty($item->id)) { 97 $buttonarray[] = &$mform->createElement('submit', 98 'update_item', 99 get_string('update_item', 'feedback')); 100 101 $buttonarray[] = &$mform->createElement('submit', 102 'clone_item', 103 get_string('save_as_new_item', 'feedback')); 104 } else { 105 $mform->addElement('hidden', 'clone_item', 0); 106 $mform->setType('clone_item', PARAM_INT); 107 $buttonarray[] = &$mform->createElement('submit', 108 'save_item', 109 get_string('savechanges')); 110 } 111 $buttonarray[] = &$mform->createElement('cancel'); 112 $mform->addGroup($buttonarray, 'buttonar', ' ', array(' '), false); 113 114 } 115 116 /** 117 * Return submitted data if properly submitted or returns NULL if validation fails or 118 * if there is no submitted data. 119 * 120 * @return object submitted data; NULL if not valid or not submitted or cancelled 121 */ 122 public function get_data() { 123 if ($item = parent::get_data()) { 124 if (!isset($item->dependvalue)) { 125 $item->dependvalue = ''; 126 } 127 } 128 return $item; 129 } 130 } 131
title
Description
Body
title
Description
Body
title
Description
Body
title
Body