Merge branch 'MDL-27675_master' of git://github.com/grabs/moodle
[moodle.git] / mod / feedback / item / feedback_item_form_class.php
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/>.
17 require_once($CFG->libdir.'/formslib.php');
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     public function definition() {
23         $item = $this->_customdata['item']; //the item object
25         //common is an array like:
26         //    array('cmid'=>$cm->id,
27         //         'id'=>isset($item->id) ? $item->id : NULL,
28         //         'typ'=>$item->typ,
29         //         'items'=>$feedbackitems,
30         //         'feedback'=>$feedback->id);
31         $common = $this->_customdata['common'];
33         //positionlist is an array with possible positions for the item location
34         $positionlist = $this->_customdata['positionlist'];
36         //the current position of the item
37         $position = $this->_customdata['position'];
39         $mform =& $this->_form;
41         if ($common['items']) {
42             $mform->addElement('select',
43                                 'dependitem',
44                                 get_string('dependitem', 'feedback').'&nbsp;',
45                                 $common['items']
46                                 );
47             $mform->addHelpButton('dependitem', 'depending', 'feedback');
48             $mform->addElement('text',
49                                 'dependvalue',
50                                 get_string('dependvalue', 'feedback'),
51                                 array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255));
52         } else {
53             $mform->addElement('hidden', 'dependitem', 0);
54             $mform->setType('dependitem', PARAM_INT);
55             $mform->addElement('hidden', 'dependvalue', '');
56             $mform->setType('dependitem', PARAM_ALPHA);
57         }
59         $position_select = $mform->addElement('select',
60                                             'position',
61                                             get_string('position', 'feedback').'&nbsp;',
62                                             $positionlist);
63         $position_select->setValue($position);
65         $mform->addElement('hidden', 'cmid', $common['cmid']);
66         $mform->setType('cmid', PARAM_INT);
68         $mform->addElement('hidden', 'id', $common['id']);
69         $mform->setType('id', PARAM_INT);
71         $mform->addElement('hidden', 'feedback', $common['feedback']);
72         $mform->setType('feedback', PARAM_INT);
74         $mform->addElement('hidden', 'template', 0);
75         $mform->setType('template', PARAM_INT);
77         $mform->setType('name', PARAM_RAW);
78         $mform->setType('label', PARAM_ALPHANUM);
80         $mform->addElement('hidden', 'typ', $this->type);
81         $mform->setType('typ', PARAM_ALPHA);
83         $mform->addElement('hidden', 'hasvalue', 0);
84         $mform->setType('hasvalue', PARAM_INT);
86         $mform->addElement('hidden', 'options', '');
87         $mform->setType('options', PARAM_ALPHA);
89         $buttonarray = array();
90         if (!empty($item->id)) {
91             $buttonarray[] = &$mform->createElement('submit',
92                                                     'update_item',
93                                                     get_string('update_item', 'feedback'));
95             $buttonarray[] = &$mform->createElement('submit',
96                                                     'clone_item',
97                                                     get_string('save_as_new_item', 'feedback'));
98         } else {
99             $mform->addElement('hidden', 'clone_item', 0);
100             $mform->setType('clone_item', PARAM_INT);
101             $buttonarray[] = &$mform->createElement('submit',
102                                                     'save_item',
103                                                     get_string('save_item', 'feedback'));
104         }
105         $buttonarray[] = &$mform->createElement('cancel');
106         $mform->addGroup($buttonarray, 'buttonar', '&nbsp;', array(' '), false);
108     }