ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MailMemberSearchTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data;
24use ILIAS\UI;
25use Psr\Http\Message\ServerRequestInterface;
26use ilArrayUtil;
27use ilLanguage;
28use ilCtrl;
31
33{
34 private readonly ServerRequestInterface $request;
35 private readonly Data\Factory $data_factory;
37 private ?array $records = null;
38
39 public function __construct(
40 private readonly int $ref_id,
42 private readonly ilCtrl $ctrl,
43 private readonly ilLanguage $lng,
44 private readonly \ILIAS\UI\Factory $ui_factory,
45 \ILIAS\HTTP\GlobalHttpState $http
46 ) {
47 $this->request = $http->request();
48 $this->data_factory = new Data\Factory();
49 }
50
51 public function getComponent(): UI\Component\Table\Data
52 {
53 $columns = $this->getColumns();
54 $actions = $this->getActions();
55
56 return $this->ui_factory
57 ->table()
58 ->data(
59 $this,
60 $this->lng->txt('members'),
61 $columns,
62 )
63 ->withId(self::class . '_' . $this->ref_id)
64 ->withOrder(new \ILIAS\Data\Order('login', \ILIAS\Data\Order::ASC))
65 ->withActions($actions)
66 ->withRequest($this->request);
67 }
68
72 private function getColumns(): array
73 {
74 return [
75 'login' => $this->ui_factory
76 ->table()
77 ->column()
78 ->text($this->lng->txt('login'))
79 ->withIsSortable(true),
80 'name' => $this->ui_factory
81 ->table()
82 ->column()
83 ->text($this->lng->txt('name'))
84 ->withIsSortable(true),
85 'role' => $this->ui_factory
86 ->table()
87 ->column()
88 ->text($this->lng->txt('role'))
89 ->withIsSortable(true),
90 ];
91 }
92
96 private function getActions(): array
97 {
98 $query_params_namespace = ['contact', 'search', 'members'];
99
100 $uri = $this->data_factory->uri(
101 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
102 \ilMailMemberSearchGUI::class,
103 'handleSearchMembersActions'
104 )
105 );
106
107 $url_builder = new UI\URLBuilder($uri);
108 [
109 $url_builder,
110 $action_parameter_token_copy,
111 $row_id_token
112 ] = $url_builder->acquireParameters(
113 $query_params_namespace,
114 'action',
115 'user_ids'
116 );
117
118 return [
119 'sendMailToSelectedUsers' => $this->ui_factory->table()->action()->multi(
120 $this->lng->txt('mail_members'),
121 $url_builder->withParameter($action_parameter_token_copy, 'sendMailToSelectedUsers'),
122 $row_id_token
123 ),
124 ];
125 }
126
127 private function initRecords(): void
128 {
129 if ($this->records === null) {
130 $this->records = [];
131 $i = 0;
132 $entries = $this->provider->getData();
133 if ($entries !== []) {
134 foreach ($entries as $entry) {
135 $this->records[$i]['user_id'] = (int) $entry['user_id'];
136 $this->records[$i]['login'] = $entry['login'];
137 $this->records[$i]['name'] = $entry['name'];
138 $this->records[$i]['role'] = $entry['role'];
139 ++$i;
140 }
141 }
142 }
143 }
144
145 public function getRows(
146 UI\Component\Table\DataRowBuilder $row_builder,
147 array $visible_column_ids,
149 Data\Order $order,
150 ?array $filter_data,
151 ?array $additional_parameters
152 ): \Generator {
153 $records = $this->getRecords($range, $order);
154
155 foreach ($records as $record) {
156 $row_id = (string) $record['user_id'];
157 yield $row_builder->buildDataRow($row_id, $record);
158 }
159 }
160
161 public function getTotalRowCount(
162 ?array $filter_data,
163 ?array $additional_parameters
164 ): ?int {
165 $this->initRecords();
166
167 return \count($this->records);
168 }
169
173 private function sortedRecords(Data\Order $order): array
174 {
175 $records = $this->records;
176 [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
177
178 return ilArrayUtil::stableSortArray($records, $order_field, strtolower($order_direction), false);
179 }
180
184 private function getRecords(Data\Range $range, Data\Order $order): array
185 {
186 $this->initRecords();
187
188 $records = $this->sortedRecords($order);
189
190 return $this->limitRecords($records, $range);
191 }
192
197 private function limitRecords(array $records, Data\Range $range): array
198 {
199 return \array_slice($records, $range->getStart(), $range->getLength());
200 }
201}
getRows(UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Data\Range $range, Data\Order $order, ?array $filter_data, ?array $additional_parameters)
getRecords(Data\Range $range, Data\Order $order)
__construct(private readonly int $ref_id, private readonly ilMailMemberSearchDataProvider $provider, private readonly ilCtrl $ctrl, private readonly ilLanguage $lng, private readonly \ILIAS\UI\Factory $ui_factory, \ILIAS\HTTP\GlobalHttpState $http)
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
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
Definition: UI.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stableSortArray(array $array, string $a_array_sortby, string $a_array_sortorder="asc", bool $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...
Class ilCtrl provides processing control methods.
language handling
Class ilMailMemberSearchDataProvider.
$http
Definition: deliver.php:30
A Column describes the form of presentation for a certain aspect of data, i.e.
Definition: Column.php:28
$ref_id
Definition: ltiauth.php:66
$provider
Definition: ltitoken.php:80
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