ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
MailingListsMembersTable.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 ilUserUtil;
29use ilLanguage;
32
34{
35 private readonly ServerRequestInterface $request;
36 private readonly Data\Factory $data_factory;
38 private ?array $records = null;
39
40 public function __construct(
41 private readonly ilMailingList $mailing_list,
42 private readonly \ilCtrlInterface $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 \sprintf(
61 $this->lng->txt('mail_members_of_mailing_list'),
62 $this->mailing_list->getTitle()
63 ),
64 $columns,
65 )
66 ->withId(str_replace('\\', '', self::class) . '_' . $this->mailing_list->getId())
67 ->withOrder(new \ILIAS\Data\Order('login', \ILIAS\Data\Order::ASC))
68 ->withRange(new Range(0, 50))
69 ->withActions($actions)
70 ->withRequest($this->request);
71 }
72
76 private function getColumns(): array
77 {
78 return [
79 'login' => $this->ui_factory
80 ->table()
81 ->column()
82 ->text($this->lng->txt('login'))
83 ->withIsSortable(true),
84 ];
85 }
86
90 private function getActions(): array
91 {
92 $query_params_namespace = ['contact', 'mailinglist', 'members'];
93
94 $uri = $this->data_factory->uri(
95 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
96 ilMailingListsGUI::class,
97 'handleMailingListMemberActions'
98 )
99 );
100
101 $url_builder = new UI\URLBuilder($uri);
102 [
103 $url_builder,
104 $action_parameter_token_copy,
105 $row_id_token
106 ] = $url_builder->acquireParameters(
107 $query_params_namespace,
108 'action',
109 'entry_ids'
110 );
111
112 return [
113 'confirmDeleteMembers' => $this->ui_factory->table()->action()->multi(
114 $this->lng->txt('remove'),
115 $url_builder->withParameter($action_parameter_token_copy, 'confirmDeleteMembers'),
116 $row_id_token
117 ),
118 ];
119 }
120
121 private function initRecords(): void
122 {
123 if ($this->records === null) {
124 $this->records = [];
125 $i = 0;
126 $entries = $this->mailing_list->getAssignedEntries();
127 if ($entries !== []) {
128 $usr_ids = array_map(static fn(array $entry): int => (int) $entry['usr_id'], $entries);
129 $names = ilUserUtil::getNamePresentation($usr_ids, false, false, '', false, false, false);
130
131 foreach ($entries as $entry) {
132 $this->records[$i]['a_id'] = $entry['a_id'];
133 $this->records[$i]['user_id'] = $entry['usr_id'];
134 $this->records[$i]['login'] = $names[$entry['usr_id']];
135 ++$i;
136 }
137 }
138 }
139 }
140
141 public function getRows(
142 UI\Component\Table\DataRowBuilder $row_builder,
143 array $visible_column_ids,
145 Data\Order $order,
146 mixed $additional_viewcontrol_data,
147 mixed $filter_data,
148 mixed $additional_parameters
149 ): \Generator {
150 $records = $this->getRecords($range, $order);
151
152 foreach ($records as $record) {
153 $row_id = (string) $record['a_id'];
154 yield $row_builder->buildDataRow($row_id, $record);
155 }
156 }
157
158 public function getTotalRowCount(
159 mixed $additional_viewcontrol_data,
160 mixed $filter_data,
161 mixed $additional_parameters
162 ): ?int {
163 $this->initRecords();
164
165 return \count($this->records);
166 }
167
171 private function sortedRecords(Data\Order $order): array
172 {
173 $records = $this->records;
174 [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
175
176 return ilArrayUtil::stableSortArray($records, $order_field, strtolower($order_direction), false);
177 }
178
182 private function getRecords(Data\Range $range, Data\Order $order): array
183 {
184 $this->initRecords();
185
186 $records = $this->sortedRecords($order);
187
188 return $this->limitRecords($records, $range);
189 }
190
195 private function limitRecords(array $records, Data\Range $range): array
196 {
197 return \array_slice($records, $range->getStart(), $range->getLength());
198 }
199}
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...
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)
__construct(private readonly ilMailingList $mailing_list, private readonly \ilCtrlInterface $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...
language handling
Class ilUserUtil.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
$http
Definition: deliver.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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