ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilMultipleTextsInputGUI.php
Go to the documentation of this file.
1<?php
2
20use ILIAS\UI\Component\Button\Factory as ButtonFactory;
22
27{
32
36 protected $editElementOrderEnabled = false;
37
38 protected GlyphFactory $glyph_factory;
39 protected ButtonFactory $button_factory;
42
49 public function __construct($a_title = "", $a_postvar = "")
50 {
51 parent::__construct($a_title, $a_postvar);
52
53 global $DIC;
54 $this->lng = $DIC['lng'];
55 $this->glyph_factory = $DIC->ui()->factory()->symbol()->glyph();
56 $this->button_factory = $DIC->ui()->factory()->button();
57 $this->renderer = $DIC['ui.renderer'];
58 $this->tpl = $DIC['tpl'];
59
60 $this->validationRegexp = "";
61 }
62
66 public function isEditElementOccuranceEnabled(): bool
67 {
69 }
70
75 {
76 $this->editElementOccuranceEnabled = $editElementOccuranceEnabled;
77 }
78
82 public function isEditElementOrderEnabled(): bool
83 {
85 }
86
91 {
92 $this->editElementOrderEnabled = $editElementOrderEnabled;
93 }
94
95 public function onCheckInput(): bool
96 {
98
99 $submittedElements = $this->getInput();
100
101 if ($submittedElements === [] && $this->getRequired()) {
102 $this->setAlert($lng->txt('msg_input_is_required'));
103 return false;
104 }
105
106 foreach ($submittedElements as $submittedValue) {
107 $submittedContentText = $this->fetchContentTextFromValue($submittedValue);
108
109 if ($this->getRequired() && trim((string) $submittedContentText) === "") {
110 $this->setAlert($lng->txt('msg_input_is_required'));
111 return false;
112 }
113
114 if ($this->getValidationRegexp() !== '') {
115 if (!preg_match($this->getValidationRegexp(), (string) $submittedContentText)) {
116 $this->setAlert($lng->txt('msg_wrong_format'));
117 return false;
118 }
119 }
120 }
121
122 return $this->checkSubItemsInput();
123 }
124
125 public function render(string $a_mode = ""): string
126 {
127 $tpl = new ilTemplate("tpl.prop_multi_text_inp.html", true, true, "components/ILIAS/TestQuestionPool");
128 $i = 0;
129 foreach ($this->getIdentifiedMultiValues() as $identifier => $value) {
130 if ($value !== null) {
131 $tpl->setCurrentBlock("prop_text_propval");
134 }
135 if ($this->isEditElementOrderEnabled()) {
136 $tpl->setCurrentBlock("move");
137 $tpl->setVariable("ID_UP", $this->getMultiValuePosIndexedSubFieldId($identifier, 'up', $i));
138 $tpl->setVariable("ID_DOWN", $this->getMultiValuePosIndexedSubFieldId($identifier, 'down', $i));
139 $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
140 $tpl->setVariable("UP_BUTTON", $this->renderer->render(
141 $this->button_factory->shy('', '')->withSymbol($this->glyph_factory->up())
142 ));
143 $tpl->setVariable("DOWN_BUTTON", $this->renderer->render(
144 $this->button_factory->shy('', '')->withSymbol($this->glyph_factory->down())
145 ));
147 }
148 $tpl->setCurrentBlock("row");
149 $tpl->setVariable("POST_VAR", $this->getMultiValuePostVarPosIndexed($identifier, $i));
150 $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
151 $tpl->setVariable("SIZE", $this->getSize());
152 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
153
154 if ($this->getDisabled()) {
155 $tpl->setVariable(
156 "DISABLED",
157 " disabled=\"disabled\""
158 );
159 } elseif ($this->isEditElementOccuranceEnabled()) {
160 $tpl->setVariable("ID_ADD", $this->getMultiValuePosIndexedSubFieldId($identifier, 'add', $i));
161 $tpl->setVariable("ID_REMOVE", $this->getMultiValuePosIndexedSubFieldId($identifier, 'remove', $i));
162 $tpl->setVariable("ADD_BUTTON", $this->renderer->render(
163 $this->button_factory->shy('', '')->withSymbol($this->glyph_factory->add())
164 ));
165 $tpl->setVariable("REMOVE_BUTTON", $this->renderer->render(
166 $this->button_factory->shy('', '')->withSymbol($this->glyph_factory->remove())
167 ));
168 }
169
171 $i++;
172 }
173 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
174
175 if (!$this->getDisabled()) {
176 $config = '{'
177 . '"fieldContainerSelector": ".ilWzdContainerText", '
178 . '"reindexingRequiredElementsSelectors": ["input:text", "button"], '
179 . '"handleRowCleanUpCallback": function(rowElem) {$(rowElem).find("input:text").val("")}'
180 . '}';
181 $this->tpl->addJavascript("assets/js/answerwizardinput.js");
182 $this->tpl->addJavascript("assets/js/identifiedwizardinput.js");
183 $this->tpl->addOnLoadCode("$.extend({}, AnswerWizardInput, IdentifiedWizardInput).init({$config});");
184 }
185
186 return $tpl->get();
187 }
188
193 protected function valueHasContentText($value): bool
194 {
195 if ($value === null || is_array($value) || is_object($value)) {
196 return false;
197 }
198
199 return (bool) strlen($value);
200 }
201
207 {
208 if ($this->valueHasContentText($value)) {
209 return $value;
210 }
211
212 return null;
213 }
214}
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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