ILIAS  release_8 Revision v8.24
class.ilMatrixRowWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
25{
27 protected ?SurveyCategories $values = null;
28 protected bool $allowMove = false;
29 protected bool $show_wizard = false;
30 protected bool $show_save_phrase = 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->show_save_phrase = false;
49 $this->categorytext = $lng->txt('row_text');
50 $this->use_other_answer = false;
51
52 $this->setMaxLength(1000); // #6803
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 public function setShowSavePhrase(bool $a_value): void
129 {
130 $this->show_save_phrase = $a_value;
131 }
132
133 public function getShowSavePhrase(): bool
134 {
136 }
137
138 public function checkInput(): bool
139 {
141 $foundvalues = $this->getInput();
142 if (count($foundvalues) > 0) {
143 // check answers
144 if (is_array($foundvalues['answer'])) {
145 foreach ($foundvalues['answer'] as $idx => $answervalue) {
146 if (((strlen($answervalue)) == 0) && ($this->getRequired() && (!$foundvalues['other'][$idx]))) {
147 $this->setAlert($lng->txt("msg_input_is_required"));
148 return false;
149 }
150 }
151 }
152 } else {
153 $this->setAlert($lng->txt("msg_input_is_required"));
154 return false;
155 }
156
157 return $this->checkSubItemsInput();
158 }
159
160 public function getInput(): array
161 {
162 $val = $this->arrayArray($this->getPostVar());
164 return $val;
165 }
166
167 public function insert(ilTemplate $a_tpl): void
168 {
170
171 $tpl = new ilTemplate("tpl.prop_matrixrowwizardinput.html", true, true, "Modules/SurveyQuestionPool");
172 if (is_object($this->values)) {
173 for ($i = 0; $i < $this->values->getCategoryCount(); $i++) {
174 $cat = $this->values->getCategory($i);
175 $tpl->setCurrentBlock("prop_text_propval");
176 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput((string) $cat->title));
178 $tpl->setCurrentBlock("prop_label_propval");
179 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput((string) $cat->label));
181
182 if ($this->getUseOtherAnswer()) {
183 $tpl->setCurrentBlock("other_answer_checkbox");
184 $tpl->setVariable("POST_VAR", $this->getPostVar());
185 $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
186 $tpl->setVariable("ROW_NUMBER", $i);
187 if ($cat->other) {
188 $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
189 }
191 }
192
193 if ($this->getAllowMove()) {
194 $tpl->setCurrentBlock("move");
195 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
196 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
197 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
198 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
201 }
202
203 $tpl->setCurrentBlock("row");
204 $tpl->setVariable("POST_VAR", $this->getPostVar());
205 $tpl->setVariable("ROW_NUMBER", $i);
206 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
207 $tpl->setVariable("ID_LABEL", $this->getPostVar() . "[label][$i]");
208 $tpl->setVariable("SIZE", $this->getSize());
209 $tpl->setVariable("SIZE_LABEL", 15);
210 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
211 if ($this->getDisabled()) {
212 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
213 $tpl->setVariable("DISABLED_LABEL", " disabled=\"disabled\"");
214 }
215
216 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
217 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
218 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
221 }
222 }
223
224 if ($this->getShowWizard()) {
225 $tpl->setCurrentBlock("wizard");
226 $tpl->setVariable("CMD_WIZARD", 'cmd[wizard' . $this->getFieldId() . ']');
227 $tpl->setVariable("WIZARD_BUTTON", ilUtil::getImagePath('wizard.svg'));
228 $tpl->setVariable("WIZARD_TEXT", $lng->txt('add_phrase'));
230 }
231
232 if ($this->getShowSavePhrase()) {
233 $tpl->setCurrentBlock('savephrase');
234 $tpl->setVariable("POST_VAR", $this->getPostVar());
235 $tpl->setVariable("VALUE_SAVE_PHRASE", $lng->txt('save_phrase'));
237 }
238
239 if ($this->getUseOtherAnswer()) {
240 $tpl->setCurrentBlock('other_answer_title');
241 $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
243 }
244
245 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
246 $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
247 $tpl->setVariable("LABEL_TEXT", $this->getLabelText());
248 $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
249
250 $a_tpl->setCurrentBlock("prop_generic");
251 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
252 $a_tpl->parseCurrentBlock();
253
255 $tpl->addJavaScript("./Services/Form/js/ServiceFormWizardInput.js");
256 $tpl->addJavaScript("./Modules/SurveyQuestionPool/js/matrixrowwizard.js");
257 }
258}
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...
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)
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)
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)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
$index
Definition: metadata.php:145
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc