ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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(str_replace('\\', '', self::class) . '_' . $this->ref_id)
64 ->withOrder(new \ILIAS\Data\Order('login', \ILIAS\Data\Order::ASC))
65 ->withRange(new \ILIAS\Data\Range(0, 50))
66 ->withActions($actions)
67 ->withRequest($this->request);
68 }
69
73 private function getColumns(): array
74 {
75 return [
76 'login' => $this->ui_factory
77 ->table()
78 ->column()
79 ->text($this->lng->txt('login'))
80 ->withIsSortable(true),
81 'name' => $this->ui_factory
82 ->table()
83 ->column()
84 ->text($this->lng->txt('name'))
85 ->withIsSortable(true),
86 'role' => $this->ui_factory
87 ->table()
88 ->column()
89 ->text($this->lng->txt('role'))
90 ->withIsSortable(true),
91 ];
92 }
93
97 private function getActions(): array
98 {
99 $query_params_namespace = ['contact', 'search', 'members'];
100
101 $uri = $this->data_factory->uri(
102 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
103 \ilMailMemberSearchGUI::class,
104 'handleSearchMembersActions'
105 )
106 );
107
108 $url_builder = new UI\URLBuilder($uri);
109 [
110 $url_builder,
111 $action_parameter_token_copy,
112 $row_id_token
113 ] = $url_builder->acquireParameters(
114 $query_params_namespace,
115 'action',
116 'user_ids'
117 );
118
119 return [
120 'sendMailToSelectedUsers' => $this->ui_factory->table()->action()->multi(
121 $this->lng->txt('mail_members'),
122 $url_builder->withParameter($action_parameter_token_copy, 'sendMailToSelectedUsers'),
123 $row_id_token
124 ),
125 ];
126 }
127
128 private function initRecords(): void
129 {
130 if ($this->records === null) {
131 $this->records = [];
132 $i = 0;
133 $entries = $this->provider->getData();
134 if ($entries !== []) {
135 foreach ($entries as $entry) {
136 $this->records[$i]['user_id'] = (int) $entry['user_id'];
137 $this->records[$i]['login'] = $entry['login'];
138 $this->records[$i]['name'] = $entry['name'];
139 $this->records[$i]['role'] = $entry['role'];
140 ++$i;
141 }
142 }
143 }
144 }
145
146 public function getRows(
147 UI\Component\Table\DataRowBuilder $row_builder,
148 array $visible_column_ids,
150 Data\Order $order,
151 mixed $additional_viewcontrol_data,
152 mixed $filter_data,
153 mixed $additional_parameters
154 ): \Generator {
155 $records = $this->getRecords($range, $order);
156
157 foreach ($records as $record) {
158 $row_id = (string) $record['user_id'];
159 yield $row_builder->buildDataRow($row_id, $record);
160 }
161 }
162
163 public function getTotalRowCount(
164 mixed $additional_viewcontrol_data,
165 mixed $filter_data,
166 mixed $additional_parameters
167 ): ?int {
168 $this->initRecords();
169
170 return \count($this->records);
171 }
172
176 private function sortedRecords(Data\Order $order): array
177 {
178 $records = $this->records;
179 [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
180
181 return ilArrayUtil::stableSortArray($records, $order_field, strtolower($order_direction), false);
182 }
183
187 private function getRecords(Data\Range $range, Data\Order $order): array
188 {
189 $this->initRecords();
190
191 $records = $this->sortedRecords($order);
192
193 return $this->limitRecords($records, $range);
194 }
195
200 private function limitRecords(array $records, Data\Range $range): array
201 {
202 return \array_slice($records, $range->getStart(), $range->getLength());
203 }
204}
getRecords(Data\Range $range, Data\Order $order)
getRows(UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Data\Range $range, Data\Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
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...
__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)
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