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