ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
MailAttachmentTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilStr;
24use ilUtil;
25
27{
28 private readonly \ILIAS\UI\URLBuilder $url_builder;
29 private readonly \ILIAS\UI\URLBuilderToken $action_parameter_token;
30 private readonly \ILIAS\UI\URLBuilderToken $row_id_token;
31 private readonly \ILIAS\Data\Factory $data_factory;
32
36 public function __construct(
37 private readonly \ilMailAttachmentGUI $parent_gui,
38 private readonly \ilObjUser $actor,
39 private readonly array $records,
40 private readonly \ILIAS\UI\Factory $ui_factory,
41 private readonly \ILIAS\UI\Renderer $ui_renderer,
42 private readonly \ilLanguage $lng,
43 private readonly \ilCtrlInterface $ctrl,
44 private readonly \Psr\Http\Message\ServerRequestInterface $http_request,
45 private readonly \ILIAS\Data\Factory $df,
46 private readonly string $parent_cmd,
47 private readonly AttachmentManagement $mode
48 ) {
49 $form_action = $this->df->uri(
50 ilUtil::_getHttpPath() . '/' .
51 $this->ctrl->getLinkTarget($this->parent_gui, $this->parent_cmd)
52 );
53
54 [
58 ] = (new \ILIAS\UI\URLBuilder($form_action))->acquireParameters(
59 ['mail', 'attachments'],
60 'table_action',
61 'filename'
62 );
63
64 $this->data_factory = new \ILIAS\Data\Factory();
65 }
66
67 public function get(): \ILIAS\UI\Component\Table\Data
68 {
69 return $this->ui_factory
70 ->table()
71 ->data(
72 $this,
73 $this->lng->txt('attachment'),
74 $this->getColumnDefinition(),
75 )
76 ->withId(self::class . '_' . $this->mode->name)
77 ->withOrder(new \ILIAS\Data\Order('filename', \ILIAS\Data\Order::ASC))
78 ->withActions($this->getActions())
79 ->withRequest($this->http_request);
80 }
81
85 private function getColumnDefinition(): array
86 {
87 if ((int) $this->actor->getTimeFormat() === \ilCalendarSettings::TIME_FORMAT_12) {
88 $date_format = $this->data_factory->dateFormat()->withTime12($this->actor->getDateFormat());
89 } else {
90 $date_format = $this->data_factory->dateFormat()->withTime24($this->actor->getDateFormat());
91 }
92
93 return [
94 'filename' => $this->ui_factory
95 ->table()
96 ->column()
97 ->text($this->lng->txt('mail_file_name'))
98 ->withIsSortable(true),
99 'filesize' => $this->ui_factory
100 ->table()
101 ->column()
102 ->text($this->lng->txt('mail_file_size'))
103 ->withIsSortable(true),
104 'filecreatedate' => $this->ui_factory
105 ->table()
106 ->column()
107 ->date($this->lng->txt('create_date'), $date_format)
108 ->withIsSortable(true),
109 ];
110 }
111
115 private function getActions(): array
116 {
117 $actions = [];
118
119 if ($this->mode === AttachmentManagement::CONSUME) {
120 $actions['saveAttachments'] = $this->ui_factory->table()->action()->multi(
121 $this->lng->txt('adopt'),
122 $this->url_builder->withParameter(
123 $this->action_parameter_token,
124 self::TABLE_ACTION_SAVE_ATTACHMENTS
125 ),
126 $this->row_id_token
127 );
128 } else {
129 $actions['deleteAttachments'] = $this->ui_factory->table()->action()->multi(
130 $this->lng->txt('delete'),
131 $this->url_builder->withParameter(
132 $this->action_parameter_token,
133 self::TABLE_CONFIRM_DELETE_ATTACHMENTS
134 ),
135 $this->row_id_token
136 );
137 }
138
139 return $actions;
140 }
141
145 private function getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order): array
146 {
147 $records = $this->records;
148
149 [$order_field, $order_direction] = $order->join([], static fn($ret, $key, $value) => [$key, $value]);
150
151 usort($records, static function (array $left, array $right) use ($order_field): int {
152 if ($order_field === 'filename') {
153 return ilStr::strCmp($left[$order_field], $right[$order_field]);
154 }
155
156 return $left[$order_field] <=> $right[$order_field];
157 });
158
159 if ($order_direction === 'DESC') {
160 $records = array_reverse($records);
161 }
162
163 $records = \array_slice($records, $range->getStart(), $range->getLength());
164
165 return $records;
166 }
167
168 public function getRows(
169 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
170 array $visible_column_ids,
172 \ILIAS\Data\Order $order,
173 ?array $filter_data,
174 ?array $additional_parameters
175 ): \Generator {
176 foreach ($this->getRecords($range, $order) as $item) {
177 $record = [
178 'filename' => $item['filename'],
179 'filesize' => ilUtil::formatSize($item['filesize'], 'long'),
180 'filecreatedate' => (new \DateTimeImmutable('@' . $item['filecreatedate']))->setTimezone(
181 new \DateTimeZone($this->actor->getTimeZone())
182 )
183 ];
184
185 yield $row_builder
186 ->buildDataRow(urlencode($record['filename']), $record);
187 }
188 }
189
190 public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
191 {
192 return \count($this->records);
193 }
194}
Builds data types.
Definition: Factory.php:36
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
readonly ILIAS UI URLBuilderToken $row_id_token
__construct(private readonly \ilMailAttachmentGUI $parent_gui, private readonly \ilObjUser $actor, private readonly array $records, private readonly \ILIAS\UI\Factory $ui_factory, private readonly \ILIAS\UI\Renderer $ui_renderer, private readonly \ilLanguage $lng, private readonly \ilCtrlInterface $ctrl, private readonly \Psr\Http\Message\ServerRequestInterface $http_request, private readonly \ILIAS\Data\Factory $df, private readonly string $parent_cmd, private readonly AttachmentManagement $mode)
readonly ILIAS UI URLBuilderToken $action_parameter_token
getRows(\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, \ILIAS\Data\Range $range, \ILIAS\Data\Order $order, ?array $filter_data, ?array $additional_parameters)
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...
getRecords(\ILIAS\Data\Range $range, \ILIAS\Data\Order $order)
Definition: UI.php:24
language handling
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: class.ilStr.php:20
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
Util class various functions, usage as namespace.
static formatSize(int $size, string $a_mode='short', ?ilLanguage $a_lng=null)
Returns the specified file size value in a human friendly form.
static _getHttpPath()
An entity that renders components to a string output.
Definition: Renderer.php:31
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