19 declare(strict_types=1);
20 require_once(
"./Services/Form/classes/class.ilFormPropertyGUI.php");
53 public function __construct(
string $a_title =
"",
string $a_postvar =
"")
63 if (isset($this->hooks[$key])) {
64 return $this->hooks[
$key];
72 $this->hooks[
$key] = $options;
77 if (isset($this->hooks[$key])) {
78 unset($this->hooks[$key]);
89 $this->input_options[$input->
getPostVar()] = $options;
122 public function setMulti(
bool $a_multi,
bool $a_sortable =
false,
bool $a_addremove =
true): void
124 $this->multi = $a_multi;
131 foreach ($this->inputs as
$key => $item) {
135 if (array_key_exists(
$key, $value)) {
136 $item->setValue((
string) $value[
$key]);
145 foreach ($this->inputs as
$key => $item) {
156 $this->line_values =
$data;
168 $internal_fields = array_keys($this->inputs);
172 if (is_array(
$post)) {
173 foreach (
$post as $authority) {
175 array_key_exists(self::MULTI_FIELD_ID, $authority) &&
176 array_key_exists(self::MULTI_FIELD_OVER, $authority) &&
177 array_key_exists(self::MULTI_FIELD_SCOPE, $authority) &&
178 trim($authority[self::MULTI_FIELD_OVER]) !==
'' &&
179 trim($authority[self::MULTI_FIELD_SCOPE]) !==
'' 181 $this->
setAlert($this->
lng->txt(
"msg_input_is_required"));
192 if (isset($this->cust_attr[$key]) && !$override) {
214 public function render(
int|
string $iterator_id = 0,
bool $clean_render =
false): string
218 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'Modules/OrgUnit');
220 $class =
'multi_input_line';
223 $tpl->setCurrentBlock(
'cust_attr');
224 $tpl->setVariable(
'CUSTOM_ATTR_KEY',
$key);
225 $tpl->setVariable(
'CUSTOM_ATTR_VALUE',
$value);
226 $tpl->parseCurrentBlock();
229 foreach ($inputs as
$key => $input) {
230 $input = clone $input;
233 if (!method_exists($input,
'render')) {
242 throw new \ilException(
"Method " . get_class($input)
243 .
"::render() does not exists! You cannot use this input-type in ilMultiLineInputGUI");
247 $is_disabled_hook = $this->
getHook(self::HOOK_IS_INPUT_DISABLED);
248 if ($is_disabled_hook !==
false && !$clean_render) {
249 $input->setDisabled($is_disabled_hook($this->
getValue()));
252 $input->setDisabled(
true);
254 if ($iterator_id == 0 && !isset($this->post_var_cache[
$key])) {
255 $this->post_var_cache[
$key] = $input->getPostVar();
258 $input->setPostVar($this->post_var_cache[$key]);
261 $input->setPostVar($post_var);
262 $before_render_hook = $this->
getHook(self::HOOK_BEFORE_INPUT_RENDER);
263 if ($before_render_hook !==
false && !$clean_render) {
264 $input = $before_render_hook($this->
getValue(), $key, $input);
268 $tpl->setCurrentBlock(
'hidden');
269 $tpl->setVariable(
'NAME', $post_var);
274 $tpl->setCurrentBlock(
'input_label');
275 $tpl->setVariable(
'LABEL', $input->getTitle());
276 $tpl->setVariable(
'CONTENT', $input->getHTML());
277 $tpl->parseCurrentBlock();
278 $first_label =
false;
280 $tpl->setCurrentBlock(
'input');
281 $tpl->setVariable(
'CONTENT', $input->getHTML());
286 $tpl->setCurrentBlock(
'input_label');
287 $tpl->setVariable(
'LABEL', $input->getTitle());
288 $tpl->setVariable(
'CONTENT', $input->render());
289 $first_label =
false;
291 $tpl->setCurrentBlock(
'input');
292 $tpl->setVariable(
'CONTENT', $input->render());
298 $tpl->setCurrentBlock(
'input_info_label');
299 $tpl->setVariable(
'INFO_LABEL', $input->getInfo());
300 $tpl->parseCurrentBlock();
302 $tpl->setCurrentBlock(
'input_info');
303 $tpl->setVariable(
'INFO', $input->getInfo());
304 $tpl->parseCurrentBlock();
307 $tpl->parseCurrentBlock();
312 $is_removeable_hook = $this->
getHook(self::HOOK_IS_LINE_REMOVABLE);
313 if ($is_removeable_hook !==
false && !$clean_render) {
314 $show_remove = $is_removeable_hook($this->
getValue());
318 $tpl->setCurrentBlock(
'multi_icons');
319 $tpl->setVariable(
'IMAGE_PLUS', $image_plus);
320 $tpl->setVariable(
'IMAGE_MINUS', $image_minus);
321 $tpl->parseCurrentBlock();
323 $tpl->setCurrentBlock(
'multi_icons_move');
326 $tpl->parseCurrentBlock();
336 $tpl->addJavascript(
'Modules/OrgUnit/js/generic_multi_line_input.js');
347 $output .= $this->
render(0,
true);
348 if ($this->
getMulti() && is_array($this->line_values) && count($this->line_values) > 0) {
349 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'Modules/OrgUnit');
351 $image_minus =
'<span class="glyphicon glyphicon-minus hide"></span>';
353 $tpl->setVariable(
'ADDITIONAL_ATTRS',
"id='multi_line_add_button' style='display:none'");
354 $tpl->setCurrentBlock(
'multi_icons');
355 $tpl->setVariable(
'IMAGE_PLUS', $image_plus);
356 $tpl->setVariable(
'IMAGE_MINUS', $image_minus);
357 $tpl->parseCurrentBlock();
358 $output .= $tpl->get();
360 foreach ($this->line_values as $run =>
$data) {
362 $object->setValue(
$data);
363 $output .= $object->render($run);
366 if ($this->render_one_for_empty_value) {
367 $output .= $this->
render(0,
true);
369 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'Modules/OrgUnit');
371 $image_minus =
'<span class="glyphicon glyphicon-minus hide"></span>';
373 $tpl->setVariable(
'ADDITIONAL_ATTRS',
"id='multi_line_add_button'");
374 $tpl->setCurrentBlock(
'multi_icons');
375 $tpl->setVariable(
'IMAGE_PLUS', $image_plus);
376 $tpl->setVariable(
'IMAGE_MINUS', $image_minus);
377 $tpl->parseCurrentBlock();
378 $output .= $tpl->get();
382 $output =
"<div id='{$this->getFieldId()}' class='multi_line_input'>{$output}</div>";
385 $options = json_encode($this->input_options);
386 $tpl->addOnLoadCode(
"$('#{$this->getFieldId()}').multi_line_input({$this->getFieldId()}, '{$options}')");
407 return $this->
render(
"toolbar");
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static get(string $a_glyph, string $a_text="")
setVariable($variable, $value='')
Sets a variable value.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a text area property in a property form.