ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TableBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Factory as UIFactory;
33
35{
36 protected UIFactory $ui_factory;
41
43 protected array $data;
44
45 public function __construct(
46 UIFactory $ui_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}
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
__construct(UIFactory $ui_factory, Renderer $renderer, PresenterInterface $presenter, DataFinder $data_finder, ButtonFactory $button_factory)
withAdditionalRow(ElementInterface $element, FlexibleSignal $update_signal, ?FlexibleSignal $delete_signal)
An entity that renders components to a string output.
Definition: Renderer.php:31
$res
Definition: ltiservices.php:69
if(!file_exists('../ilias.ini.php'))