ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ServerTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
26{
27 private \ILIAS\UI\URLBuilder $url_builder;
28 private \ILIAS\UI\URLBuilderToken $action_parameter_token;
29 private \ILIAS\UI\URLBuilderToken $row_id_token;
30
34 public function __construct(
35 private array $servers,
36 private \ilLDAPSettingsGUI $parent_gui,
37 private \ILIAS\UI\Factory $ui_factory,
38 private \ILIAS\UI\Renderer $ui_renderer,
39 private \ilLanguage $lng,
40 private \ilCtrlInterface $ctrl,
41 private \Psr\Http\Message\ServerRequestInterface $http_request,
42 private \ILIAS\Data\URI $action_url,
43 private bool $has_write_access,
44 private bool $has_read_access
45 ) {
46 [
50 ] = (new \ILIAS\UI\URLBuilder($action_url))->acquireParameters(
51 ['ldap', 'servers'],
52 'table_action',
53 'server_id'
54 );
55 }
56
60 private function getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order): array
61 {
62 $servers = $this->servers;
63
64 [$order_field, $order_direction] = $order->join([], static function ($ret, $key, $value) {
65 return [$key, $value];
66 });
67
68 array_walk(
69 $servers,
70 static function (array &$server): void {
71 $server['user'] = \count(\ilObjUser::_getExternalAccountsByAuthMode('ldap_' . $server['server_id']));
72 }
73 );
74
75 $records = \ilArrayUtil::sortArray(
76 $servers,
77 $order_field,
78 strtolower($order_direction),
79 \in_array($order_field, ['user', 'active'], true)
80 );
81
82 if ($order_field === 'active') {
83 $records = array_reverse($records);
84 }
85
86 $records = \array_slice($records, $range->getStart(), $range->getLength());
87
88 return $records;
89 }
90
91 public function getRows(
92 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
93 array $visible_column_ids,
95 \ILIAS\Data\Order $order,
96 mixed $additional_viewcontrol_data,
97 mixed $filter_data,
98 mixed $additional_parameters
99 ): \Generator {
100 foreach ($this->getRecords($range, $order) as $server) {
101 $title = $server['name'];
102 if ($this->has_read_access) {
103 $this->ctrl->setParameter($this->parent_gui, 'ldap_server_id', $server['server_id']);
104 $title = $this->ui_renderer->render(
105 $this->ui_factory->link()->standard(
106 $title,
107 $this->ctrl->getLinkTarget($this->parent_gui, 'editServerSettings')
108 )
109 );
110 }
111
112 yield $row_builder
113 ->buildDataRow(
114 (string) $server['server_id'],
115 [
116 'name' => $title,
117 'active' => (bool) $server['active'],
118 'user' => $server['user']
119 ]
120 )
121 ->withDisabledAction(
122 'activateServer',
123 (bool) $server['active'],
124 )
125 ->withDisabledAction(
126 'deactivateServer',
127 !$server['active'],
128 );
129 }
130 }
131
132 public function getTotalRowCount(
133 mixed $additional_viewcontrol_data,
134 mixed $filter_data,
135 mixed $additional_parameters
136 ): ?int {
137 return \count($this->servers);
138 }
139
143 private function getColumnDefinition(): array
144 {
145 return [
146 'active' => $this->ui_factory
147 ->table()
148 ->column()
149 ->boolean(
150 $this->lng->txt('status'),
151 $this->ui_factory->symbol()->icon()->custom(
152 'assets/images/standard/icon_ok.svg',
153 $this->lng->txt('active'),
154 'small'
155 ),
156 $this->ui_factory->symbol()->icon()->custom(
157 'assets/images/standard/icon_not_ok.svg',
158 $this->lng->txt('inactive'),
159 'small'
160 )
161 )
162 ->withIsSortable(true)
163 ->withOrderingLabels(
164 "{$this->lng->txt('status')}, {$this->lng->txt('active')} {$this->lng->txt('order_option_first')}",
165 "{$this->lng->txt('status')}, {$this->lng->txt('inactive')} {$this->lng->txt('order_option_first')}"
166 ),
167 'name' => $this->ui_factory
168 ->table()
169 ->column()
170 ->text($this->lng->txt('title'))
171 ->withIsSortable(true),
172 'user' => $this->ui_factory
173 ->table()
174 ->column()
175 ->number($this->lng->txt('user'))
176 ->withIsSortable(true)
177 ];
178 }
179
183 private function getActions(): array
184 {
185 $actions = [];
186
187 if ($this->has_read_access || $this->has_write_access) {
188 $actions['editServerSettings'] = $this->ui_factory->table()->action()->single(
189 $this->has_write_access ? $this->lng->txt('edit') : $this->lng->txt('view'),
190 $this->url_builder->withParameter($this->action_parameter_token, 'editServerSettings'),
191 $this->row_id_token
192 );
193 }
194
195 if ($this->has_write_access) {
196 $actions['activateServer'] = $this->ui_factory->table()->action()->single(
197 $this->lng->txt('activate'),
198 $this->url_builder->withParameter($this->action_parameter_token, 'activateServer'),
199 $this->row_id_token
200 );
201
202 $actions['deactivateServer'] = $this->ui_factory->table()->action()->single(
203 $this->lng->txt('deactivate'),
204 $this->url_builder->withParameter($this->action_parameter_token, 'deactivateServer'),
205 $this->row_id_token
206 );
207
208 $actions['confirmDeleteServerSettings'] = $this->ui_factory->table()->action()->single(
209 $this->lng->txt('delete'),
210 $this->url_builder->withParameter($this->action_parameter_token, 'confirmDeleteServerSettings'),
211 $this->row_id_token
212 );
213 }
214
215 return $actions;
216 }
217
219 {
220 return $this->ui_factory
221 ->table()
222 ->data(
223 $this,
224 $this->lng->txt('ldap_servers'),
225 $this->getColumnDefinition(),
226 )
227 ->withId(str_replace('\\', '', self::class))
228 ->withOrder(new \ILIAS\Data\Order('title', \ILIAS\Data\Order::ASC))
229 ->withRange(new Range(0, 100))
230 ->withActions($this->getActions())
231 ->withRequest($this->http_request);
232 }
233}
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:27
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:91
ILIAS UI URLBuilderToken $action_parameter_token
Definition: ServerTable.php:28
__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, private bool $has_read_access)
Definition: ServerTable.php:34
getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order)
Definition: ServerTable.php:60
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:29
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