ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.GlossaryForeignTermTable.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Data;
24 use ILIAS\UI;
26 
31 {
32  protected \ilCtrl $ctrl;
33  protected \ilLanguage $lng;
34  protected UI\Factory $ui_fac;
36  protected Data\Factory $df;
37  protected \ilObjGlossary $glossary;
38  protected \ilObjGlossary $foreign_glossary;
39 
40  public function __construct(\ilObjGlossary $glossary, \ilObjGlossary $foreign_glossary)
41  {
42  global $DIC;
43 
44  $this->ctrl = $DIC->ctrl();
45  $this->lng = $DIC->language();
46  $this->ui_fac = $DIC->ui()->factory();
47  $this->request = $DIC->http()->request();
48  $this->df = new Data\Factory();
49  $this->glossary = $glossary;
50  $this->foreign_glossary = $foreign_glossary;
51  }
52 
53  public function getComponent(): UI\Component\Table\Data
54  {
55  $columns = $this->getColumns();
56  $actions = $this->getActions();
57  $data_retrieval = $this->getDataRetrieval();
58 
59  $table = $this->ui_fac->table()
60  ->data(
61  $data_retrieval,
62  $this->foreign_glossary->getTitle() . ": " .$this->lng->txt("glo_select_terms"),
63  $columns,
64  )
65  ->withId(
66  self::class . "_" .
67  $this->glossary->getRefId() . "_" .
68  $this->foreign_glossary->getRefId()
69  )
70  ->withActions($actions)
71  ->withRequest($this->request);
72 
73  return $table;
74  }
75 
76  protected function getColumns(): array
77  {
78  $columns = [
79  "title" => $this->ui_fac->table()->column()->text($this->lng->txt("glo_term"))
80  ->withIsSortable(false)
81  ];
82 
83  return $columns;
84  }
85 
86  protected function getActions(): array
87  {
88  $query_params_namespace = ["glo_foreign_term_table"];
89 
90  $uri_copy = $this->df->uri(
91  ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTargetByClass("ilglossaryforeigntermcollectorgui", "copyTerms")
92  );
93  $url_builder_copy = new UI\URLBuilder($uri_copy);
94  list($url_builder_copy, $action_parameter_token_copy, $row_id_token_copy) =
95  $url_builder_copy->acquireParameters(
96  $query_params_namespace,
97  "action",
98  "term_ids"
99  );
100 
101  $uri_reference = $this->df->uri(
102  ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTargetByClass("ilglossaryforeigntermcollectorgui", "referenceTerms")
103  );
104  $url_builder_reference = new UI\URLBuilder($uri_reference);
105  list($url_builder_reference, $action_parameter_token_reference, $row_id_token_reference) =
106  $url_builder_reference->acquireParameters(
107  $query_params_namespace,
108  "action",
109  "term_ids"
110  );
111 
112  $actions = [
113  "copy" => $this->ui_fac->table()->action()->multi(
114  $this->lng->txt("glo_copy_terms"),
115  $url_builder_copy->withParameter($action_parameter_token_copy, "copyTerms"),
116  $row_id_token_copy
117  ),
118  "reference" => $this->ui_fac->table()->action()->multi(
119  $this->lng->txt("glo_reference_terms"),
120  $url_builder_reference->withParameter($action_parameter_token_reference, "referenceTerms"),
121  $row_id_token_reference
122  )
123  ];
124 
125  return $actions;
126  }
127 
128  protected function getDataRetrieval(): UI\Component\Table\DataRetrieval
129  {
130  $data_retrieval = new class (
132  ) implements UI\Component\Table\DataRetrieval {
133  use TableRecords;
134 
135  public function __construct(
136  protected \ilObjGlossary $foreign_glossary
137  ) {
138  }
139 
140  public function getRows(
141  UI\Component\Table\DataRowBuilder $row_builder,
142  array $visible_column_ids,
143  Data\Range $range,
144  Data\Order $order,
145  ?array $filter_data,
146  ?array $additional_parameters
147  ): \Generator {
148  $records = $this->getRecords($range);
149  foreach ($records as $idx => $record) {
150  $row_id = (string) $record["term_id"];
151 
152  yield $row_builder->buildDataRow($row_id, $record);
153  }
154  }
155 
156  public function getTotalRowCount(
157  ?array $filter_data,
158  ?array $additional_parameters
159  ): ?int {
160  return count($this->getRecords());
161  }
162 
163  protected function getRecords(?Data\Range $range = null): array
164  {
165  $records = [];
166  $i = 0;
167  foreach ($this->foreign_glossary->getTermList() as $term) {
168  $records[$i]["term_id"] = $term["id"];
169  $records[$i]["title"] = $term["term"];
170  $i++;
171  }
172 
173  if ($range) {
174  $records = $this->limitRecords($records, $range);
175  }
176 
177  return $records;
178  }
179  };
180 
181  return $data_retrieval;
182  }
183 }
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:28
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(\ilObjGlossary $glossary, \ilObjGlossary $foreign_glossary)
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28