ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.TermDefinitionBulkCreationTable.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 \ilLanguage $lng;
35  protected UI\Factory $ui_fac;
37  protected string $raw_data;
38  protected \ilObjGlossary $glossary;
39 
40  public function __construct(string $raw_data, \ilObjGlossary $glossary)
41  {
42  global $DIC;
43 
44  $this->lng = $DIC->language();
45  $this->ui_fac = $DIC->ui()->factory();
46  $this->request = $DIC->http()->request();
47  $this->raw_data = $raw_data;
48  $this->glossary = $glossary;
49  }
50 
51  public function getComponent(): UI\Component\Table\Data
52  {
53  $columns = $this->getColumns();
54  $data_retrieval = $this->getDataRetrieval();
55 
56  $table = $this->ui_fac->table()
57  ->data($this->lng->txt("glo_term_definition_pairs"), $columns, $data_retrieval)
58  ->withId(
59  self::class . "_" .
60  $this->glossary->getRefId()
61  )
62  ->withRequest($this->request);
63 
64  return $table;
65  }
66 
67  protected function getColumns(): array
68  {
69  $columns = [
70  "term" => $this->ui_fac->table()->column()->text($this->lng->txt("cont_term"))
71  ->withIsSortable(false),
72  "definition" => $this->ui_fac->table()->column()->text($this->lng->txt("cont_definition"))
73  ->withIsSortable(false)
74  ];
75 
76  return $columns;
77  }
78 
79  protected function getDataRetrieval(): UI\Component\Table\DataRetrieval
80  {
81  $data_retrieval = new class (
84  ) implements UI\Component\Table\DataRetrieval {
85  use TableRecords;
86 
87  protected TermManager $term_manager;
88 
89  public function __construct(
90  protected string $raw_data,
91  protected \ilObjGlossary $glossary
92  ) {
93  global $DIC;
94 
95  $this->term_manager = $DIC->glossary()->internal()->domain()->term($this->glossary);
96  }
97 
98  public function getRows(
99  UI\Component\Table\DataRowBuilder $row_builder,
100  array $visible_column_ids,
101  Data\Range $range,
102  Data\Order $order,
103  ?array $filter_data,
104  ?array $additional_parameters
105  ): \Generator {
106  $records = $this->getRecords($range);
107  foreach ($records as $idx => $record) {
108  $row_id = (string) $record["id"];
109 
110  yield $row_builder->buildDataRow($row_id, $record);
111  }
112  }
113 
114  public function getTotalRowCount(
115  ?array $filter_data,
116  ?array $additional_parameters
117  ): ?int {
118  return count($this->getRecords());
119  }
120 
121  protected function getRecords(Data\Range $range = null): array
122  {
123  $data = $this->term_manager->getDataArrayFromInputString($this->raw_data);
124 
125  $records = [];
126  $i = 0;
127  foreach ($data as $pair) {
128  $records[$i]["id"] = $i + 1;
129  $records[$i]["term"] = $pair["term"];
130  $records[$i]["definition"] = $pair["definition"];
131 
132  $i++;
133  }
134 
135  if ($range) {
136  $records = $this->limitRecords($records, $range);
137  }
138 
139  return $records;
140  }
141  };
142 
143  return $data_retrieval;
144  }
145 }
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...
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...