Merge branch 'MDL-27675_master' of git://github.com/grabs/moodle
[moodle.git] / mod / feedback / item / multichoice / multichoice_form.php
CommitLineData
6ee09cfe 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/>.
6ee09cfe 16
a627a9c1 17require_once($CFG->dirroot.'/mod/feedback/item/feedback_item_form_class.php');
6ee09cfe 18
a627a9c1 19class feedback_multichoice_form extends feedback_item_form {
9c5bc7a5 20 protected $type = "multichoice";
1adbd2c3 21
9c5bc7a5 22 public function definition() {
a59ff6b0
AG
23 $item = $this->_customdata['item'];
24 $common = $this->_customdata['common'];
25 $positionlist = $this->_customdata['positionlist'];
26 $position = $this->_customdata['position'];
27
6ee09cfe 28 $mform =& $this->_form;
1adbd2c3 29
6ee09cfe 30 $mform->addElement('header', 'general', get_string($this->type, 'feedback'));
1adbd2c3 31
a59ff6b0 32 $mform->addElement('checkbox', 'required', get_string('required', 'feedback'));
1adbd2c3 33
af26e345
AG
34 $mform->addElement('text',
35 'name',
36 get_string('item_name', 'feedback'),
9c5bc7a5
AG
37 array('size' => FEEDBACK_ITEM_NAME_TEXTBOX_SIZE,
38 'maxlength' => 255));
39
af26e345
AG
40 $mform->addElement('text',
41 'label',
42 get_string('item_label', 'feedback'),
9c5bc7a5
AG
43 array('size' => FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE,
44 'maxlength' => 255));
6ee09cfe 45
a59ff6b0
AG
46 $mform->addElement('select',
47 'horizontal',
48 get_string('adjustment', 'feedback').'&nbsp;',
9c5bc7a5
AG
49 array(0 => get_string('vertical', 'feedback'),
50 1 => get_string('horizontal', 'feedback')));
1adbd2c3 51
a59ff6b0
AG
52 $mform->addElement('select',
53 'subtype',
54 get_string('multichoicetype', 'feedback').'&nbsp;',
55 array('r'=>get_string('radio', 'feedback'),
56 'c'=>get_string('check', 'feedback'),
57 'd'=>get_string('dropdown', 'feedback')));
6ee09cfe 58
9c5bc7a5
AG
59 $mform->addElement('selectyesno',
60 'ignoreempty',
61 get_string('do_not_analyse_empty_submits', 'feedback'));
62
63 $mform->addElement('selectyesno',
64 'hidenoselect',
65 get_string('hide_no_select_option', 'feedback'));
66
67 $mform->addElement('static',
68 'hint',
69 get_string('multichoice_values', 'feedback'),
70 get_string('use_one_line_for_each_value', 'feedback'));
1adbd2c3 71
a59ff6b0 72 $mform->addElement('textarea', 'values', '', 'wrap="virtual" rows="10" cols="65"');
6ee09cfe 73
5e97c34d 74 parent::definition();
a59ff6b0
AG
75 $this->set_data($item);
76
77 }
9c5bc7a5
AG
78
79 public function set_data($item) {
a59ff6b0
AG
80 $info = $this->_customdata['info'];
81
82 $item->horizontal = $info->horizontal;
51859310 83
a59ff6b0
AG
84 $item->subtype = $info->subtype;
85
86 $itemvalues = str_replace(FEEDBACK_MULTICHOICE_LINE_SEP, "\n", $info->presentation);
87 $itemvalues = str_replace("\n\n", "\n", $itemvalues);
88 $item->values = $itemvalues;
9c5bc7a5
AG
89
90 return parent::set_data($item);
a59ff6b0 91 }
9c5bc7a5
AG
92
93 public function get_data() {
94 if (!$item = parent::get_data()) {
a59ff6b0
AG
95 return false;
96 }
9c5bc7a5 97
a59ff6b0 98 $presentation = str_replace("\n", FEEDBACK_MULTICHOICE_LINE_SEP, trim($item->values));
9c5bc7a5 99 if (!isset($item->subtype)) {
a59ff6b0 100 $subtype = 'r';
9c5bc7a5 101 } else {
a59ff6b0
AG
102 $subtype = substr($item->subtype, 0, 1);
103 }
9c5bc7a5 104 if (isset($item->horizontal) AND $item->horizontal == 1 AND $subtype != 'd') {
a59ff6b0
AG
105 $presentation .= FEEDBACK_MULTICHOICE_ADJUST_SEP.'1';
106 }
9c5bc7a5 107
a59ff6b0
AG
108 $item->presentation = $subtype.FEEDBACK_MULTICHOICE_TYPE_SEP.$presentation;
109 return $item;
6ee09cfe 110 }
111}