ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
57 public function getUseOtherAnswer()
58 {
60 }
61
62 public function setUseOtherAnswer($a_value)
63 {
64 $this->use_other_answer = ($a_value) ? true : false;
65 }
66
72 function setValue($a_value)
73 {
74 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
75 $this->values = new SurveyCategories();
76 if (is_array($a_value))
77 {
78 if (is_array($a_value['answer']))
79 {
80 foreach ($a_value['answer'] as $index => $value)
81 {
82 $this->values->addCategory($value, $a_value['other'][$index]);
83 }
84 }
85 }
86 }
87
93 function setValues($a_values)
94 {
95 $this->values = $a_values;
96 }
97
103 function getValues()
104 {
105 return $this->values;
106 }
107
113 function setAllowMove($a_allow_move)
114 {
115 $this->allowMove = $a_allow_move;
116 }
117
123 function getAllowMove()
124 {
125 return $this->allowMove;
126 }
127
128 function setShowWizard($a_value)
129 {
130 $this->show_wizard = $a_value;
131 }
132
133 function getShowWizard()
134 {
135 return $this->show_wizard;
136 }
137
138 public function setCategoryText($a_text)
139 {
140 $this->categorytext = $a_text;
141 }
142
143 public function getCategoryText()
144 {
145 return $this->categorytext;
146 }
147
148 public function setLabelText($a_text)
149 {
150 $this->labeltext = $a_text;
151 }
152
153 public function getLabelText()
154 {
155 return $this->labeltext;
156 }
157
158 function setShowSavePhrase($a_value)
159 {
160 $this->show_save_phrase = $a_value;
161 }
162
164 {
166 }
167
173 function checkInput()
174 {
175 global $lng;
176 if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
177 $foundvalues = $_POST[$this->getPostVar()];
178 if (is_array($foundvalues))
179 {
180 // check answers
181 if (is_array($foundvalues['answer']))
182 {
183 foreach ($foundvalues['answer'] as $idx => $answervalue)
184 {
185 if (((strlen($answervalue)) == 0) && ($this->getRequired() && (!$foundvalues['other'][$idx])))
186 {
187 $this->setAlert($lng->txt("msg_input_is_required"));
188 return FALSE;
189 }
190 }
191 }
192 }
193 else
194 {
195 $this->setAlert($lng->txt("msg_input_is_required"));
196 return FALSE;
197 }
198
199 return $this->checkSubItemsInput();
200 }
201
207 function insert(&$a_tpl)
208 {
209 global $lng;
210
211 $tpl = new ilTemplate("tpl.prop_matrixrowwizardinput.html", true, true, "Modules/SurveyQuestionPool");
212 $i = 0;
213 if (is_object($this->values))
214 {
215 for ($i = 0; $i < $this->values->getCategoryCount(); $i++)
216 {
217 $cat = $this->values->getCategory($i);
218 $tpl->setCurrentBlock("prop_text_propval");
219 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($cat->title));
220 $tpl->parseCurrentBlock();
221 $tpl->setCurrentBlock("prop_label_propval");
222 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($cat->label));
223 $tpl->parseCurrentBlock();
224
225 if ($this->getUseOtherAnswer())
226 {
227 $tpl->setCurrentBlock("other_answer_checkbox");
228 $tpl->setVariable("POST_VAR", $this->getPostVar());
229 $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
230 $tpl->setVariable("ROW_NUMBER", $i);
231 if ($cat->other)
232 {
233 $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
234 }
235 $tpl->parseCurrentBlock();
236 }
237
238 if ($this->getAllowMove())
239 {
240 $tpl->setCurrentBlock("move");
241 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
242 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
243 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
244 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
245 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
246 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
247 $tpl->parseCurrentBlock();
248 }
249
250 $tpl->setCurrentBlock("row");
251 $tpl->setVariable("POST_VAR", $this->getPostVar());
252 $tpl->setVariable("ROW_NUMBER", $i);
253 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
254 $tpl->setVariable("ID_LABEL", $this->getPostVar() . "[label][$i]");
255 $tpl->setVariable("SIZE", $this->getSize());
256 $tpl->setVariable("SIZE_LABEL", 15);
257 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
258 if ($this->getDisabled())
259 {
260 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
261 $tpl->setVariable("DISABLED_LABEL", " disabled=\"disabled\"");
262 }
263
264 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
265 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
266 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
267 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
268 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
269 $tpl->parseCurrentBlock();
270 }
271 }
272
273 if ($this->getShowWizard())
274 {
275 $tpl->setCurrentBlock("wizard");
276 $tpl->setVariable("CMD_WIZARD", 'cmd[wizard' . $this->getFieldId() . ']');
277 $tpl->setVariable("WIZARD_BUTTON", ilUtil::getImagePath('wizard.svg'));
278 $tpl->setVariable("WIZARD_TEXT", $lng->txt('add_phrase'));
279 $tpl->parseCurrentBlock();
280 }
281
282 if ($this->getShowSavePhrase())
283 {
284 $tpl->setCurrentBlock('savephrase');
285 $tpl->setVariable("POST_VAR", $this->getPostVar());
286 $tpl->setVariable("VALUE_SAVE_PHRASE", $lng->txt('save_phrase'));
287 $tpl->parseCurrentBlock();
288 }
289
290 if ($this->getUseOtherAnswer())
291 {
292 $tpl->setCurrentBlock('other_answer_title');
293 $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
294 $tpl->parseCurrentBlock();
295 }
296
297 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
298 $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
299 $tpl->setVariable("LABEL_TEXT", $this->getLabelText());
300 $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
301
302 $a_tpl->setCurrentBlock("prop_generic");
303 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
304 $a_tpl->parseCurrentBlock();
305
306 global $tpl;
307 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
308 $tpl->addJavascript("./Modules/SurveyQuestionPool/templates/default/matrixrowwizard.js");
309 }
310}
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.
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