ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMatrixRowWizardInputGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
32{
33 protected $values = array();
34 protected $allowMove = false;
35 protected $show_wizard = false;
36 protected $show_save_phrase = false;
37 protected $categorytext;
38 protected $labeltext;
40
47 function __construct($a_title = "", $a_postvar = "")
48 {
49 parent::__construct($a_title, $a_postvar);
50 global $lng;
51 $this->show_wizard = false;
52 $this->show_save_phrase = false;
53 $this->categorytext = $lng->txt('row_text');
54 $this->use_other_answer = false;
55
56 $this->setMaxLength(1000); // #6803
57 }
58
59 public function getUseOtherAnswer()
60 {
62 }
63
64 public function setUseOtherAnswer($a_value)
65 {
66 $this->use_other_answer = ($a_value) ? true : false;
67 }
68
74 function setValue($a_value)
75 {
76 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
77 $this->values = new SurveyCategories();
78 if (is_array($a_value))
79 {
80 if (is_array($a_value['answer']))
81 {
82 foreach ($a_value['answer'] as $index => $value)
83 {
84 $this->values->addCategory($value, $a_value['other'][$index]);
85 }
86 }
87 }
88 }
89
95 function setValues($a_values)
96 {
97 $this->values = $a_values;
98 }
99
105 function getValues()
106 {
107 return $this->values;
108 }
109
115 function setAllowMove($a_allow_move)
116 {
117 $this->allowMove = $a_allow_move;
118 }
119
125 function getAllowMove()
126 {
127 return $this->allowMove;
128 }
129
130 function setShowWizard($a_value)
131 {
132 $this->show_wizard = $a_value;
133 }
134
135 function getShowWizard()
136 {
137 return $this->show_wizard;
138 }
139
140 public function setCategoryText($a_text)
141 {
142 $this->categorytext = $a_text;
143 }
144
145 public function getCategoryText()
146 {
147 return $this->categorytext;
148 }
149
150 public function setLabelText($a_text)
151 {
152 $this->labeltext = $a_text;
153 }
154
155 public function getLabelText()
156 {
157 return $this->labeltext;
158 }
159
160 function setShowSavePhrase($a_value)
161 {
162 $this->show_save_phrase = $a_value;
163 }
164
166 {
168 }
169
175 function checkInput()
176 {
177 global $lng;
178 if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
179 $foundvalues = $_POST[$this->getPostVar()];
180 if (is_array($foundvalues))
181 {
182 // check answers
183 if (is_array($foundvalues['answer']))
184 {
185 foreach ($foundvalues['answer'] as $idx => $answervalue)
186 {
187 if (((strlen($answervalue)) == 0) && ($this->getRequired() && (!$foundvalues['other'][$idx])))
188 {
189 $this->setAlert($lng->txt("msg_input_is_required"));
190 return FALSE;
191 }
192 }
193 }
194 }
195 else
196 {
197 $this->setAlert($lng->txt("msg_input_is_required"));
198 return FALSE;
199 }
200
201 return $this->checkSubItemsInput();
202 }
203
209 function insert(&$a_tpl)
210 {
211 global $lng;
212
213 $tpl = new ilTemplate("tpl.prop_matrixrowwizardinput.html", true, true, "Modules/SurveyQuestionPool");
214 $i = 0;
215 if (is_object($this->values))
216 {
217 for ($i = 0; $i < $this->values->getCategoryCount(); $i++)
218 {
219 $cat = $this->values->getCategory($i);
220 $tpl->setCurrentBlock("prop_text_propval");
221 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($cat->title));
222 $tpl->parseCurrentBlock();
223 $tpl->setCurrentBlock("prop_label_propval");
224 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($cat->label));
225 $tpl->parseCurrentBlock();
226
227 if ($this->getUseOtherAnswer())
228 {
229 $tpl->setCurrentBlock("other_answer_checkbox");
230 $tpl->setVariable("POST_VAR", $this->getPostVar());
231 $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
232 $tpl->setVariable("ROW_NUMBER", $i);
233 if ($cat->other)
234 {
235 $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
236 }
237 $tpl->parseCurrentBlock();
238 }
239
240 if ($this->getAllowMove())
241 {
242 $tpl->setCurrentBlock("move");
243 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
244 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
245 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
246 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
247 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
248 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
249 $tpl->parseCurrentBlock();
250 }
251
252 $tpl->setCurrentBlock("row");
253 $tpl->setVariable("POST_VAR", $this->getPostVar());
254 $tpl->setVariable("ROW_NUMBER", $i);
255 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
256 $tpl->setVariable("ID_LABEL", $this->getPostVar() . "[label][$i]");
257 $tpl->setVariable("SIZE", $this->getSize());
258 $tpl->setVariable("SIZE_LABEL", 15);
259 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
260 if ($this->getDisabled())
261 {
262 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
263 $tpl->setVariable("DISABLED_LABEL", " disabled=\"disabled\"");
264 }
265
266 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
267 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
268 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
269 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
270 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
271 $tpl->parseCurrentBlock();
272 }
273 }
274
275 if ($this->getShowWizard())
276 {
277 $tpl->setCurrentBlock("wizard");
278 $tpl->setVariable("CMD_WIZARD", 'cmd[wizard' . $this->getFieldId() . ']');
279 $tpl->setVariable("WIZARD_BUTTON", ilUtil::getImagePath('wizard.svg'));
280 $tpl->setVariable("WIZARD_TEXT", $lng->txt('add_phrase'));
281 $tpl->parseCurrentBlock();
282 }
283
284 if ($this->getShowSavePhrase())
285 {
286 $tpl->setCurrentBlock('savephrase');
287 $tpl->setVariable("POST_VAR", $this->getPostVar());
288 $tpl->setVariable("VALUE_SAVE_PHRASE", $lng->txt('save_phrase'));
289 $tpl->parseCurrentBlock();
290 }
291
292 if ($this->getUseOtherAnswer())
293 {
294 $tpl->setCurrentBlock('other_answer_title');
295 $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
296 $tpl->parseCurrentBlock();
297 }
298
299 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
300 $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
301 $tpl->setVariable("LABEL_TEXT", $this->getLabelText());
302 $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
303
304 $a_tpl->setCurrentBlock("prop_generic");
305 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
306 $a_tpl->parseCurrentBlock();
307
308 global $tpl;
309 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
310 $tpl->addJavascript("./Modules/SurveyQuestionPool/templates/default/matrixrowwizard.js");
311 }
312}
global $tpl
Definition: ilias.php:8
Class SurveyCategories.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a survey question category wizard property in a property form.
insert(&$a_tpl)
Insert property html.
setAllowMove($a_allow_move)
Set allow move.
checkInput()
Check input, strip slashes etc.
__construct($a_title="", $a_postvar="")
Constructor.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
setMaxLength($a_maxlength)
Set Max Length.
getMaxLength()
Get Max Length.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40