ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ServerTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 private \ILIAS\UI\URLBuilder $url_builder;
26 private \ILIAS\UI\URLBuilderToken $action_parameter_token;
27 private \ILIAS\UI\URLBuilderToken $row_id_token;
28
32 public function __construct(
33 private array $servers,
34 private \ilLDAPSettingsGUI $parent_gui,
35 private \ILIAS\UI\Factory $ui_factory,
36 private \ILIAS\UI\Renderer $ui_renderer,
37 private \ilLanguage $lng,
38 private \ilCtrlInterface $ctrl,
39 private \Psr\Http\Message\ServerRequestInterface $http_request,
40 private \ILIAS\Data\URI $action_url,
41 private bool $has_write_access
42 ) {
43 [
47 ] = (new \ILIAS\UI\URLBuilder($action_url))->acquireParameters(
48 ['ldap', 'servers'],
49 'table_action',
50 'server_id'
51 );
52 }
53
57 private function getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order): array
58 {
59 $servers = $this->servers;
60
61 [$order_field, $order_direction] = $order->join([], static function ($ret, $key, $value) {
62 return [$key, $value];
63 });
64
65 array_walk(
66 $servers,
67 static function (array &$server): void {
68 $server['user'] = \count(\ilObjUser::_getExternalAccountsByAuthMode('ldap_' . $server['server_id']));
69 }
70 );
71
72 $records = \ilArrayUtil::sortArray(
73 $servers,
74 $order_field,
75 strtolower($order_direction),
76 \in_array($order_field, ['user', 'active'], true)
77 );
78
79 if ($order_field === 'active') {
80 $records = array_reverse($records);
81 }
82
83 $records = \array_slice($records, $range->getStart(), $range->getLength());
84
85 return $records;
86 }
87
88 public function getRows(
89 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
90 array $visible_column_ids,
92 \ILIAS\Data\Order $order,
93 mixed $additional_viewcontrol_data,
94 mixed $filter_data,
95 mixed $additional_parameters
96 ): \Generator {
97 foreach ($this->getRecords($range, $order) as $server) {
98 $title = $server['name'];
99 if ($this->has_write_access) {
100 $this->ctrl->setParameter($this->parent_gui, 'ldap_server_id', $server['server_id']);
101 $title = $this->ui_renderer->render(
102 $this->ui_factory->link()->standard(
103 $title,
104 $this->ctrl->getLinkTarget($this->parent_gui, 'editServerSettings')
105 )
106 );
107 }
108
109 yield $row_builder
110 ->buildDataRow(
111 (string) $server['server_id'],
112 [
113 'name' => $title,
114 'active' => (bool) $server['active'],
115 'user' => $server['user']
116 ]
117 )
118 ->withDisabledAction(
119 'activateServer',
120 (bool) $server['active'],
121 )
122 ->withDisabledAction(
123 'deactivateServer',
124 !$server['active'],
125 );
126 }
127 }
128
129 public function getTotalRowCount(
130 mixed $additional_viewcontrol_data,
131 mixed $filter_data,
132 mixed $additional_parameters
133 ): ?int {
134 return \count($this->servers);
135 }
136
140 private function getColumnDefinition(): array
141 {
142 return [
143 'active' => $this->ui_factory
144 ->table()
145 ->column()
146 ->boolean(
147 $this->lng->txt('status'),
148 $this->ui_factory->symbol()->icon()->custom(
149 'assets/images/standard/icon_ok.svg',
150 $this->lng->txt('active'),
151 'small'
152 ),
153 $this->ui_factory->symbol()->icon()->custom(
154 'assets/images/standard/icon_not_ok.svg',
155 $this->lng->txt('inactive'),
156 'small'
157 )
158 )
159 ->withIsSortable(true)
160 ->withOrderingLabels(
161 "{$this->lng->txt('status')}, {$this->lng->txt('active')} {$this->lng->txt('order_option_first')}",
162 "{$this->lng->txt('status')}, {$this->lng->txt('inactive')} {$this->lng->txt('order_option_first')}"
163 ),
164 'name' => $this->ui_factory
165 ->table()
166 ->column()
167 ->text($this->lng->txt('title'))
168 ->withIsSortable(true),
169 'user' => $this->ui_factory
170 ->table()
171 ->column()
172 ->number($this->lng->txt('user'))
173 ->withIsSortable(true)
174 ];
175 }
176
180 private function getActions(): array
181 {
182 if (!$this->has_write_access) {
183 return [];
184 }
185
186 return [
187 'editServerSettings' => $this->ui_factory->table()->action()->single(
188 $this->lng->txt('edit'),
189 $this->url_builder->withParameter($this->action_parameter_token, 'editServerSettings'),
190 $this->row_id_token
191 ),
192 'activateServer' => $this->ui_factory->table()->action()->single(
193 $this->lng->txt('activate'),
194 $this->url_builder->withParameter($this->action_parameter_token, 'activateServer'),
195 $this->row_id_token
196 ),
197 'deactivateServer' => $this->ui_factory->table()->action()->single(
198 $this->lng->txt('deactivate'),
199 $this->url_builder->withParameter($this->action_parameter_token, 'deactivateServer'),
200 $this->row_id_token
201 ),
202 'confirmDeleteServerSettings' => $this->ui_factory->table()->action()->single(
203 $this->lng->txt('delete'),
204 $this->url_builder->withParameter($this->action_parameter_token, 'confirmDeleteServerSettings'),
205 $this->row_id_token
206 )
207 ];
208 }
209
211 {
212 return $this->ui_factory
213 ->table()
214 ->data(
215 $this,
216 $this->lng->txt('ldap_servers'),
217 $this->getColumnDefinition(),
218 )
219 ->withId(self::class)
220 ->withOrder(new \ILIAS\Data\Order('title', \ILIAS\Data\Order::ASC))
221 ->withActions($this->getActions())
222 ->withRequest($this->http_request);
223 }
224}
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
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
ILIAS UI URLBuilder $url_builder
Definition: ServerTable.php:25
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)
Definition: ServerTable.php:88
ILIAS UI URLBuilderToken $action_parameter_token
Definition: ServerTable.php:26
getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order)
Definition: ServerTable.php:57
__construct(private array $servers, private \ilLDAPSettingsGUI $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\URI $action_url, private bool $has_write_access)
Definition: ServerTable.php:32
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 URLBuilderToken $row_id_token
Definition: ServerTable.php:27
Definition: UI.php:24
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
language handling
static _getExternalAccountsByAuthMode(string $a_auth_mode, bool $a_read_auth_default=false)
Get list of external account by authentication method Note: If login == ext_account for two user with...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An entity that renders components to a string output.
Definition: Renderer.php:31
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
$server
Definition: shib_login.php:28