ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
36  protected $tpl;
37 
38  protected $values = array();
39  protected $allowMove = false;
40  protected $show_wizard = false;
41  protected $show_save_phrase = false;
42  protected $categorytext;
43  protected $labeltext;
44  protected $use_other_answer;
45 
52  public function __construct($a_title = "", $a_postvar = "")
53  {
54  global $DIC;
55 
56  $this->lng = $DIC->language();
57  $this->tpl = $DIC["tpl"];
58  $lng = $DIC->language();
59 
60  parent::__construct($a_title, $a_postvar);
61 
62  $this->show_wizard = false;
63  $this->show_save_phrase = false;
64  $this->categorytext = $lng->txt('row_text');
65  $this->use_other_answer = false;
66 
67  $this->setMaxLength(1000); // #6803
68  }
69 
70  public function getUseOtherAnswer()
71  {
73  }
74 
75  public function setUseOtherAnswer($a_value)
76  {
77  $this->use_other_answer = ($a_value) ? true : false;
78  }
79 
85  public function setValue($a_value)
86  {
87  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
88  $this->values = new SurveyCategories();
89  if (is_array($a_value)) {
90  if (is_array($a_value['answer'])) {
91  foreach ($a_value['answer'] as $index => $value) {
92  $this->values->addCategory($value, $a_value['other'][$index]);
93  }
94  }
95  }
96  }
97 
103  public function setValues($a_values)
104  {
105  $this->values = $a_values;
106  }
107 
113  public function getValues()
114  {
115  return $this->values;
116  }
117 
123  public function setAllowMove($a_allow_move)
124  {
125  $this->allowMove = $a_allow_move;
126  }
127 
133  public function getAllowMove()
134  {
135  return $this->allowMove;
136  }
137 
138  public function setShowWizard($a_value)
139  {
140  $this->show_wizard = $a_value;
141  }
142 
143  public function getShowWizard()
144  {
145  return $this->show_wizard;
146  }
147 
148  public function setCategoryText($a_text)
149  {
150  $this->categorytext = $a_text;
151  }
152 
153  public function getCategoryText()
154  {
155  return $this->categorytext;
156  }
157 
158  public function setLabelText($a_text)
159  {
160  $this->labeltext = $a_text;
161  }
162 
163  public function getLabelText()
164  {
165  return $this->labeltext;
166  }
167 
168  public function setShowSavePhrase($a_value)
169  {
170  $this->show_save_phrase = $a_value;
171  }
172 
173  public function getShowSavePhrase()
174  {
176  }
177 
183  public function checkInput()
184  {
185  $lng = $this->lng;
186  if (is_array($_POST[$this->getPostVar()])) {
188  }
189  $foundvalues = $_POST[$this->getPostVar()];
190  if (is_array($foundvalues)) {
191  // check answers
192  if (is_array($foundvalues['answer'])) {
193  foreach ($foundvalues['answer'] as $idx => $answervalue) {
194  if (((strlen($answervalue)) == 0) && ($this->getRequired() && (!$foundvalues['other'][$idx]))) {
195  $this->setAlert($lng->txt("msg_input_is_required"));
196  return false;
197  }
198  }
199  }
200  } else {
201  $this->setAlert($lng->txt("msg_input_is_required"));
202  return false;
203  }
204 
205  return $this->checkSubItemsInput();
206  }
207 
213  public function insert($a_tpl)
214  {
215  $lng = $this->lng;
216 
217  $tpl = new ilTemplate("tpl.prop_matrixrowwizardinput.html", true, true, "Modules/SurveyQuestionPool");
218  $i = 0;
219  if (is_object($this->values)) {
220  for ($i = 0; $i < $this->values->getCategoryCount(); $i++) {
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  $tpl->setCurrentBlock("other_answer_checkbox");
231  $tpl->setVariable("POST_VAR", $this->getPostVar());
232  $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
233  $tpl->setVariable("ROW_NUMBER", $i);
234  if ($cat->other) {
235  $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
236  }
237  $tpl->parseCurrentBlock();
238  }
239 
240  if ($this->getAllowMove()) {
241  $tpl->setCurrentBlock("move");
242  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
243  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
244  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
245  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
246  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
247  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
248  $tpl->parseCurrentBlock();
249  }
250 
251  $tpl->setCurrentBlock("row");
252  $tpl->setVariable("POST_VAR", $this->getPostVar());
253  $tpl->setVariable("ROW_NUMBER", $i);
254  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
255  $tpl->setVariable("ID_LABEL", $this->getPostVar() . "[label][$i]");
256  $tpl->setVariable("SIZE", $this->getSize());
257  $tpl->setVariable("SIZE_LABEL", 15);
258  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
259  if ($this->getDisabled()) {
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  $tpl->setCurrentBlock("wizard");
275  $tpl->setVariable("CMD_WIZARD", 'cmd[wizard' . $this->getFieldId() . ']');
276  $tpl->setVariable("WIZARD_BUTTON", ilUtil::getImagePath('wizard.svg'));
277  $tpl->setVariable("WIZARD_TEXT", $lng->txt('add_phrase'));
278  $tpl->parseCurrentBlock();
279  }
280 
281  if ($this->getShowSavePhrase()) {
282  $tpl->setCurrentBlock('savephrase');
283  $tpl->setVariable("POST_VAR", $this->getPostVar());
284  $tpl->setVariable("VALUE_SAVE_PHRASE", $lng->txt('save_phrase'));
285  $tpl->parseCurrentBlock();
286  }
287 
288  if ($this->getUseOtherAnswer()) {
289  $tpl->setCurrentBlock('other_answer_title');
290  $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
291  $tpl->parseCurrentBlock();
292  }
293 
294  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
295  $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
296  $tpl->setVariable("LABEL_TEXT", $this->getLabelText());
297  $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
298 
299  $a_tpl->setCurrentBlock("prop_generic");
300  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
301  $a_tpl->parseCurrentBlock();
302 
303  $tpl = $this->tpl;
304  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
305  $tpl->addJavascript("./Modules/SurveyQuestionPool/templates/default/matrixrowwizard.js");
306  }
307 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
global $DIC
Definition: saml.php:7
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.
$index
Definition: metadata.php:60
setAlert($a_alert)
Set Alert Text.
__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.
$i
Definition: disco.tpl.php:19
$_POST["username"]