ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
TableRows.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Contact;
22
27use Generator;
28use Closure;
29
33class TableRows implements DataRetrieval
34{
40 public function __construct(
41 private readonly array $records,
42 private readonly array $sigle_actions,
43 private readonly Closure $link_to_profile
44 ) {
45 }
46
47 public function getRows(
48 DataRowBuilder $row_builder,
49 array $visible_column_ids,
51 Order $order,
52 mixed $additional_viewcontrol_data,
53 mixed $filter_data,
54 mixed $additional_parameters
55 ): Generator {
56 [$order_field, $order_direction] = $order->join(
57 [],
58 fn($ret, $key, $value) => [$key, $value]
59 );
60
61 $records = $this->records;
62
63 $times = $order_direction === 'ASC' ? 1 : -1;
64 usort(
65 $records,
66 static fn(array $a, array $b): int => $times * strcasecmp(
67 $a[$order_field],
68 $b[$order_field]
69 )
70 );
71
72 if ($range) {
73 $records = \array_slice($records, $range->getStart(), $range->getLength());
74 }
75
76 foreach ($records as $row) {
77 $row['public_name'] = ($this->link_to_profile)($row['user_id'], $row['public_name']);
78 $row['login'] = ($this->link_to_profile)($row['user_id'], $row['login']);
79
80 $transitions = array_map(
81 static fn($s): string => $row['state'] . '->' . $s,
82 $row['target_states']
83 );
84
85 $data_row = $row_builder->buildDataRow((string) $row['user_id'], $row);
86 foreach ($this->sigle_actions as $action) {
87 if (!\in_array($action, $transitions, true)) {
88 $data_row = $data_row->withDisabledAction($action);
89 }
90 }
91
92 yield $data_row;
93 }
94 }
95
96 public function getTotalRowCount(
97 mixed $additional_viewcontrol_data,
98 mixed $filter_data,
99 mixed $additional_parameters
100 ): ?int {
101 return \count($this->records);
102 }
103}
@phpstan-import-type RelationRecord from \ILIAS\Contact\BuddySystem\Tables\RelationsTable
Definition: TableRows.php:34
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
Definition: TableRows.php:47
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...
Definition: TableRows.php:96
__construct(private readonly array $records, private readonly array $sigle_actions, private readonly Closure $link_to_profile)
Definition: TableRows.php:40
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
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildDataRow(string $id, array $record)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples