ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMatrixRowWizardInputGUI.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 $show_wizard = false;
31 protected string $categorytext;
32 protected string $labeltext;
33 protected bool $use_other_answer;
34
35 public function __construct(
36 string $a_title = "",
37 string $a_postvar = ""
38 ) {
39 global $DIC;
40
41 $this->lng = $DIC->language();
42 $this->tpl = $DIC["tpl"];
43 $lng = $DIC->language();
44
45 parent::__construct($a_title, $a_postvar);
46
47 $this->show_wizard = false;
48 $this->categorytext = $lng->txt('row_text');
49 $this->use_other_answer = false;
50
51 $this->setMaxLength(1000); // #6803
52 $this->gui = $DIC->survey()->internal()->gui();
53 }
54
55 public function getUseOtherAnswer(): bool
56 {
58 }
59
60 public function setUseOtherAnswer(bool $a_value): void
61 {
62 $this->use_other_answer = $a_value;
63 }
64
68 public function setValue($a_value): void
69 {
70 $this->values = new SurveyCategories();
71 if (is_array($a_value) && is_array($a_value['answer'])) {
72 foreach ($a_value['answer'] as $index => $value) {
73 $this->values->addCategory($value, $a_value['other'][$index] ?? 0);
74 }
75 }
76 }
77
78 public function setValues(SurveyCategories $a_values): void
79 {
80 $this->values = $a_values;
81 }
82
83 public function getValues(): SurveyCategories
84 {
85 return $this->values;
86 }
87
88 public function setAllowMove(bool $a_allow_move): void
89 {
90 $this->allowMove = $a_allow_move;
91 }
92
93 public function getAllowMove(): bool
94 {
95 return $this->allowMove;
96 }
97
98 public function setShowWizard(bool $a_value): void
99 {
100 $this->show_wizard = $a_value;
101 }
102
103 public function getShowWizard(): bool
104 {
105 return $this->show_wizard;
106 }
107
108 public function setCategoryText(string $a_text): void
109 {
110 $this->categorytext = $a_text;
111 }
112
113 public function getCategoryText(): string
114 {
115 return $this->categorytext;
116 }
117
118 public function setLabelText(string $a_text): void
119 {
120 $this->labeltext = $a_text;
121 }
122
123 public function getLabelText(): string
124 {
125 return $this->labeltext;
126 }
127
128
129 public function checkInput(): bool
130 {
132 $foundvalues = $this->getInput();
133 if (count($foundvalues) > 0) {
134 // check answers
135 if (is_array($foundvalues['answer'])) {
136 foreach ($foundvalues['answer'] as $idx => $answervalue) {
137 if (((strlen($answervalue ?? "")) == 0) && ($this->getRequired() && (!$foundvalues['other'][$idx]))) {
138 $this->setAlert($lng->txt("msg_input_is_required"));
139 return false;
140 }
141 }
142 }
143 } else {
144 $this->setAlert($lng->txt("msg_input_is_required"));
145 return false;
146 }
147
148 return $this->checkSubItemsInput();
149 }
150
151 public function getInput(): array
152 {
153 $val = $this->arrayArray($this->getPostVar());
155 return $val;
156 }
157
158 public function insert(ilTemplate $a_tpl): void
159 {
161
162 $tpl = new ilTemplate("tpl.prop_matrixrowwizardinput.html", true, true, "components/ILIAS/SurveyQuestionPool");
163 if (is_object($this->values)) {
164 for ($i = 0; $i < $this->values->getCategoryCount(); $i++) {
165 $cat = $this->values->getCategory($i);
166 $tpl->setCurrentBlock("prop_text_propval");
167 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput((string) $cat->title));
169 $tpl->setCurrentBlock("prop_label_propval");
170 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput((string) $cat->label));
172
173 if ($this->getUseOtherAnswer()) {
174 $tpl->setCurrentBlock("other_answer_checkbox");
175 $tpl->setVariable("POST_VAR", $this->getPostVar());
176 $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
177 $tpl->setVariable("ROW_NUMBER", $i);
178 if ($cat->other) {
179 $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
180 }
182 }
183
184 if ($this->getAllowMove()) {
185 $tpl->setCurrentBlock("move");
186 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
187 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
188 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
189 $tpl->setVariable("UP_BUTTON", $this->gui->symbol()->glyph("up")->render());
190 $tpl->setVariable("DOWN_BUTTON", $this->gui->symbol()->glyph("down")->render());
192 }
193
194 $tpl->setCurrentBlock("row");
195 $tpl->setVariable("POST_VAR", $this->getPostVar());
196 $tpl->setVariable("ROW_NUMBER", $i);
197 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
198 $tpl->setVariable("ID_LABEL", $this->getPostVar() . "[label][$i]");
199 $tpl->setVariable("SIZE", $this->getSize());
200 $tpl->setVariable("SIZE_LABEL", 15);
201 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
202 if ($this->getDisabled()) {
203 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
204 $tpl->setVariable("DISABLED_LABEL", " disabled=\"disabled\"");
205 }
206
207 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
208 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
209 $tpl->setVariable("ADD_BUTTON", $this->gui->symbol()->glyph("add")->render());
210 $tpl->setVariable("REMOVE_BUTTON", $this->gui->symbol()->glyph("remove")->render());
212 }
213 }
214
215 if ($this->getUseOtherAnswer()) {
216 $tpl->setCurrentBlock('other_answer_title');
217 $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
219 }
220
221 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
222 $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
223 $tpl->setVariable("LABEL_TEXT", $this->getLabelText());
224 $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
225
226 $a_tpl->setCurrentBlock("prop_generic");
227 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
228 $a_tpl->parseCurrentBlock();
229
231 $tpl->addJavaScript("assets/js/ServiceFormWizardInput.js");
232 $tpl->addJavaScript("assets/js/matrixrowwizard.js");
233 }
234}
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="")
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(string $a_title="", string $a_postvar="")
checkInput()
Check input, strip slashes etc.
setValues(SurveyCategories $a_values)
ILIAS Survey InternalGUIService $gui
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.
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