ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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;
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 ilMailingList $mailing_list,
41 private readonly \ilCtrlInterface $ctrl,
42 private readonly ilLanguage $lng,
43 private readonly \ILIAS\UI\Factory $ui_factory,
44 \ILIAS\HTTP\GlobalHttpState $http
45 ) {
46 $this->request = $http->request();
47 $this->data_factory = new Data\Factory();
48 }
49
50 public function getComponent(): UI\Component\Table\Data
51 {
52 $columns = $this->getColumns();
53 $actions = $this->getActions();
54
55 return $this->ui_factory
56 ->table()
57 ->data(
58 $this,
59 \sprintf(
60 $this->lng->txt('mail_members_of_mailing_list'),
61 $this->mailing_list->getTitle()
62 ),
63 $columns,
64 )
65 ->withId(self::class . '_' . $this->mailing_list->getId())
66 ->withOrder(new \ILIAS\Data\Order('login', \ILIAS\Data\Order::ASC))
67 ->withActions($actions)
68 ->withRequest($this->request);
69 }
70
74 private function getColumns(): array
75 {
76 return [
77 'login' => $this->ui_factory
78 ->table()
79 ->column()
80 ->text($this->lng->txt('login'))
81 ->withIsSortable(true),
82 ];
83 }
84
88 private function getActions(): array
89 {
90 $query_params_namespace = ['contact', 'mailinglist', 'members'];
91
92 $uri = $this->data_factory->uri(
93 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
94 ilMailingListsGUI::class,
95 'handleMailingListMemberActions'
96 )
97 );
98
99 $url_builder = new UI\URLBuilder($uri);
100 [
101 $url_builder,
102 $action_parameter_token_copy,
103 $row_id_token
104 ] = $url_builder->acquireParameters(
105 $query_params_namespace,
106 'action',
107 'entry_ids'
108 );
109
110 return [
111 'confirmDeleteMembers' => $this->ui_factory->table()->action()->multi(
112 $this->lng->txt('remove'),
113 $url_builder->withParameter($action_parameter_token_copy, 'confirmDeleteMembers'),
114 $row_id_token
115 ),
116 ];
117 }
118
119 private function initRecords(): void
120 {
121 if ($this->records === null) {
122 $this->records = [];
123 $i = 0;
124 $entries = $this->mailing_list->getAssignedEntries();
125 if ($entries !== []) {
126 $usr_ids = array_map(static fn(array $entry): int => (int) $entry['usr_id'], $entries);
127 $names = ilUserUtil::getNamePresentation($usr_ids, false, false, '', false, false, false);
128
129 foreach ($entries as $entry) {
130 $this->records[$i]['a_id'] = $entry['a_id'];
131 $this->records[$i]['user_id'] = $entry['usr_id'];
132 $this->records[$i]['login'] = $names[$entry['usr_id']];
133 ++$i;
134 }
135 }
136 }
137 }
138
139 public function getRows(
140 UI\Component\Table\DataRowBuilder $row_builder,
141 array $visible_column_ids,
143 Data\Order $order,
144 mixed $additional_viewcontrol_data,
145 mixed $filter_data,
146 mixed $additional_parameters
147 ): \Generator {
148 $records = $this->getRecords($range, $order);
149
150 foreach ($records as $record) {
151 $row_id = (string) $record['a_id'];
152 yield $row_builder->buildDataRow($row_id, $record);
153 }
154 }
155
156 public function getTotalRowCount(
157 mixed $additional_viewcontrol_data,
158 mixed $filter_data,
159 mixed $additional_parameters
160 ): ?int {
161 $this->initRecords();
162
163 return \count($this->records);
164 }
165
169 private function sortedRecords(Data\Order $order): array
170 {
171 $records = $this->records;
172 [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
173
174 return ilArrayUtil::stableSortArray($records, $order_field, strtolower($order_direction), false);
175 }
176
180 private function getRecords(Data\Range $range, Data\Order $order): array
181 {
182 $this->initRecords();
183
184 $records = $this->sortedRecords($order);
185
186 return $this->limitRecords($records, $range);
187 }
188
193 private function limitRecords(array $records, Data\Range $range): array
194 {
195 return \array_slice($records, $range->getStart(), $range->getLength());
196 }
197}
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