ILIAS  trunk Revision v11.0_alpha-2658-ge2404539063
TableBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
33 
35 {
37  protected Renderer $renderer;
41 
43  protected array $data;
44 
45  public function __construct(
46  UIFactory $ui_factory,
47  Renderer $renderer,
48  PresenterInterface $presenter,
49  DataFinder $data_finder,
50  ButtonFactory $button_factory
51  ) {
52  $this->ui_factory = $ui_factory;
53  $this->renderer = $renderer;
54  $this->presenter = $presenter;
55  $this->data_finder = $data_finder;
56  $this->button_factory = $button_factory;
57  }
58 
59  public function get(): Table
60  {
61  $table = $this->init();
62  $table->setData($this->data);
63  return $table;
64  }
65 
66  public function withAdditionalRow(
67  ElementInterface $element,
68  FlexibleSignal $update_signal,
69  ?FlexibleSignal $delete_signal
70  ): TableBuilder {
71  if (!isset($this->template_element)) {
72  $this->template_element = $element;
73  }
74 
75  $res = [];
76 
77  foreach ($this->data_finder->getDataCarryingElements(
78  $element,
79  true
80  ) as $data_el) {
81  $data = '';
82  if ($data_el->getData()->type() !== Type::NULL) {
83  $data = $this->presenter->data()->dataValue($data_el->getData());
84  }
85  $res[] = $data;
86  }
87 
88  $action_buttons = [];
89  $action_buttons[] = $this->button_factory->update($update_signal);
90  if ($delete_signal) {
91  $action_buttons[] = $this->button_factory->delete(
92  $delete_signal,
93  true
94  );
95  }
96  $dropdown = $this->ui_factory->dropdown()->standard($action_buttons);
97  $res['dropdown'] = $this->renderer->render($dropdown);
98 
99  $clone = clone $this;
100  $clone->data[] = $res;
101  return $clone;
102  }
103 
104  protected function init(): Table
105  {
106  if (!isset($this->template_element)) {
107  throw new \ilMDEditorException('Table cannot be empty.');
108  }
109  $table = new Table();
110  $table->setRowTemplate(
111  'tpl.full_editor_row.html',
112  'components/ILIAS/MetaData'
113  );
114  $table->setTitle($this->presenter->elements()->nameWithParents(
115  $this->template_element,
116  null,
117  true
118  ));
119  $table->setExternalSegmentation(true);
120 
121  foreach ($this->data_finder->getDataCarryingElements(
122  $this->template_element,
123  true
124  ) as $data_el) {
125  $table->addColumn($this->presenter->elements()->nameWithParents(
126  $data_el,
127  $this->template_element,
128  false
129  ));
130  }
131  $table->addColumn('');
132  return $table;
133  }
134 }
$res
Definition: ltiservices.php:66
__construct(UIFactory $ui_factory, Renderer $renderer, PresenterInterface $presenter, DataFinder $data_finder, ButtonFactory $button_factory)
renderer()
withAdditionalRow(ElementInterface $element, FlexibleSignal $update_signal, ?FlexibleSignal $delete_signal)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null