ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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;
39  protected $use_other_answer;
40 
47  function __construct($a_title = "", $a_postvar = "")
48  {
49  global $lng;
50 
51  parent::__construct($a_title, $a_postvar);
52 
53  $this->show_wizard = false;
54  $this->show_save_phrase = false;
55  $this->categorytext = $lng->txt('row_text');
56  $this->use_other_answer = false;
57 
58  $this->setMaxLength(1000); // #6803
59  }
60 
61  public function getUseOtherAnswer()
62  {
64  }
65 
66  public function setUseOtherAnswer($a_value)
67  {
68  $this->use_other_answer = ($a_value) ? true : false;
69  }
70 
76  function setValue($a_value)
77  {
78  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
79  $this->values = new SurveyCategories();
80  if (is_array($a_value))
81  {
82  if (is_array($a_value['answer']))
83  {
84  foreach ($a_value['answer'] as $index => $value)
85  {
86  $this->values->addCategory($value, $a_value['other'][$index]);
87  }
88  }
89  }
90  }
91 
97  function setValues($a_values)
98  {
99  $this->values = $a_values;
100  }
101 
107  function getValues()
108  {
109  return $this->values;
110  }
111 
117  function setAllowMove($a_allow_move)
118  {
119  $this->allowMove = $a_allow_move;
120  }
121 
127  function getAllowMove()
128  {
129  return $this->allowMove;
130  }
131 
132  function setShowWizard($a_value)
133  {
134  $this->show_wizard = $a_value;
135  }
136 
137  function getShowWizard()
138  {
139  return $this->show_wizard;
140  }
141 
142  public function setCategoryText($a_text)
143  {
144  $this->categorytext = $a_text;
145  }
146 
147  public function getCategoryText()
148  {
149  return $this->categorytext;
150  }
151 
152  public function setLabelText($a_text)
153  {
154  $this->labeltext = $a_text;
155  }
156 
157  public function getLabelText()
158  {
159  return $this->labeltext;
160  }
161 
162  function setShowSavePhrase($a_value)
163  {
164  $this->show_save_phrase = $a_value;
165  }
166 
167  function getShowSavePhrase()
168  {
170  }
171 
177  function checkInput()
178  {
179  global $lng;
180  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
181  $foundvalues = $_POST[$this->getPostVar()];
182  if (is_array($foundvalues))
183  {
184  // check answers
185  if (is_array($foundvalues['answer']))
186  {
187  foreach ($foundvalues['answer'] as $idx => $answervalue)
188  {
189  if (((strlen($answervalue)) == 0) && ($this->getRequired() && (!$foundvalues['other'][$idx])))
190  {
191  $this->setAlert($lng->txt("msg_input_is_required"));
192  return FALSE;
193  }
194  }
195  }
196  }
197  else
198  {
199  $this->setAlert($lng->txt("msg_input_is_required"));
200  return FALSE;
201  }
202 
203  return $this->checkSubItemsInput();
204  }
205 
211  function insert($a_tpl)
212  {
213  global $lng;
214 
215  $tpl = new ilTemplate("tpl.prop_matrixrowwizardinput.html", true, true, "Modules/SurveyQuestionPool");
216  $i = 0;
217  if (is_object($this->values))
218  {
219  for ($i = 0; $i < $this->values->getCategoryCount(); $i++)
220  {
221  $cat = $this->values->getCategory($i);
222  $tpl->setCurrentBlock("prop_text_propval");
223  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($cat->title));
224  $tpl->parseCurrentBlock();
225  $tpl->setCurrentBlock("prop_label_propval");
226  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($cat->label));
227  $tpl->parseCurrentBlock();
228 
229  if ($this->getUseOtherAnswer())
230  {
231  $tpl->setCurrentBlock("other_answer_checkbox");
232  $tpl->setVariable("POST_VAR", $this->getPostVar());
233  $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
234  $tpl->setVariable("ROW_NUMBER", $i);
235  if ($cat->other)
236  {
237  $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
238  }
239  $tpl->parseCurrentBlock();
240  }
241 
242  if ($this->getAllowMove())
243  {
244  $tpl->setCurrentBlock("move");
245  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
246  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
247  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
248  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
249  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
250  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
251  $tpl->parseCurrentBlock();
252  }
253 
254  $tpl->setCurrentBlock("row");
255  $tpl->setVariable("POST_VAR", $this->getPostVar());
256  $tpl->setVariable("ROW_NUMBER", $i);
257  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
258  $tpl->setVariable("ID_LABEL", $this->getPostVar() . "[label][$i]");
259  $tpl->setVariable("SIZE", $this->getSize());
260  $tpl->setVariable("SIZE_LABEL", 15);
261  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
262  if ($this->getDisabled())
263  {
264  $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
265  $tpl->setVariable("DISABLED_LABEL", " disabled=\"disabled\"");
266  }
267 
268  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
269  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
270  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
271  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
272  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
273  $tpl->parseCurrentBlock();
274  }
275  }
276 
277  if ($this->getShowWizard())
278  {
279  $tpl->setCurrentBlock("wizard");
280  $tpl->setVariable("CMD_WIZARD", 'cmd[wizard' . $this->getFieldId() . ']');
281  $tpl->setVariable("WIZARD_BUTTON", ilUtil::getImagePath('wizard.svg'));
282  $tpl->setVariable("WIZARD_TEXT", $lng->txt('add_phrase'));
283  $tpl->parseCurrentBlock();
284  }
285 
286  if ($this->getShowSavePhrase())
287  {
288  $tpl->setCurrentBlock('savephrase');
289  $tpl->setVariable("POST_VAR", $this->getPostVar());
290  $tpl->setVariable("VALUE_SAVE_PHRASE", $lng->txt('save_phrase'));
291  $tpl->parseCurrentBlock();
292  }
293 
294  if ($this->getUseOtherAnswer())
295  {
296  $tpl->setCurrentBlock('other_answer_title');
297  $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
298  $tpl->parseCurrentBlock();
299  }
300 
301  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
302  $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
303  $tpl->setVariable("LABEL_TEXT", $this->getLabelText());
304  $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
305 
306  $a_tpl->setCurrentBlock("prop_generic");
307  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
308  $a_tpl->parseCurrentBlock();
309 
310  global $tpl;
311  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
312  $tpl->addJavascript("./Modules/SurveyQuestionPool/templates/default/matrixrowwizard.js");
313  }
314 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
checkInput()
Check input, strip slashes etc.
getPostVar()
Get Post Variable.
insert($a_tpl)
Insert property html.
setAllowMove($a_allow_move)
Set allow move.
static get($a_glyph, $a_text="")
Get glyph html.
setAlert($a_alert)
Set Alert Text.
global $tpl
Definition: ilias.php:8
__construct($a_title="", $a_postvar="")
Constructor.
Class SurveyCategories.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
This class represents a text property in a property form.
setMaxLength($a_maxlength)
Set Max Length.
This class represents a survey question category wizard property in a property form.
Create styles array
The data for the language used.
global $lng
Definition: privfeed.php:17
$_POST["username"]