ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
MailingListsMembersTable.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\Data;
24 use ILIAS\UI;
26 use ilArrayUtil;
27 use ilUserUtil;
29 use ilLanguage;
30 use ilMailingList;
31 
32 class MailingListsMembersTable implements UI\Component\Table\DataRetrieval
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,
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,
142  Data\Range $range,
143  Data\Order $order,
144  ?array $filter_data,
145  ?array $additional_parameters
146  ): \Generator {
147  $records = $this->getRecords($range, $order);
148 
149  foreach ($records as $record) {
150  $row_id = (string) $record['a_id'];
151  yield $row_builder->buildDataRow($row_id, $record);
152  }
153  }
154 
155  public function getTotalRowCount(
156  ?array $filter_data,
157  ?array $additional_parameters
158  ): ?int {
159  $this->initRecords();
160 
161  return \count($this->records);
162  }
163 
167  private function sortedRecords(Data\Order $order): array
168  {
169  $records = $this->records;
170  [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
171 
172  return ilArrayUtil::stableSortArray($records, $order_field, strtolower($order_direction), false);
173  }
174 
178  private function getRecords(Data\Range $range, Data\Order $order): array
179  {
180  $this->initRecords();
181 
182  $records = $this->sortedRecords($order);
183 
184  return $this->limitRecords($records, $range);
185  }
186 
191  private function limitRecords(array $records, Data\Range $range): array
192  {
193  return \array_slice($records, $range->getStart(), $range->getLength());
194  }
195 }
Interface Observer Contains several chained tasks and infos about them.
$http
Definition: deliver.php:30
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:28
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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='ilpublicuserprofilegui')
Default behaviour is:
Builds data types.
Definition: Factory.php:35
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...
__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)
getRows(UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Data\Range $range, Data\Order $order, ?array $filter_data, ?array $additional_parameters)
global $lng
Definition: privfeed.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28
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...