ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.GlossaryAutoLinkTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data;
24use ILIAS\UI;
25use Psr\Http\Message\ServerRequestInterface;
27
32{
33 protected \ilCtrl $ctrl;
34 protected \ilLanguage $lng;
35 protected UI\Factory $ui_fac;
36 protected UI\Renderer $ui_ren;
37 protected ServerRequestInterface $request;
38 protected Data\Factory $df;
39 protected \ilObjGlossary $glossary;
42
47
49 {
50 global $DIC;
51
52 $this->ctrl = $DIC->ctrl();
53 $this->lng = $DIC->language();
54 $this->ui_fac = $DIC->ui()->factory();
55 $this->ui_ren = $DIC->ui()->renderer();
56 $this->request = $DIC->http()->request();
57 $this->df = new Data\Factory();
58 $this->glossary = $glossary;
59 $this->edit_gui_request = $DIC->glossary()->internal()->gui()->editing()->request();
60 $this->requested_table_glossary_auto_link_action = $this->edit_gui_request->getTableGlossaryAutoLinkAction();
61 $this->requested_table_glossary_auto_link_ids = $this->edit_gui_request->getTableGlossaryAutoLinkIds();
62 }
63
64 public function getComponent(): UI\Component\Table\Data
65 {
66 $columns = $this->getColumns();
67 $actions = $this->getActions();
68 $data_retrieval = $this->getDataRetrieval();
69
70 if ($this->requested_table_glossary_auto_link_action === "removeGlossary") {
71 $items = [];
72 foreach ($this->requested_table_glossary_auto_link_ids as $id) {
73 $items[] = $this->ui_fac->modal()->interruptiveItem()->standard(
74 $id,
76 );
77 }
78 echo($this->ui_ren->renderAsync([
79 $this->ui_fac->modal()->interruptive(
80 "",
81 $this->lng->txt("glo_remove_glossary"),
82 $this->ctrl->getFormActionByClass("ilobjglossarygui", "removeGlossary")
83 )
84 ->withAffectedItems($items)
85 ->withActionButtonLabel($this->lng->txt("remove"))
86 ]));
87 exit();
88 }
89
90 $table = $this->ui_fac->table()
91 ->data($data_retrieval, $this->lng->txt("cont_auto_glossaries"), $columns)
92 ->withId(
93 self::class . "_" .
94 $this->glossary->getRefId()
95 )
96 ->withActions($actions)
97 ->withRequest($this->request);
98
99 return $table;
100 }
101
102 protected function getColumns(): array
103 {
104 $columns = [
105 "title" => $this->ui_fac->table()->column()->text($this->lng->txt("title"))
106 ];
107
108 return $columns;
109 }
110
111 protected function getActions(): array
112 {
113 $query_params_namespace = ["glo_auto_link_table"];
114
115 $url_builder_remove = new UI\URLBuilder($this->df->uri($this->request->getUri()->__toString()));
116 list($url_builder_remove, $action_parameter_token_remove, $row_id_token_remove) =
117 $url_builder_remove->acquireParameters(
118 $query_params_namespace,
119 "action",
120 "glo_ids"
121 );
122
123 $actions["remove"] = $this->ui_fac->table()->action()->single(
124 $this->lng->txt("remove"),
125 $url_builder_remove->withParameter($action_parameter_token_remove, "removeGlossary"),
126 $row_id_token_remove
127 )
128 ->withAsync();
129
130 return $actions;
131 }
132
133 protected function getDataRetrieval(): UI\Component\Table\DataRetrieval
134 {
135 $data_retrieval = new class (
137 ) implements UI\Component\Table\DataRetrieval {
138 use TableRecords;
139
140 public function __construct(
141 protected \ilObjGlossary $glossary
142 ) {
143 }
144
145 public function getRows(
146 UI\Component\Table\DataRowBuilder $row_builder,
147 array $visible_column_ids,
149 Data\Order $order,
150 ?array $filter_data,
151 ?array $additional_parameters
152 ): \Generator {
153 $records = $this->getRecords($range, $order);
154 foreach ($records as $idx => $record) {
155 $row_id = (string) $record["glo_id"];
156
157 yield $row_builder->buildDataRow($row_id, $record);
158 }
159 }
160
161 public function getTotalRowCount(
162 ?array $filter_data,
163 ?array $additional_parameters
164 ): ?int {
165 return count($this->getRecords());
166 }
167
168 protected function getRecords(?Data\Range $range = null, ?Data\Order $order = null): array
169 {
170 $records = [];
171 $i = 0;
172 foreach ($this->glossary->getAutoGlossaries() as $glo_id) {
173 $records[$i]["glo_id"] = $glo_id;
174 $records[$i]["title"] = \ilObject::_lookupTitle($glo_id);
175 $i++;
176 }
177
178 if ($order) {
179 $records = $this->orderRecords($records, $order);
180 }
181
182 if ($range) {
183 $records = $this->limitRecords($records, $range);
184 }
185
186 return $records;
187 }
188 };
189
190 return $data_retrieval;
191 }
192}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
Definition: UI.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $obj_id)
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26