ILIAS  release_8 Revision v8.24
class.ilAnswerWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
27{
28 protected $values = array();
29 protected $allowMove = false;
30 protected $allowAddRemove = true;
31 protected $singleline = true;
32 protected $qstObject = null;
33 protected $minvalue = false;
34 protected $minvalueShouldBeGreater = false;
35
42 public function __construct($a_title = "", $a_postvar = "")
43 {
44 parent::__construct($a_title, $a_postvar);
45 $this->setSize('25');
46 $this->validationRegexp = "";
47 }
48
49 public function setValue($a_value): void
50 {
51 $this->values = array();
52 if (is_array($a_value)) {
53 if (is_array($a_value['answer'])) {
54 foreach ($a_value['answer'] as $index => $value) {
55 $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, -1);
56 if (isset($a_value['imagename'][$index])) {
57 $answer->setImage($a_value['imagename'][$index]);
58 }
59 array_push($this->values, $answer);
60 }
61 }
62 }
63 }
64
70 public function setValues($a_values): void
71 {
72 $this->values = $a_values;
73 }
74
80 public function getValues(): array
81 {
82 return $this->values;
83 }
84
90 public function setSingleline($a_value): void
91 {
92 $this->singleline = $a_value;
93 }
94
100 public function getSingleline(): bool
101 {
102 return $this->singleline;
103 }
104
110 public function setQuestionObject($a_value): void
111 {
112 $this->qstObject = &$a_value;
113 }
114
120 public function getQuestionObject(): ?object
121 {
122 return $this->qstObject;
123 }
124
130 public function setAllowMove($a_allow_move): void
131 {
132 $this->allowMove = $a_allow_move;
133 }
134
140 public function getAllowMove(): bool
141 {
142 return $this->allowMove;
143 }
144
148 public function isAddRemoveAllowed(): bool
149 {
151 }
152
156 public function setAllowAddRemove($allowAddRemove): void
157 {
158 $this->allowAddRemove = $allowAddRemove;
159 }
160
166 public function setMinvalueShouldBeGreater($a_bool): void
167 {
168 $this->minvalueShouldBeGreater = $a_bool;
169 }
170
176 public function minvalueShouldBeGreater(): bool
177 {
179 }
185 public function setMinValue($a_minvalue): void
186 {
187 $this->minvalue = $a_minvalue;
188 }
189
195 public function getMinValue()
196 {
197 return $this->minvalue;
198 }
203 public function checkInput(): bool
204 {
205 global $DIC;
206 $lng = $DIC['lng'];
207
208 $foundvalues = $_POST[$this->getPostVar()];
209 if (is_array($foundvalues)) {
210 $foundvalues = ilArrayUtil::stripSlashesRecursive($foundvalues);
211 // check answers
212 if (is_array($foundvalues['answer'])) {
213 foreach ($foundvalues['answer'] as $aidx => $answervalue) {
214 if ((strlen($answervalue)) == 0) {
215 $this->setAlert($lng->txt("msg_input_is_required"));
216 return false;
217 }
218 }
219 }
220 // check points
221 $max = 0;
222 if (is_array($foundvalues['points'])) {
223 foreach ($foundvalues['points'] as $points) {
224 if ($points > $max) {
225 $max = $points;
226 }
227 if (((strlen($points)) == 0) || (!is_numeric($points))) {
228 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
229 return false;
230 }
231 if ($this->minvalueShouldBeGreater()) {
232 if (trim($points) != "" &&
233 $this->getMinValue() !== false &&
234 $points <= $this->getMinValue()) {
235 $this->setAlert($lng->txt("form_msg_value_too_low"));
236
237 return false;
238 }
239 } else {
240 if (trim($points) != "" &&
241 $this->getMinValue() !== false &&
242 $points < $this->getMinValue()) {
243 $this->setAlert($lng->txt("form_msg_value_too_low"));
244
245 return false;
246 }
247 }
248 }
249 }
250 if ($max == 0) {
251 $this->setAlert($lng->txt("enter_enough_positive_points"));
252 return false;
253 }
254 } else {
255 $this->setAlert($lng->txt("msg_input_is_required"));
256 return false;
257 }
258
259 return $this->checkSubItemsInput();
260 }
261
262 public function insert(ilTemplate $a_tpl): void
263 {
264 global $DIC;
265 $lng = $DIC['lng'];
266
267 $tpl = new ilTemplate($this->getTemplate(), true, true, "Modules/TestQuestionPool");
268 $i = 0;
269 foreach ($this->values as $value) {
270 if ($this->getSingleline()) {
271 if (is_object($value)) {
272 $tpl->setCurrentBlock("prop_text_propval");
273 $tpl->setVariable(
274 "PROPERTY_VALUE",
276 );
277 $tpl->parseCurrentBlock();
278 $tpl->setCurrentBlock("prop_points_propval");
279 $tpl->setVariable(
280 "PROPERTY_VALUE",
282 );
283 $tpl->parseCurrentBlock();
284 }
285 $tpl->setCurrentBlock('singleline');
286 $tpl->setVariable("SIZE", $this->getSize());
287 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
288 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
289 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
290 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
291 if ($this->getDisabled()) {
292 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
293 }
294 $tpl->parseCurrentBlock();
295 } elseif (!$this->getSingleline()) {
296 if (is_object($value)) {
297 $tpl->setCurrentBlock("prop_points_propval");
298 $tpl->setVariable(
299 "PROPERTY_VALUE",
301 );
302 $tpl->parseCurrentBlock();
303 }
304 $tpl->setCurrentBlock('multiline');
305 $tpl->setVariable("PROPERTY_VALUE", $this->qstObject->prepareTextareaOutput($value->getAnswertext()));
306 $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
307 $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
308 $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
309 if ($this->getDisabled()) {
310 $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
311 }
312 $tpl->parseCurrentBlock();
313 }
314 if ($this->getAllowMove()) {
315 $tpl->setCurrentBlock("move");
316 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
317 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
318 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
319 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
320 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
321 $tpl->parseCurrentBlock();
322 }
323 $tpl->setCurrentBlock("row");
324 $tpl->setVariable("POST_VAR", $this->getPostVar());
325 $tpl->setVariable("ROW_NUMBER", $i);
326 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
327 $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
328 if ($this->isAddRemoveAllowed()) {
329 $tpl->setVariable("ADD_REMOVE_ID", $this->getPostVar() . "[$i]");
330 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
331 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
332 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
333 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
334 }
335 if ($this->getDisabled()) {
336 $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
337 }
338 $tpl->parseCurrentBlock();
339 $i++;
340 }
341
342 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
343 $tpl->setVariable("ANSWER_TEXT", $this->getTextInputLabel($lng));
344 $tpl->setVariable("POINTS_TEXT", $this->getPointsInputLabel($lng));
345 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
346
347 $a_tpl->setCurrentBlock("prop_generic");
348 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
349 $a_tpl->parseCurrentBlock();
350
351 global $DIC;
352 $tpl = $DIC['tpl'];
353 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
354 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/answerwizard.js");
355 }
356
361 protected function getTextInputLabel($lng)
362 {
363 return $lng->txt('answer_text');
364 }
365
370 protected function getPointsInputLabel($lng)
371 {
372 return $lng->txt('points');
373 }
374
378 protected function getTemplate(): string
379 {
380 return "tpl.prop_answerwizardinput.html";
381 }
382}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getQuestionObject()
Get question object.
checkInput()
Check input, strip slashes etc.
setMinvalueShouldBeGreater($a_bool)
Set minvalueShouldBeGreater.
setAllowMove($a_allow_move)
Set allow move.
minvalueShouldBeGreater()
Get minvalueShouldBeGreater.
__construct($a_title="", $a_postvar="")
Constructor.
setSingleline($a_value)
Set singleline.
setMinValue($a_minvalue)
Set Minimum Value.
setQuestionObject($a_value)
Set question object.
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
static get(string $a_glyph, string $a_text="")
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static prepareFormOutput($a_str, bool $a_strip=false)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a text property in a property form.
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$index
Definition: metadata.php:145
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc