ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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(
171 DataRowBuilder $row_builder,
172 array $visible_column_ids,
174 Order $order,
175 mixed $additional_viewcontrol_data,
176 mixed $filter_data,
177 mixed $additional_parameters
178 ): Generator {
179 foreach ($this->records as $record) {
180 $record["active"] = $this->ui_factory->symbol()->icon()->custom(
181 $record["active"] ?
182 'assets/images/standard/icon_ok.svg' :
183 'assets/images/standard/icon_not_ok.svg',
184 $record["active"] ? $this->lng->txt('active') : $this->lng->txt('inactive'),
185 Icon::MEDIUM
186 );
187
188 $role = ilObjectFactory::getInstanceByObjId($record['role'], false);
189 if ($role instanceof ilObjRole) {
190 $record['role'] = $role->getTitle();
191 } else {
192 $record['role'] = '';
193 }
194
195 $record["objects"] = '';
196 $obj_types = ilObjLTIAdministration::getActiveObjectTypes($record["id"]);
197 if ($obj_types) {
198 foreach ($obj_types as $obj_type) {
199 $record["objects"] .= $GLOBALS['DIC']->language()->txt('objs_' . $obj_type) . '<br/>';
200 }
201 }
202
203 yield $row_builder->buildDataRow((string) $record["id"], $record);
204 }
205 }
206
207 public function getTotalRowCount(
208 mixed $additional_viewcontrol_data,
209 mixed $filter_data,
210 mixed $additional_parameters
211 ): ?int {
212 return count($this->records);
213 }
214
218 public function getHtml(): string
219 {
220 $table = $this->ui_factory->table()
221 ->data($this->lng->txt('lti_object_consumer'), $this->getColumns(), $this)
222 ->withOrder(new Order('title', Order::ASC))
223 ->withActions($this->getActions())
224 ->withRequest($this->request);
225
226 return $this->ui_renderer->render($table);
227 }
228
229 public function isEditable(): bool
230 {
231 return $this->editable;
232 }
233
234 public function setEditable(bool $a_editable): void
235 {
236 $this->editable = $a_editable;
237 }
238}
$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.
getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
ServerRequestInterface RequestInterface $request
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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