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