ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMultipleTextsInputGUI.php
Go to the documentation of this file.
1<?php
2
21
26{
31
35 protected $editElementOrderEnabled = false;
36
37 protected GlyphFactory $glyph_factory;
40
47 public function __construct($a_title = "", $a_postvar = "")
48 {
49 parent::__construct($a_title, $a_postvar);
50
51 global $DIC;
52 $this->lng = $DIC['lng'];
53 $this->glyph_factory = $DIC->ui()->factory()->symbol()->glyph();
54 $this->renderer = $DIC['ui.renderer'];
55 $this->tpl = $DIC['tpl'];
56
57 $this->validationRegexp = "";
58 }
59
63 public function isEditElementOccuranceEnabled(): bool
64 {
66 }
67
72 {
73 $this->editElementOccuranceEnabled = $editElementOccuranceEnabled;
74 }
75
79 public function isEditElementOrderEnabled(): bool
80 {
82 }
83
88 {
89 $this->editElementOrderEnabled = $editElementOrderEnabled;
90 }
91
92 public function onCheckInput(): bool
93 {
95
96 $submittedElements = $this->getInput();
97
98 if ($submittedElements === [] && $this->getRequired()) {
99 $this->setAlert($lng->txt('msg_input_is_required'));
100 return false;
101 }
102
103 foreach ($submittedElements as $submittedValue) {
104 $submittedContentText = $this->fetchContentTextFromValue($submittedValue);
105
106 if ($this->getRequired() && trim((string) $submittedContentText) === "") {
107 $this->setAlert($lng->txt('msg_input_is_required'));
108 return false;
109 }
110
111 if ($this->getValidationRegexp() !== '') {
112 if (!preg_match($this->getValidationRegexp(), (string) $submittedContentText)) {
113 $this->setAlert($lng->txt('msg_wrong_format'));
114 return false;
115 }
116 }
117 }
118
119 return $this->checkSubItemsInput();
120 }
121
122 public function render(string $a_mode = ""): string
123 {
124 $tpl = new ilTemplate("tpl.prop_multi_text_inp.html", true, true, "components/ILIAS/TestQuestionPool");
125 $i = 0;
126 foreach ($this->getIdentifiedMultiValues() as $identifier => $value) {
127 if ($value !== null) {
128 $tpl->setCurrentBlock("prop_text_propval");
131 }
132 if ($this->isEditElementOrderEnabled()) {
133 $tpl->setCurrentBlock("move");
134 $tpl->setVariable("ID_UP", $this->getMultiValuePosIndexedSubFieldId($identifier, 'up', $i));
135 $tpl->setVariable("ID_DOWN", $this->getMultiValuePosIndexedSubFieldId($identifier, 'down', $i));
136 $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
137 $tpl->setVariable("UP_BUTTON", $this->renderer->render(
138 $this->glyph_factory->up()->withAction('#')
139 ));
140 $tpl->setVariable("DOWN_BUTTON", $this->renderer->render(
141 $this->glyph_factory->down()->withAction('#')
142 ));
144 }
145 $tpl->setCurrentBlock("row");
146 $tpl->setVariable("POST_VAR", $this->getMultiValuePostVarPosIndexed($identifier, $i));
147 $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
148 $tpl->setVariable("SIZE", $this->getSize());
149 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
150
151 if ($this->getDisabled()) {
152 $tpl->setVariable(
153 "DISABLED",
154 " disabled=\"disabled\""
155 );
156 } elseif ($this->isEditElementOccuranceEnabled()) {
157 $tpl->setVariable("ID_ADD", $this->getMultiValuePosIndexedSubFieldId($identifier, 'add', $i));
158 $tpl->setVariable("ID_REMOVE", $this->getMultiValuePosIndexedSubFieldId($identifier, 'remove', $i));
159 $tpl->setVariable("ADD_BUTTON", $this->renderer->render(
160 $this->glyph_factory->add()->withAction('#')
161 ));
162 $tpl->setVariable("REMOVE_BUTTON", $this->renderer->render(
163 $this->glyph_factory->remove()->withAction('#')
164 ));
165 }
166
168 $i++;
169 }
170 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
171
172 if (!$this->getDisabled()) {
173 $config = '{'
174 . '"fieldContainerSelector": ".ilWzdContainerText", '
175 . '"reindexingRequiredElementsSelectors": ["input:text", "button"], '
176 . '"handleRowCleanUpCallback": function(rowElem) {$(rowElem).find("input:text").val("")}'
177 . '}';
178 $this->tpl->addJavascript("assets/js/answerwizardinput.js");
179 $this->tpl->addJavascript("assets/js/identifiedwizardinput.js");
180 $this->tpl->addOnLoadCode("$.extend({}, AnswerWizardInput, IdentifiedWizardInput).init({$config});");
181 }
182
183 return $tpl->get();
184 }
185
190 protected function valueHasContentText($value): bool
191 {
192 if ($value === null || is_array($value) || is_object($value)) {
193 return false;
194 }
195
196 return (bool) strlen($value);
197 }
198
204 {
205 if ($this->valueHasContentText($value)) {
206 return $value;
207 }
208
209 return null;
210 }
211}
renderer()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMultiValuePosIndexedFieldId($identifier, $position_index)
getMultiValuePosIndexedSubFieldId($identifier, $sub_field_index, $position_index)
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)
setEditElementOccuranceEnabled($editElementOccuranceEnabled)
__construct($a_title="", $a_postvar="")
Constructor.
setEditElementOrderEnabled($editElementOrderEnabled)
special template class to simplify handling of ITX/PEAR
setVariable(string $variable, $value='')
Sets the given variable to the given value.
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.
This is how a factory for glyphs looks like.
Definition: Factory.php:27
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26