ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 
30  protected ?array $line_values = [];
31 
32  public function __construct(string $a_title = "", string $a_postvar = "")
33  {
34  global $DIC;
35 
36  $this->ui_factory = $DIC->ui()->factory();
37  $this->renderer = $DIC->ui()->renderer();
38 
39  parent::__construct($a_title, $a_postvar);
40  }
41 
42  public function setInput(ilFormPropertyGUI $input): void
43  {
44  $this->input = $input;
45  }
46 
47  public function setValue(string $value): void
48  {
49  if ($this->input instanceof ilDateTimeInputGUI) {
50  $this->input->setDate(new ilDateTime(strtotime($value), IL_CAL_UNIX));
51  } else {
52  $this->input->setValue($value);
53  }
54  }
55 
56  public function setValueByArray(array $a_values): void
57  {
58  $this->line_values = $a_values[$this->getPostVar()] ?? [];
59  }
60 
61  public function checkInput(): bool
62  {
63  return true;
64  }
65 
66  public function getInput(): array
67  {
68  return $this->strArray($this->getPostVar());
69  }
70 
71  public function render(int $iterator_id): string
72  {
73  $tpl = new ilTemplate("tpl.prop_generic_multi_line.html", true, true, 'components/ILIAS/DataCollection');
74 
75  $input = clone $this->input;
76  $input->setPostVar($this->getPostVar() . '[' . $iterator_id . ']');
77 
78  $tpl->setCurrentBlock('input');
79  $tpl->setVariable('CONTENT', $input->render());
80  $tpl->parseCurrentBlock();
81 
82  $tpl->setVariable('IMAGE_PLUS', $this->renderer->render($this->ui_factory->symbol()->glyph()->add()));
83  $tpl->setVariable('IMAGE_MINUS', $this->renderer->render($this->ui_factory->symbol()->glyph()->remove()));
84  $tpl->setVariable('IMAGE_UP', $this->renderer->render($this->ui_factory->symbol()->glyph()->up()));
85  $tpl->setVariable('IMAGE_DOWN', $this->renderer->render($this->ui_factory->symbol()->glyph()->down()));
86 
87  return $tpl->get();
88  }
89 
90  public function insert(ilTemplate $a_tpl): void
91  {
92  $output = $this->render(0);
93 
94  if (is_array($this->line_values) && count($this->line_values) > 0) {
95  $counter = 0;
96  foreach ($this->line_values as $i => $data) {
97  $object = $this;
98  $object->setValue($data);
99  $output .= $object->render($i);
100  $counter++;
101  }
102  } else {
103  $output .= $this->render(1);
104  }
105 
106  $output = '<div id="' . $this->getFieldId() . '" class="multi_line_input">' . $output . '</div>';
107  $this->global_tpl->addJavaScript('assets/js/generic_multi_line_input.js');
108  $id = $this->getFieldId();
109  $this->global_tpl->addOnLoadCode("il.DataCollection.genericMultiLineInit('$id');");
110 
111  $a_tpl->setCurrentBlock("prop_generic");
112  $a_tpl->setVariable("PROP_GENERIC", $output);
113  $a_tpl->parseCurrentBlock();
114  }
115 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
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:546
__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:25
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)