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