ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjectConsumerTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29use Psr\Http\Message\ServerRequestInterface;
30use Psr\Http\Message\RequestInterface;
31
41{
42 protected ilLanguage $lng;
44 protected \ILIAS\UI\Renderer $ui_renderer;
45 private ServerRequestInterface|RequestInterface $request;
46 protected \ILIAS\Data\Factory $data_factory;
49 protected \ILIAS\Refinery\Factory $refinery;
50 private array $records;
51 private bool $editable = false;
52
53 public function __construct()
54 {
55 global $DIC;
56
57 $this->lng = $DIC->language();
58 $this->ui_factory = $DIC->ui()->factory();
59 $this->ui_renderer = $DIC->ui()->renderer();
60 $this->request = $DIC->http()->request();
61 $this->data_factory = new \ILIAS\Data\Factory();
62 $this->ctrl = $DIC->ctrl();
63 $this->wrapper = $DIC->http()->wrapper();
64 $this->refinery = $DIC->refinery();
65
66 $this->records = $this->getRecords();
67 }
68
69 public function getColumns(): array
70 {
71 return [
72 'active' => $this->ui_factory->table()->column()->statusIcon($this->lng->txt('active')),
73 'title' => $this->ui_factory->table()->column()->text($this->lng->txt('title')),
74 'description' => $this->ui_factory->table()->column()->text($this->lng->txt('description')),
75 'prefix' => $this->ui_factory->table()->column()->text($this->lng->txt('prefix')),
76 'language' => $this->ui_factory->table()->column()->text($this->lng->txt('in_use')),
77 'objects' => $this->ui_factory->table()->column()->text($this->lng->txt('objects')),
78 'role' => $this->ui_factory->table()->column()->text($this->lng->txt('role'))
79 ];
80 }
81
82 private function getRecords(): array
83 {
84 $dataConnector = new ilLTIDataConnector();
85
86 $consumer_data = $dataConnector->getGlobalToolConsumerSettings();
87
88 $result = array();
89
90 foreach ($consumer_data as $cons) {
91 $result[] = array(
92 "id" => $cons->getExtConsumerId(),
93 "active" => $cons->getActive(),
94 "title" => $cons->getTitle(),
95 "description" => $cons->getDescription(),
96 "prefix" => $cons->getPrefix(),
97 "language" => $cons->getLanguage(),
98 "role" => $cons->getRole(),
99 );
100 }
101
102 return $result;
103 }
104
108 private function getActions(): array
109 {
110 if (!$this->isEditable()) {
111 return [];
112 }
113
114 $df = new \ILIAS\Data\Factory();
115 $here_uri = $df->uri($this->request->getUri()->__toString());
116 $url_builder = new URLBuilder($here_uri);
117
118 $query_params_namespace = ['lti_consumer_table'];
119 list($url_builder, $id_token, $action_token) = $url_builder->acquireParameters(
120 $query_params_namespace,
121 "consumer_id",
122 "action"
123 );
124
125 $query = $this->wrapper->query();
126 if ($query->has($action_token->getName())) {
127 $action = $query->retrieve($action_token->getName(), $this->refinery->to()->string());
128 $ids = $query->retrieve($id_token->getName(), $this->refinery->custom()->transformation(fn($v) => $v));
129 $id = $ids[0] ?? null;
130
131 switch ($action) {
132 case "edit":
133 $this->ctrl->setParameterByClass(ilObjLTIAdministrationGUI::class, 'cid', $id);
134 $this->ctrl->redirectByClass(ilObjLTIAdministrationGUI::class, 'editConsumer');
135 break;
136 case "delete":
137 $this->ctrl->setParameterByClass(ilObjLTIAdministrationGUI::class, 'cid', $id);
138 $this->ctrl->redirectByClass(ilObjLTIAdministrationGUI::class, 'deleteLTIConsumer');
139 break;
140 case "status":
141 $this->ctrl->setParameterByClass(ilObjLTIAdministrationGUI::class, 'cid', $id);
142 $this->ctrl->redirectByClass(ilObjLTIAdministrationGUI::class, 'changeStatusLTIConsumer');
143 break;
144 }
145 }
146
147 return [
148 $this->ui_factory->table()->action()->single(
149 $this->lng->txt('edit'),
150 $url_builder->withParameter($action_token, "edit"),
151 $id_token
152 ),
153 $this->ui_factory->table()->action()->single(
154 $this->lng->txt('delete'),
155 $url_builder->withParameter($action_token, "delete"),
156 $id_token
157 ),
158 $this->ui_factory->table()->action()->single(
159 $this->lng->txt('activate') . " / " . $this->lng->txt('deactivate'),
160 $url_builder->withParameter($action_token, "status"),
161 $id_token
162 )
163 ];
164 }
165
170 public function getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters): Generator
171 {
172 foreach ($this->records as $record) {
173 $record["active"] = $this->ui_factory->symbol()->icon()->custom(
174 $record["active"] ?
175 'assets/images/standard/icon_ok.svg' :
176 'assets/images/standard/icon_not_ok.svg',
177 $record["active"] ? $this->lng->txt('active') : $this->lng->txt('inactive'),
178 Icon::MEDIUM
179 );
180
181 $role = ilObjectFactory::getInstanceByObjId($record['role'], false);
182 if ($role instanceof ilObjRole) {
183 $record['role'] = $role->getTitle();
184 } else {
185 $record['role'] = '';
186 }
187
188 $record["objects"] = '';
189 $obj_types = ilObjLTIAdministration::getActiveObjectTypes($record["id"]);
190 if ($obj_types) {
191 foreach ($obj_types as $obj_type) {
192 $record["objects"] .= $GLOBALS['DIC']->language()->txt('objs_' . $obj_type) . '<br/>';
193 }
194 }
195
196 yield $row_builder->buildDataRow((string) $record["id"], $record);
197 }
198 }
199
200 public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
201 {
202 return count($this->records);
203 }
204
208 public function getHtml(): string
209 {
210 $table = $this->ui_factory->table()
211 ->data($this->lng->txt('lti_object_consumer'), $this->getColumns(), $this)
212 ->withOrder(new Order('title', Order::ASC))
213 ->withActions($this->getActions())
214 ->withRequest($this->request);
215
216 return $this->ui_renderer->render($table);
217 }
218
219 public function isEditable(): bool
220 {
221 return $this->editable;
222 }
223
224 public function setEditable(bool $a_editable): void
225 {
226 $this->editable = $a_editable;
227 }
228}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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
language handling
static getActiveObjectTypes(int $a_consumer_id)
Class ilObjRole.
TableGUI class for LTI consumer listing.
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
ServerRequestInterface RequestInterface $request
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:29
buildDataRow(string $id, array $record)
This is how the factory for UI elements looks.
Definition: Factory.php:38
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
$GLOBALS["DIC"]
Definition: wac.php:54