ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCategoryWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
25{
26 protected \ILIAS\Survey\InternalGUIService $gui;
28 protected ?SurveyCategories $values = null;
29 protected bool $allowMove = false;
30 protected bool $disabled_scale = true;
31 protected bool $show_wizard = false;
32 protected string $categorytext;
33 protected bool $show_neutral_category = false;
34 protected string $neutral_category_title;
35 protected bool $use_other_answer;
36
37 public function __construct(
38 string $a_title = "",
39 string $a_postvar = ""
40 ) {
41 global $DIC;
42
43 $this->lng = $DIC->language();
44 $this->tpl = $DIC["tpl"];
45 $lng = $DIC->language();
46
47 parent::__construct($a_title, $a_postvar);
48
49 $this->show_wizard = false;
50 $this->categorytext = $lng->txt('answer');
51 $this->use_other_answer = false;
52
53 $this->setMaxLength(1000); // #6218
54 $this->gui = $DIC->survey()->internal()->gui();
55 }
56
57 public function getUseOtherAnswer(): bool
58 {
60 }
61
62 public function setUseOtherAnswer(bool $a_value): void
63 {
64 $this->use_other_answer = $a_value;
65 }
66
67 public function getCategoryCount(): int
68 {
69 if (!is_object($this->values)) {
70 return 0;
71 }
72 return $this->values->getCategoryCount();
73 }
74
75 protected function calcNeutralCategoryScale(): int
76 {
77 if (is_object($this->values)) {
78 $scale = 0;
79 for ($i = 0; $i < $this->values->getCategoryCount(); $i++) {
80 $cat = $this->values->getCategory($i);
81 if ($cat->neutral == 0) {
82 $scale += 1;
83 }
84 }
85 return $scale + 1;
86 }
87
88 return 99;
89 }
90
91 public function setShowNeutralCategory(bool $a_value): void
92 {
93 $this->show_neutral_category = $a_value;
94 }
95
96 public function getShowNeutralCategory(): bool
97 {
99 }
100
101 public function setNeutralCategoryTitle(string $a_title): void
102 {
103 $this->neutral_category_title = $a_title;
104 }
105
106 public function getNeutralCategoryTitle(): string
107 {
109 }
110
114 public function setValue($a_value): void
115 {
116 $this->values = new SurveyCategories();
117 if (is_array($a_value)) {
118 if (is_array($a_value['answer'])) {
119 foreach ($a_value['answer'] as $index => $value) {
120 $this->values->addCategory(
121 $value,
122 $a_value['other'][$index] ?? 0,
123 0,
124 null,
125 isset($a_value['scale'][$index]) && (int) $a_value['scale'][$index] > 0
126 ? (int) $a_value['scale'][$index]
127 : null
128 );
129 }
130 }
131 }
132 if (array_key_exists('neutral', $a_value)) {
133 $scale = $this->str($this->postvar . '_neutral_scale');
134 $scale = ($scale === "")
135 ? null
136 : (int) $scale;
137 $this->values->addCategory(
138 $a_value['neutral'],
139 0,
140 1,
141 null,
142 $scale
143 );
144 }
145 }
146
147 public function setValues(SurveyCategories $a_values): void
148 {
149 $this->values = $a_values;
150 }
151
152 public function getValues(): SurveyCategories
153 {
154 return $this->values;
155 }
156
157 public function setAllowMove(bool $a_allow_move): void
158 {
159 $this->allowMove = $a_allow_move;
160 }
161
162 public function getAllowMove(): bool
163 {
164 return $this->allowMove;
165 }
166
167 public function setShowWizard(bool $a_value): void
168 {
169 $this->show_wizard = $a_value;
170 }
171
172 public function getShowWizard(): bool
173 {
174 return $this->show_wizard;
175 }
176
177 public function setCategoryText(string $a_text): void
178 {
179 $this->categorytext = $a_text;
180 }
181
182 public function getCategoryText(): string
183 {
184 return $this->categorytext;
185 }
186
187 public function getDisabledScale(): bool
188 {
190 }
191
192 public function setDisabledScale(bool $a_value): void
193 {
194 $this->disabled_scale = $a_value;
195 }
196
197 public function checkInput(): bool
198 {
200 $foundvalues = $this->getInput();
201 $neutral_scale = $this->getNeutralScaleInput();
202 $neutral = $this->getNeutralInput();
203
204 if (count($foundvalues) > 0) {
205 // check answers
206 if (is_array($foundvalues['answer'] ?? false)) {
207 foreach ($foundvalues['answer'] as $idx => $answervalue) {
208 if (((strlen($answervalue ?? "")) == 0) && ($this->getRequired() && (!isset($foundvalues['other'][$idx])))) {
209 $this->setAlert($lng->txt("msg_input_is_required"));
210 return false;
211 }
212 }
213 }
214 // check neutral column
215 /* see #33267
216 if (array_key_exists('neutral', $foundvalues)) {
217 if ((strlen($neutral) == 0) && ($this->getRequired())) {
218 $this->setAlert($lng->txt("msg_input_is_required"));
219 return false;
220 }
221 }*/
222 // check scales
223 if (isset($foundvalues['scale'])) {
224 foreach ($foundvalues['scale'] as $scale) {
225 //scales required
226 if ((strlen($scale ?? "")) == 0) {
227 $this->setAlert($lng->txt("msg_input_is_required"));
228 return false;
229 }
230 //scales positive number
231 if (!ctype_digit($scale) || $scale <= 0) {
232 $this->setAlert($lng->txt("msg_input_only_positive_numbers"));
233 return false;
234 }
235 }
236 //scales no duplicates.
237 if (count(array_unique($foundvalues['scale'])) !== count($foundvalues['scale'])) {
238 $this->setAlert($lng->txt("msg_duplicate_scale"));
239 return false;
240 }
241 }
242
243 // check neutral column scale
244 if ($neutral_scale != "") {
245 if (isset($foundvalues['scale'])) {
246 if (in_array($neutral_scale, $foundvalues['scale'])) {
247 $this->setAlert($lng->txt("msg_duplicate_scale"));
248 return false;
249 }
250 }
251 }
252 } else {
253 $this->setAlert($lng->txt("msg_input_is_required"));
254 return false;
255 }
256 return $this->checkSubItemsInput();
257 }
258
259 public function getInput(): array
260 {
261 $val = $this->arrayArray($this->getPostVar());
263 return $val;
264 }
265
266 public function getNeutralScaleInput(): string
267 {
268 return $this->str($this->getPostVar() . '_neutral_scale');
269 }
270
271 public function getNeutralInput(): string
272 {
273 $val = $this->strArray($this->getPostVar());
274 return $val["neutral"];
275 }
276
277 public function insert(
278 ilTemplate $a_tpl
279 ): void {
280 $lng = $this->lng;
281
282 $neutral_category = null;
283 $tpl = new ilTemplate("tpl.prop_categorywizardinput.html", true, true, "components/ILIAS/SurveyQuestionPool");
284 if (is_object($this->values)) {
285 for ($i = 0; $i < $this->values->getCategoryCount(); $i++) {
286 $cat = $this->values->getCategory($i);
287 if (!$cat->neutral) {
288 $tpl->setCurrentBlock("prop_text_propval");
289 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($cat->title));
291 $tpl->setCurrentBlock("prop_scale_propval");
293 "PROPERTY_VALUE",
294 ilLegacyFormElementsUtil::prepareFormOutput($this->values->getScale($i))
295 );
297
298 if ($this->getUseOtherAnswer()) {
299 $tpl->setCurrentBlock("other_answer_checkbox");
300 $tpl->setVariable("POST_VAR", $this->getPostVar());
301 $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
302 $tpl->setVariable("ROW_NUMBER", $i);
303 if ($cat->other) {
304 $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
305 }
307 }
308
309 if ($this->getAllowMove()) {
310 $tpl->setCurrentBlock("move");
311 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
312 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
313 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
314 $tpl->setVariable("UP_BUTTON", $this->gui->symbol()->glyph("up")->render());
315 $tpl->setVariable("DOWN_BUTTON", $this->gui->symbol()->glyph("down")->render());
317 }
318
319 $tpl->setCurrentBlock("row");
320 $tpl->setVariable("POST_VAR", $this->getPostVar());
321 $tpl->setVariable("ROW_NUMBER", $i);
322 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
323 $tpl->setVariable("SIZE", $this->getSize());
324 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
325 if ($this->getDisabled()) {
326 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
327 }
328
329 $tpl->setVariable("SCALE_ID", $this->getPostVar() . "[scale][$i]");
330 if ($this->getDisabledScale()) {
331 $tpl->setVariable("DISABLED_SCALE", " disabled=\"disabled\"");
332 }
333
334 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
335 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
336 $tpl->setVariable("ADD_BUTTON", $this->gui->symbol()->glyph("add")->render());
337 $tpl->setVariable("REMOVE_BUTTON", $this->gui->symbol()->glyph("remove")->render());
339 } else {
340 $neutral_category = $cat;
341 }
342 }
343 }
344
345
346 if ($this->getShowNeutralCategory()) {
347 if (is_object($neutral_category) && strlen($neutral_category->title ?? "")) {
348 $tpl->setCurrentBlock("prop_text_neutral_propval");
350 "PROPERTY_VALUE",
351 ilLegacyFormElementsUtil::prepareFormOutput($neutral_category->title)
352 );
354 }
355 if ($this->getNeutralCategoryTitle() !== '') {
356 $tpl->setCurrentBlock("neutral_category_title");
357 $tpl->setVariable("NEUTRAL_COLS", ($this->getUseOtherAnswer()) ? 4 : 3);
358 $tpl->setVariable(
359 "CATEGORY_TITLE",
361 );
362 $tpl->parseCurrentBlock();
363 }
364 $tpl->setCurrentBlock("prop_scale_neutral_propval");
365 $scale = (is_object($neutral_category) && $neutral_category->scale > 0) ? $neutral_category->scale : $this->values->getNewScale();
368
369 if ($this->getUseOtherAnswer()) {
370 $tpl->touchBlock('other_answer_neutral');
371 }
372
373 $tpl->setCurrentBlock('neutral_row');
374 $tpl->setVariable("POST_VAR", $this->getPostVar());
375 $tpl->setVariable("ID", $this->getPostVar() . "_neutral");
376 $tpl->setVariable("SIZE", $this->getSize());
377 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
378 if ($this->getDisabled()) {
379 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
380 }
381 $tpl->setVariable("SCALE_ID", $this->getPostVar() . "_neutral_scale");
382 if ($this->getDisabledScale()) {
383 $tpl->setVariable("DISABLED_SCALE", " disabled=\"disabled\"");
384 }
386 }
387
388 if ($this->getUseOtherAnswer()) {
389 $tpl->setCurrentBlock('other_answer_title');
390 $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
392 }
393
394 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
395 $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
396 $tpl->setVariable("SCALE_TEXT", $lng->txt('scale'));
397 $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
398
399 $a_tpl->setCurrentBlock("prop_generic");
400 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
401 $a_tpl->parseCurrentBlock();
402
404 $tpl->addJavaScript("assets/js/ServiceFormWizardInput.js");
405 $tpl->addJavaScript("assets/js/categorywizard.js");
406 }
407}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Survey InternalGUIService $gui
__construct(string $a_title="", string $a_postvar="")
checkInput()
Check input, strip slashes etc.
setValues(SurveyCategories $a_values)
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.
setMaxLength(?int $a_maxlength)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
touchBlock(string $block)
overwrites ITX::touchBlock.
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26