ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSamlIdpTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
24 private array $idps;
28
29 public function __construct(
30 private ilSamlSettingsGUI $parent_gui,
31 private \ILIAS\UI\Factory $ui_factory,
32 private \ILIAS\UI\Renderer $ui_renderer,
33 private ilLanguage $lng,
34 private ilCtrlInterface $ctrl,
35 private \Psr\Http\Message\ServerRequestInterface $http_request,
36 private \ILIAS\Data\Factory $df,
37 private string $parent_cmd,
38 private bool $has_write_access
39 ) {
40 $this->idps = ilSamlIdp::getAllIdps();
41
42 $form_action = $this->df->uri(
43 ilUtil::_getHttpPath() . '/' .
44 $this->ctrl->getLinkTarget($this->parent_gui, $this->parent_cmd)
45 );
46
47 [
51 ] = (new ILIAS\UI\URLBuilder($form_action))->acquireParameters(
52 ['saml', 'idps'],
53 'table_action',
54 'idp_id'
55 );
56 }
57
58 public function get(): \ILIAS\UI\Component\Table\Data
59 {
60 return $this->ui_factory
61 ->table()
62 ->data(
63 $this,
64 $this->lng->txt('auth_saml_idps'),
65 $this->getColumnDefinition(),
66 )
67 ->withId(self::class)
68 ->withOrder(new \ILIAS\Data\Order('title', \ILIAS\Data\Order::ASC))
69 ->withActions($this->getActions())
70 ->withRequest($this->http_request);
71 }
72
76 private function getColumnDefinition(): array
77 {
78 return [
79 'title' => $this->ui_factory
80 ->table()
81 ->column()
82 ->text($this->lng->txt('saml_tab_head_idp'))
83 ->withIsSortable(true),
84 'active' => $this->ui_factory
85 ->table()
86 ->column()
87 ->boolean(
88 $this->lng->txt('status'),
89 $this->ui_factory->symbol()->icon()->custom(
90 'assets/images/standard/icon_ok.svg',
91 $this->lng->txt('active'),
92 'small'
93 ),
94 $this->ui_factory->symbol()->icon()->custom(
95 'assets/images/standard/icon_not_ok.svg',
96 $this->lng->txt('inactive'),
97 'small'
98 )
99 )
100 ->withIsSortable(true)
101 ->withOrderingLabels(
102 "{$this->lng->txt('status')}, {$this->lng->txt('active')} {$this->lng->txt('order_option_first')}",
103 "{$this->lng->txt('status')}, {$this->lng->txt('inactive')} {$this->lng->txt('order_option_first')}"
104 )
105 ];
106 }
107
111 private function getActions(): array
112 {
113 if (!$this->has_write_access) {
114 return [];
115 }
116
117 return [
118 'edit' => $this->ui_factory->table()->action()->single(
119 $this->lng->txt('edit'),
120 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_SHOW_IDP_SETTINGS),
121 $this->row_id_token
122 ),
123 'activate' => $this->ui_factory->table()->action()->single(
124 $this->lng->txt('activate'),
125 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_ACTIVATE_IDP),
126 $this->row_id_token
127 ),
128 'deactivate' => $this->ui_factory->table()->action()->single(
129 $this->lng->txt('deactivate'),
130 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_DEACTIVATE_IDP),
131 $this->row_id_token
132 ),
133 'delete' => $this->ui_factory->table()->action()->single(
134 $this->lng->txt('delete'),
135 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_CONFIRM_DELETE_IDP),
136 $this->row_id_token
137 )
138 ];
139 }
140
144 private function getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order): array
145 {
146 $records = $this->idps;
147
148 [$order_field, $order_direction] = $order->join([], static function ($ret, $key, $value) {
149 return [$key, $value];
150 });
151
152 usort($records, static function (ilSamlIdp $left, ilSamlIdp $right) use ($order_field): int {
153 if ($order_field === 'title') {
154 return ilStr::strCmp($left->getEntityId(), $right->getEntityId());
155 }
156
157 return (int) $right->isActive() <=> (int) $left->isActive();
158 });
159
160 if ($order_direction === \ILIAS\Data\Order::DESC) {
161 $records = array_reverse($records);
162 }
163
164 $records = array_slice($records, $range->getStart(), $range->getLength());
165
166 return $records;
167 }
168
169 public function getRows(
170 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
171 array $visible_column_ids,
172 \ILIAS\Data\Range $range,
173 \ILIAS\Data\Order $order,
174 ?array $filter_data,
175 ?array $additional_parameters
176 ): Generator {
177 foreach ($this->getRecords($range, $order) as $item) {
178 yield $row_builder
179 ->buildDataRow((string) $item->getIdpId(), [
180 'title' => $item->getEntityId(),
181 'active' => $item->isActive()
182 ])
183 ->withDisabledAction(
184 'activate',
185 $item->isActive(),
186 )
187 ->withDisabledAction(
188 'deactivate',
189 !$item->isActive(),
190 );
191 }
192 }
193
194 public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
195 {
196 return count($this->idps);
197 }
198}
language handling
getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order)
ILIAS UI URLBuilderToken $row_id_token
ILIAS UI URLBuilder $url_builder
ILIAS UI URLBuilderToken $action_parameter_token
__construct(private ilSamlSettingsGUI $parent_gui, private \ILIAS\UI\Factory $ui_factory, private \ILIAS\UI\Renderer $ui_renderer, private ilLanguage $lng, private ilCtrlInterface $ctrl, private \Psr\Http\Message\ServerRequestInterface $http_request, private \ILIAS\Data\Factory $df, private string $parent_cmd, private bool $has_write_access)
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...
getRows(\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, \ILIAS\Data\Range $range, \ILIAS\Data\Order $order, ?array $filter_data, ?array $additional_parameters)
static getAllIdps()
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
static _getHttpPath()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31