ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ?array $filter_data,
103 ?array $additional_parameters
104 ): \Generator {
105 $records = $this->getRecords($range);
106 foreach ($records as $idx => $record) {
107 $row_id = (string) $record["id"];
108
109 yield $row_builder->buildDataRow($row_id, $record);
110 }
111 }
112
113 public function getTotalRowCount(
114 ?array $filter_data,
115 ?array $additional_parameters
116 ): ?int {
117 return count($this->getRecords());
118 }
119
120 protected function getRecords(?Data\Range $range = null): array
121 {
122 $data = $this->term_manager->getDataArrayFromInputString($this->raw_data);
123
124 $records = [];
125 $i = 0;
126 foreach ($data as $pair) {
127 $records[$i]["id"] = $i + 1;
128 $records[$i]["term"] = $pair["term"];
129 $records[$i]["definition"] = $pair["definition"];
130
131 $i++;
132 }
133
134 if ($range) {
135 $records = $this->limitRecords($records, $range);
136 }
137
138 return $records;
139 }
140 };
141
142 return $data_retrieval;
143 }
144}
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