ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilMultipleTextsInputGUI.php
Go to the documentation of this file.
1<?php
2
23{
28
32 protected $editElementOrderEnabled = false;
33
40 public function __construct($a_title = "", $a_postvar = "")
41 {
42 global $DIC;
43
44 $this->lng = $DIC->language();
45 parent::__construct($a_title, $a_postvar);
46 $this->validationRegexp = "";
47 }
48
52 public function isEditElementOccuranceEnabled(): bool
53 {
55 }
56
61 {
62 $this->editElementOccuranceEnabled = $editElementOccuranceEnabled;
63 }
64
68 public function isEditElementOrderEnabled(): bool
69 {
71 }
72
77 {
78 $this->editElementOrderEnabled = $editElementOrderEnabled;
79 }
80
86 public function onCheckInput(): bool
87 {
89
90 $submittedElements = $this->getInput();
91
92 if ($submittedElements === [] && $this->getRequired()) {
93 $this->setAlert($lng->txt("msg_input_is_required"));
94 return false;
95 }
96
97 foreach ($submittedElements as $submittedValue) {
98 $submittedContentText = $this->fetchContentTextFromValue($submittedValue);
99
100 if ($this->getRequired() && trim((string) $submittedContentText) === "") {
101 $this->setAlert($lng->txt('msg_input_is_required'));
102 return false;
103 }
104
105 if ($this->getValidationRegexp() !== '') {
106 if (!preg_match($this->getValidationRegexp(), (string) $submittedContentText)) {
107 $this->setAlert($lng->txt('msg_wrong_format'));
108 return false;
109 }
110 }
111 }
112
113 return $this->checkSubItemsInput();
114 }
115
120 public function render(string $a_mode = ""): string
121 {
122 $tpl = new ilTemplate("tpl.prop_multi_text_inp.html", true, true, "Services/Form");
123 $i = 0;
124 foreach ($this->getIdentifiedMultiValues() as $identifier => $value) {
125 if (strlen($value)) {
126 $tpl->setCurrentBlock("prop_text_propval");
127 $tpl->setVariable("PROPERTY_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($value));
128 $tpl->parseCurrentBlock();
129 }
130 if ($this->isEditElementOrderEnabled()) {
131 $tpl->setCurrentBlock("move");
132 $tpl->setVariable("ID_UP", $this->getMultiValuePosIndexedSubFieldId($identifier, 'up', $i));
133 $tpl->setVariable("ID_DOWN", $this->getMultiValuePosIndexedSubFieldId($identifier, 'down', $i));
134 $tpl->setVariable("CMD_UP", $this->buildMultiValueSubmitVar($identifier, $i, 'up'));
135 $tpl->setVariable("CMD_DOWN", $this->buildMultiValueSubmitVar($identifier, $i, 'down'));
136 $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
137 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
138 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
139 $tpl->parseCurrentBlock();
140 }
141 $tpl->setCurrentBlock("row");
142 $tpl->setVariable("POST_VAR", $this->getMultiValuePostVarPosIndexed($identifier, $i));
143 $tpl->setVariable("ID", $this->getMultiValuePosIndexedFieldId($identifier, $i));
144 $tpl->setVariable("SIZE", $this->getSize());
145 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
146
147 if ($this->getDisabled()) {
148 $tpl->setVariable(
149 "DISABLED",
150 " disabled=\"disabled\""
151 );
152 } elseif ($this->isEditElementOccuranceEnabled()) {
153 $tpl->setVariable("ID_ADD", $this->getMultiValuePosIndexedSubFieldId($identifier, 'add', $i));
154 $tpl->setVariable("ID_REMOVE", $this->getMultiValuePosIndexedSubFieldId($identifier, 'remove', $i));
155 $tpl->setVariable("CMD_ADD", $this->buildMultiValueSubmitVar($identifier, $i, 'add'));
156 $tpl->setVariable("CMD_REMOVE", $this->buildMultiValueSubmitVar($identifier, $i, 'remove'));
157 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
158 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
159 }
160
161 $tpl->parseCurrentBlock();
162 $i++;
163 }
164 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
165
166 if (!$this->getDisabled()) {
167 $globalTpl = $GLOBALS['DIC'] ? $GLOBALS['DIC']['tpl'] : $GLOBALS['tpl'];
168 $globalTpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
169 $globalTpl->addJavascript("./Services/Form/js/ServiceFormIdentifiedWizardInputExtend.js");
170 $globalTpl->addJavascript("./Services/Form/js/ServiceFormMultiTextInputInit.js");
171 }
172
173 return $tpl->get();
174 }
175
180 protected function valueHasContentText($value): bool
181 {
182 if ($value === null || is_array($value) || is_object($value)) {
183 return false;
184 }
185
186 return (bool) strlen($value);
187 }
188
194 {
195 if ($this->valueHasContentText($value)) {
196 return $value;
197 }
198
199 return null;
200 }
201}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static get(string $a_glyph, string $a_text="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMultiValuePosIndexedSubFieldId($identifier, $subFieldIndex, $positionIndex)
buildMultiValueSubmitVar($identifier, $positionIndex, $submitCommand)
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...
setEditElementOccuranceEnabled($editElementOccuranceEnabled)
onCheckInput()
Check input, strip slashes etc.
__construct($a_title="", $a_postvar="")
Constructor.
setEditElementOrderEnabled($editElementOrderEnabled)
special template class to simplify handling of ITX/PEAR
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc