ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclGenericMultiInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
28 protected ilObjUser $user;
29
31 protected ?array $line_values = [];
32
33 public function __construct(string $a_title = "", string $a_postvar = "")
34 {
35 global $DIC;
36
37 $this->user = $DIC->user();
38 $this->ui_factory = $DIC->ui()->factory();
39 $this->renderer = $DIC->ui()->renderer();
40
41 parent::__construct($a_title, $a_postvar);
42 }
43
44 public function setInput(ilFormPropertyGUI $input): void
45 {
46 $this->input = $input;
47 }
48
49 public function setValue(string $value): void
50 {
51 if ($this->input instanceof ilDateTimeInputGUI) {
52 $date = new DateTime($value, new DateTimeZone($this->user->getTimeZone()));
53 $this->input->setDate(new ilDateTime($date->getTimestamp(), IL_CAL_UNIX));
54 } else {
55 $this->input->setValue($value);
56 }
57 }
58
59 public function setValueByArray(array $a_values): void
60 {
61 $this->line_values = $a_values[$this->getPostVar()] ?? [];
62 }
63
64 public function checkInput(): bool
65 {
66 return true;
67 }
68
69 public function getInput(): array
70 {
71 return $this->strArray($this->getPostVar());
72 }
73
74 public function render(int $iterator_id): string
75 {
76 $tpl = new ilTemplate("tpl.prop_generic_multi_line.html", true, true, 'components/ILIAS/DataCollection');
77
78 $input = clone $this->input;
79 $input->setPostVar($this->getPostVar() . '[' . $iterator_id . ']');
80
81 $tpl->setCurrentBlock('input');
82 $tpl->setVariable('CONTENT', $input->render());
83 $tpl->parseCurrentBlock();
84
85 $tpl->setVariable('IMAGE_PLUS', $this->renderer->render($this->ui_factory->symbol()->glyph()->add()));
86 $tpl->setVariable('IMAGE_MINUS', $this->renderer->render($this->ui_factory->symbol()->glyph()->remove()));
87 $tpl->setVariable('IMAGE_UP', $this->renderer->render($this->ui_factory->symbol()->glyph()->up()));
88 $tpl->setVariable('IMAGE_DOWN', $this->renderer->render($this->ui_factory->symbol()->glyph()->down()));
89
90 return $tpl->get();
91 }
92
93 public function insert(ilTemplate $a_tpl): void
94 {
95 $output = $this->render(0);
96
97 if (is_array($this->line_values) && count($this->line_values) > 0) {
98 $counter = 0;
99 foreach ($this->line_values as $i => $data) {
100 $object = $this;
101 $object->setValue($data);
102 $output .= $object->render($i);
103 $counter++;
104 }
105 } else {
106 $output .= $this->render(1);
107 }
108
109 $output = '<div id="' . $this->getFieldId() . '" class="multi_line_input">' . $output . '</div>';
110 $this->global_tpl->addJavaScript('assets/js/generic_multi_line_input.js');
111 $id = $this->getFieldId();
112 $this->global_tpl->addOnLoadCode("il.DataCollection.genericMultiLineInit('$id');");
113
114 $a_tpl->setCurrentBlock("prop_generic");
115 $a_tpl->setVariable("PROP_GENERIC", $output);
116 $a_tpl->parseCurrentBlock();
117 }
118}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
renderer()
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
const IL_CAL_UNIX
This class represents a date/time property in a property form.
@classDescription Date and time handling
__construct(string $a_title="", string $a_postvar="")
checkInput()
Check input, strip slashes etc.
This class represents a property in a property form.
setPostVar(string $a_postvar)
User class.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This is how the factory for UI elements looks.
Definition: Factory.php:38
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
$counter