ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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 private readonly bool $has_write_access
54 ) {
55 }
56
57 public function getRows(
58 ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
59 array $visible_column_ids,
61 Order $order,
62 mixed $additional_viewcontrol_data,
63 mixed $filter_data,
64 mixed $additional_parameters
65 ): Generator {
66 $records = $this->getRecords($range, $order);
67 foreach ($records as $record) {
68 yield $row_builder->buildDataRow((string) $record['id'], $record);
69 }
70 }
71
72 public function initRecords(): void
73 {
74 if ($this->records === null) {
75 $this->records = [];
76 $mapping_instance = ilLDAPRoleGroupMappingSettings::_getInstanceByServerId($this->server_id);
77 $mappings = $mapping_instance->getMappings();
78 foreach ($mappings as $item) {
79 $title = $this->object_data_cache->lookupTitle($this->rbac_review->getObjectOfRole((int) $item['role']));
80 $this->records[] = [
81 'id' => $item['mapping_id'],
82 'title' => ilStr::shortenTextExtended($title, 30, true),
83 'role' => $item['role_name'],
84 'dn' => $item['dn'],
85 'url' => $item['url'],
86 'member_attribute' => $item['member_attribute'],
87 'info' => ilLegacyFormElementsUtil::prepareFormOutput($item['info'])
88 ];
89 }
90 }
91 }
92
93 public function getComponent(): DataTable
94 {
95 $query_params_namespace = ['ldap', 'role', 'mapping'];
96 $url_builder = new URLBuilder($this->action_url);
97 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
98 $query_params_namespace,
99 'table_action',
100 'mapping_ids'
101 );
102
103 return $this->ui_factory->table()
104 ->data(
105 $this,
106 $this->lng->txt('mail_templates'),
107 $this->getColumns()
108 )
109 ->withTitle($this->lng->txt('ldap_role_group_assignments'))
110 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
111 ->withId(
112 'ldap_role_mapping_table'
113 )
114 ->withOrder(new Order('title', Order::DESC))
115 ->withRange(new Range(0, 100))
116 ->withRequest($this->http_request);
117 }
118
119 public function getTotalRowCount(
120 mixed $additional_viewcontrol_data,
121 mixed $filter_data,
122 mixed $additional_parameters
123 ): ?int {
124 $this->initRecords();
125
126 return count((array) $this->records);
127 }
128
140 private function getRecords(Range $range, Order $order): array
141 {
142 $this->initRecords();
143 $records = $this->records;
144
145 if ($order) {
146 $records = $this->orderRecords($records, $order);
147 }
148
149 if ($range) {
150 $records = $this->limitRecords($records, $range);
151 }
152
153 return $records;
154 }
155
159 public function getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token): array
160 {
161 $actions = [];
162
163 if ($this->has_write_access) {
164 $actions['delete'] = $this->ui_factory->table()->action()->multi(
165 $this->lng->txt('delete'),
166 $url_builder->withParameter($action_parameter_token, 'confirmDeleteRoleMapping'),
167 $row_id_token
168 );
169
170 $actions['copy'] = $this->ui_factory->table()->action()->single(
171 $this->lng->txt('copy'),
172 $url_builder->withParameter($action_parameter_token, 'addRoleMapping'),
173 $row_id_token
174 );
175 }
176
177 $actions['edit'] = $this->ui_factory->table()->action()->single(
178 $this->has_write_access ? $this->lng->txt('edit') : $this->lng->txt('view'),
179 $url_builder->withParameter($action_parameter_token, 'editRoleMapping'),
180 $row_id_token
181 );
182
183 return $actions;
184 }
185
206 private function limitRecords(array $records, Range $range): array
207 {
208 return array_slice($records, $range->getStart(), $range->getLength());
209 }
210
231 private function orderRecords(array $records, Order $order): array
232 {
233 [$order_field, $order_direction] = $order->join(
234 [],
235 fn($ret, $key, $value) => [$key, $value]
236 );
237 usort($records, static fn(array $left, array $right): int => ilStr::strCmp(
238 $left[$order_field] ?? '',
239 $right[$order_field] ?? ''
240 ));
241
242 if ($order_direction === Order::DESC) {
243 $records = array_reverse($records);
244 }
245
246 return $records;
247 }
248
252 private function getColumns(): array
253 {
254 return [
255 'title' => $this->ui_factory->table()->column()->text($this->lng->txt('title')),
256 'role' => $this->ui_factory->table()->column()->text($this->lng->txt('obj_role')),
257 'dn' => $this->ui_factory->table()->column()->text($this->lng->txt('ldap_group_dn')),
258 'url' => $this->ui_factory->table()->column()->text($this->lng->txt('ldap_server')),
259 'member_attribute' => $this->ui_factory->table()->column()->text($this->lng->txt('ldap_group_member')),
260 'info' => $this->ui_factory->table()->column()->text($this->lng->txt('ldap_info_text')),
261 ];
262 }
263}
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)
__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, private readonly bool $has_write_access)
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....
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