ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilDclGenericMultiInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  protected Factory $ui_factory;
27  protected Renderer $renderer;
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 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
renderer()
const IL_CAL_UNIX
This class represents a date/time property in a property form.
setPostVar(string $a_postvar)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
__construct(string $a_title="", string $a_postvar="")
This is how the factory for UI elements looks.
Definition: Factory.php:37
global $DIC
Definition: shib_login.php:26
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)