ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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(str_replace('\\', '', self::class))
68 ->withOrder(new \ILIAS\Data\Order('title', \ILIAS\Data\Order::ASC))
69 ->withRange(new \ILIAS\Data\Range(0, 100))
70 ->withActions($this->getActions())
71 ->withRequest($this->http_request);
72 }
73
77 private function getColumnDefinition(): array
78 {
79 return [
80 'title' => $this->ui_factory
81 ->table()
82 ->column()
83 ->text($this->lng->txt('saml_tab_head_idp'))
84 ->withIsSortable(true),
85 'active' => $this->ui_factory
86 ->table()
87 ->column()
88 ->boolean(
89 $this->lng->txt('status'),
90 $this->ui_factory->symbol()->icon()->custom(
91 'assets/images/standard/icon_ok.svg',
92 $this->lng->txt('active'),
93 'small'
94 ),
95 $this->ui_factory->symbol()->icon()->custom(
96 'assets/images/standard/icon_not_ok.svg',
97 $this->lng->txt('inactive'),
98 'small'
99 )
100 )
101 ->withIsSortable(true)
102 ->withOrderingLabels(
103 "{$this->lng->txt('status')}, {$this->lng->txt('active')} {$this->lng->txt('order_option_first')}",
104 "{$this->lng->txt('status')}, {$this->lng->txt('inactive')} {$this->lng->txt('order_option_first')}"
105 )
106 ];
107 }
108
112 private function getActions(): array
113 {
114 if (!$this->has_write_access) {
115 return [];
116 }
117
118 return [
119 'edit' => $this->ui_factory->table()->action()->single(
120 $this->lng->txt('edit'),
121 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_SHOW_IDP_SETTINGS),
122 $this->row_id_token
123 ),
124 'activate' => $this->ui_factory->table()->action()->single(
125 $this->lng->txt('activate'),
126 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_ACTIVATE_IDP),
127 $this->row_id_token
128 ),
129 'deactivate' => $this->ui_factory->table()->action()->single(
130 $this->lng->txt('deactivate'),
131 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_DEACTIVATE_IDP),
132 $this->row_id_token
133 ),
134 'delete' => $this->ui_factory->table()->action()->single(
135 $this->lng->txt('delete'),
136 $this->url_builder->withParameter($this->action_parameter_token, self::TABLE_ACTION_CONFIRM_DELETE_IDP),
137 $this->row_id_token
138 )
139 ];
140 }
141
145 private function getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order): array
146 {
147 $records = $this->idps;
148
149 [$order_field, $order_direction] = $order->join([], static function ($ret, $key, $value) {
150 return [$key, $value];
151 });
152
153 usort($records, static function (ilSamlIdp $left, ilSamlIdp $right) use ($order_field): int {
154 if ($order_field === 'title') {
155 return ilStr::strCmp($left->getEntityId(), $right->getEntityId());
156 }
157
158 return (int) $right->isActive() <=> (int) $left->isActive();
159 });
160
161 if ($order_direction === \ILIAS\Data\Order::DESC) {
162 $records = array_reverse($records);
163 }
164
165 $records = array_slice($records, $range->getStart(), $range->getLength());
166
167 return $records;
168 }
169
170 public function getRows(
171 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
172 array $visible_column_ids,
173 \ILIAS\Data\Range $range,
174 \ILIAS\Data\Order $order,
175 mixed $additional_viewcontrol_data,
176 mixed $filter_data,
177 mixed $additional_parameters
178 ): Generator {
179 foreach ($this->getRecords($range, $order) as $item) {
180 yield $row_builder
181 ->buildDataRow((string) $item->getIdpId(), [
182 'title' => $item->getEntityId(),
183 'active' => $item->isActive()
184 ])
185 ->withDisabledAction(
186 'activate',
187 $item->isActive(),
188 )
189 ->withDisabledAction(
190 'deactivate',
191 !$item->isActive(),
192 );
193 }
194 }
195
196 public function getTotalRowCount(
197 mixed $additional_viewcontrol_data,
198 mixed $filter_data,
199 mixed $additional_parameters
200 ): ?int {
201 return count($this->idps);
202 }
203}
language handling
getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order)
ILIAS UI URLBuilderToken $row_id_token
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...
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)
getRows(\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, \ILIAS\Data\Range $range, \ILIAS\Data\Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
static getAllIdps()
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
static _getHttpPath()
return['delivery_method'=> 'php',]
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...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31