ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  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 
163  function getShowSavePhrase()
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  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.png'));
245  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.png'));
246  $tpl->parseCurrentBlock();
247  }
248  $tpl->setCurrentBlock("row");
249  $class = ($i % 2 == 0) ? "even" : "odd";
250  if ($i == 0) $class .= " first";
251  if ($i == $this->values->getCategoryCount()-1) $class .= " last";
252  $tpl->setVariable("ROW_CLASS", $class);
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  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
269  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
270  $tpl->parseCurrentBlock();
271  }
272  }
273 
274  if ($this->getShowWizard())
275  {
276  $tpl->setCurrentBlock("wizard");
277  $tpl->setVariable("CMD_WIZARD", 'cmd[wizard' . $this->getFieldId() . ']');
278  $tpl->setVariable("WIZARD_BUTTON", ilUtil::getImagePath('wizard.png'));
279  $tpl->setVariable("WIZARD_TEXT", $lng->txt('add_phrase'));
280  $tpl->parseCurrentBlock();
281  }
282 
283  if ($this->getShowSavePhrase())
284  {
285  $tpl->setCurrentBlock('savephrase');
286  $tpl->setVariable("POST_VAR", $this->getPostVar());
287  $tpl->setVariable("VALUE_SAVE_PHRASE", $lng->txt('save_phrase'));
288  $tpl->parseCurrentBlock();
289  }
290 
291  if ($this->getUseOtherAnswer())
292  {
293  $tpl->setCurrentBlock('other_answer_title');
294  $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
295  $tpl->parseCurrentBlock();
296  }
297 
298  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
299  $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
300  $tpl->setVariable("LABEL_TEXT", $this->getLabelText());
301  $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
302 
303  $a_tpl->setCurrentBlock("prop_generic");
304  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
305  $a_tpl->parseCurrentBlock();
306 
307  global $tpl;
308  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
310  $tpl->addJavascript("./Modules/SurveyQuestionPool/templates/default/matrixrowwizard.js");
311  }
312 }