ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
LDAPRoleMappingTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25use ILIAS\UI\Factory as UIFactory;
28use Psr\Http\Message\ServerRequestInterface;
29use ILIAS\UI\Component\Table\Data as DataTable;
31
33{
43 private ?array $records = null;
44
45 public function __construct(
46 private readonly ServerRequestInterface $http_request,
47 private readonly ilLanguage $lng,
48 private readonly UIFactory $ui_factory,
49 private readonly int $server_id,
50 private readonly ilObjectDataCache $object_data_cache,
51 private readonly ilRbacReview $rbac_review,
52 private readonly \ILIAS\Data\URI $action_url
53 ) {
54 }
55
56 public function getRows(
57 ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
58 array $visible_column_ids,
60 Order $order,
61 mixed $additional_viewcontrol_data,
62 mixed $filter_data,
63 mixed $additional_parameters
64 ): Generator {
65 $records = $this->getRecords($range, $order);
66 foreach ($records as $record) {
67 yield $row_builder->buildDataRow((string) $record['id'], $record);
68 }
69 }
70
71 public function initRecords(): void
72 {
73 if ($this->records === null) {
74 $this->records = [];
75 $mapping_instance = ilLDAPRoleGroupMappingSettings::_getInstanceByServerId($this->server_id);
76 $mappings = $mapping_instance->getMappings();
77 foreach ($mappings as $item) {
78 $title = $this->object_data_cache->lookupTitle($this->rbac_review->getObjectOfRole((int) $item['role']));
79 $this->records[] = [
80 'id' => $item['mapping_id'],
81 'title' => ilStr::shortenTextExtended($title, 30, true),
82 'role' => $item['role_name'],
83 'dn' => $item['dn'],
84 'url' => $item['url'],
85 'member_attribute' => $item['member_attribute'],
86 'info' => ilLegacyFormElementsUtil::prepareFormOutput($item['info'])
87 ];
88 }
89 }
90 }
91
92 public function getComponent(): DataTable
93 {
94 $query_params_namespace = ['ldap', 'role', 'mapping'];
95 $url_builder = new URLBuilder($this->action_url);
96 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
97 $query_params_namespace,
98 'table_action',
99 'mapping_ids'
100 );
101
102 return $this->ui_factory->table()
103 ->data(
104 $this,
105 $this->lng->txt('mail_templates'),
106 $this->getColumns()
107 )
108 ->withTitle($this->lng->txt('ldap_role_group_assignments'))
109 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
110 ->withId(
111 'ldap_role_mapping_table'
112 )
113 ->withOrder(new Order('title', Order::DESC))
114 ->withRequest($this->http_request);
115 }
116
117 public function getTotalRowCount(
118 mixed $additional_viewcontrol_data,
119 mixed $filter_data,
120 mixed $additional_parameters
121 ): ?int {
122 $this->initRecords();
123
124 return count((array) $this->records);
125 }
126
138 private function getRecords(Range $range, Order $order): array
139 {
140 $this->initRecords();
141 $records = $this->records;
142
143 if ($order) {
144 $records = $this->orderRecords($records, $order);
145 }
146
147 if ($range) {
148 $records = $this->limitRecords($records, $range);
149 }
150
151 return $records;
152 }
153
157 public function getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token): array
158 {
159 $actions = [];
160 $actions['delete'] = $this->ui_factory->table()->action()->multi(
161 $this->lng->txt('delete'),
162 $url_builder->withParameter($action_parameter_token, 'confirmDeleteRoleMapping'),
163 $row_id_token
164 );
165
166 $actions['copy'] = $this->ui_factory->table()->action()->single(
167 $this->lng->txt('copy'),
168 $url_builder->withParameter($action_parameter_token, 'addRoleMapping'),
169 $row_id_token
170 );
171
172 $actions['edit'] = $this->ui_factory->table()->action()->single(
173 $this->lng->txt('edit'),
174 $url_builder->withParameter($action_parameter_token, 'editRoleMapping'),
175 $row_id_token
176 );
177
178 return $actions;
179 }
180
201 private function limitRecords(array $records, Range $range): array
202 {
203 return array_slice($records, $range->getStart(), $range->getLength());
204 }
205
226 private function orderRecords(array $records, Order $order): array
227 {
228 [$order_field, $order_direction] = $order->join(
229 [],
230 fn($ret, $key, $value) => [$key, $value]
231 );
232 usort($records, static fn(array $left, array $right): int => ilStr::strCmp(
233 $left[$order_field] ?? '',
234 $right[$order_field] ?? ''
235 ));
236
237 if ($order_direction === Order::DESC) {
238 $records = array_reverse($records);
239 }
240
241 return $records;
242 }
243
247 private function getColumns(): array
248 {
249 return [
250 'title' => $this->ui_factory->table()->column()->text($this->lng->txt('title')),
251 'role' => $this->ui_factory->table()->column()->text($this->lng->txt('obj_role')),
252 'dn' => $this->ui_factory->table()->column()->text($this->lng->txt('ldap_group_dn')),
253 'url' => $this->ui_factory->table()->column()->text($this->lng->txt('ldap_server')),
254 'member_attribute' => $this->ui_factory->table()->column()->text($this->lng->txt('ldap_group_member')),
255 'info' => $this->ui_factory->table()->column()->text($this->lng->txt('ldap_info_text')),
256 ];
257 }
258}
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
join($init, callable $fn)
Definition: Order.php:75
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
Definition: URLBuilder.php:166
orderRecords(array $records, Order $order)
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...
limitRecords(array $records, Range $range)
getRecords(Range $range, Order $order)
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
getRows(ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
__construct(private readonly ServerRequestInterface $http_request, private readonly ilLanguage $lng, private readonly UIFactory $ui_factory, private readonly int $server_id, private readonly ilObjectDataCache $object_data_cache, private readonly ilRbacReview $rbac_review, private readonly \ILIAS\Data\URI $action_url)
static _getInstanceByServerId(int $a_server_id)
Get instance of class.
language handling
static prepareFormOutput($a_str, bool $a_strip=false)
class ilObjectDataCache
class ilRbacReview Contains Review functions of core Rbac.
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
A Column describes the form of presentation for a certain aspect of data, i.e.
Definition: Column.php:28
This describes a Data Table.
Definition: Data.php:33
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31