Merge branch 'MDL-27675_master' of git://github.com/grabs/moodle
[moodle.git] / mod / feedback / item / feedback_item_form_class.php
CommitLineData
a627a9c1 1<?php
9c5bc7a5
AG
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/>.
a627a9c1 16
9c5bc7a5 17require_once($CFG->libdir.'/formslib.php');
a627a9c1 18
ed93c78b 19define('FEEDBACK_ITEM_NAME_TEXTBOX_SIZE', 80);
b7a47958 20define('FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE', 20);
ab5bd34d 21abstract class feedback_item_form extends moodleform {
9c5bc7a5 22 public function definition() {
5e97c34d 23 $item = $this->_customdata['item']; //the item object
9c5bc7a5 24
5e97c34d
AG
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'];
9c5bc7a5 32
5e97c34d
AG
33 //positionlist is an array with possible positions for the item location
34 $positionlist = $this->_customdata['positionlist'];
9c5bc7a5 35
5e97c34d
AG
36 //the current position of the item
37 $position = $this->_customdata['position'];
9c5bc7a5 38
5e97c34d 39 $mform =& $this->_form;
9c5bc7a5
AG
40
41 if ($common['items']) {
5e97c34d
AG
42 $mform->addElement('select',
43 'dependitem',
44 get_string('dependitem', 'feedback').'&nbsp;',
45 $common['items']
46 );
47 $mform->addHelpButton('dependitem', 'depending', 'feedback');
af26e345
AG
48 $mform->addElement('text',
49 'dependvalue',
50 get_string('dependvalue', 'feedback'),
51 array('size'=>FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE, 'maxlength'=>255));
9c5bc7a5 52 } else {
5e97c34d
AG
53 $mform->addElement('hidden', 'dependitem', 0);
54 $mform->setType('dependitem', PARAM_INT);
55 $mform->addElement('hidden', 'dependvalue', '');
56 $mform->setType('dependitem', PARAM_ALPHA);
57 }
58
59 $position_select = $mform->addElement('select',
60 'position',
61 get_string('position', 'feedback').'&nbsp;',
62 $positionlist);
63 $position_select->setValue($position);
5e97c34d
AG
64
65 $mform->addElement('hidden', 'cmid', $common['cmid']);
66 $mform->setType('cmid', PARAM_INT);
9c5bc7a5 67
5e97c34d
AG
68 $mform->addElement('hidden', 'id', $common['id']);
69 $mform->setType('id', PARAM_INT);
9c5bc7a5 70
5e97c34d
AG
71 $mform->addElement('hidden', 'feedback', $common['feedback']);
72 $mform->setType('feedback', PARAM_INT);
9c5bc7a5 73
5e97c34d
AG
74 $mform->addElement('hidden', 'template', 0);
75 $mform->setType('template', PARAM_INT);
9c5bc7a5 76
5e97c34d
AG
77 $mform->setType('name', PARAM_RAW);
78 $mform->setType('label', PARAM_ALPHANUM);
9c5bc7a5 79
5e97c34d
AG
80 $mform->addElement('hidden', 'typ', $this->type);
81 $mform->setType('typ', PARAM_ALPHA);
82
83 $mform->addElement('hidden', 'hasvalue', 0);
84 $mform->setType('hasvalue', PARAM_INT);
85
86 $mform->addElement('hidden', 'options', '');
87 $mform->setType('options', PARAM_ALPHA);
88
89 $buttonarray = array();
9c5bc7a5
AG
90 if (!empty($item->id)) {
91 $buttonarray[] = &$mform->createElement('submit',
92 'update_item',
93 get_string('update_item', 'feedback'));
94
95 $buttonarray[] = &$mform->createElement('submit',
96 'clone_item',
97 get_string('save_as_new_item', 'feedback'));
98 } else {
cb416e50
AG
99 $mform->addElement('hidden', 'clone_item', 0);
100 $mform->setType('clone_item', PARAM_INT);
9c5bc7a5
AG
101 $buttonarray[] = &$mform->createElement('submit',
102 'save_item',
103 get_string('save_item', 'feedback'));
5e97c34d
AG
104 }
105 $buttonarray[] = &$mform->createElement('cancel');
106 $mform->addGroup($buttonarray, 'buttonar', '&nbsp;', array(' '), false);
9c5bc7a5 107
a627a9c1 108 }
109}
1adbd2c3 110