ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ForumDraftsTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Generator;
24use ilObjUser;
25use ilLanguage;
26use ilObjForum;
32use DateTimeImmutable;
35use ILIAS\UI\Factory as UIFactory;
36use ILIAS\Data\Factory as DataFactory;
38use Psr\Http\Message\ServerRequestInterface;
39use ILIAS\UI\Component\Table\Data as DataTable;
40
42{
44 private ?array $records = null;
45
46 public function __construct(
47 private readonly ilObjForum $forum,
48 private readonly UIFactory $ui_factory,
49 private readonly ServerRequestInterface $httpRequest,
50 private readonly ilLanguage $lng,
51 private readonly string $parent_cmd,
52 private readonly ilCtrlInterface $ctrl,
53 private readonly DataFactory $data_factory,
54 private readonly ilObjUser $user,
55 private readonly bool $mayEdit,
56 private readonly ilObjForumGUI $parent_object,
57 ) {
58 }
59
60 public function getRows(
61 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
62 array $visible_column_ids,
64 Order $order,
65 ?array $filter_data,
66 ?array $additional_parameters,
67 ): Generator {
68 $records = $this->getRecords($range, $order);
69 foreach ($records as $record) {
70 yield $row_builder->buildDataRow((string) $record['draft_id'], $record);
71 }
72 }
73
74 public function initRecords(): void
75 {
76 if ($this->records === null) {
77 $this->records = [];
79 $this->user->getId(),
80 ilObjForum::lookupForumIdByObjId($this->forum->getId())
81 );
82
83 foreach ($drafts as $draft) {
84 if (!isset($draft['draft_id'], $draft['subject'], $draft['post_update'])) {
85 continue;
86 }
87
88 $draft_id = $draft['draft_id'];
89 $this->records[$draft_id] = ['draft_id' => $draft_id];
90 if ($this->mayEdit) {
91 $this->ctrl->setParameter($this->parent_object, 'draft_id', $draft_id);
92 $url = $this->ctrl->getLinkTarget($this->parent_object, 'editThreadDraft');
93 $this->records[$draft_id]['draft'] = $this->ui_factory->link()->standard(
94 $draft['subject'],
95 $url
96 );
97 $this->ctrl->setParameter($this->parent_object, 'draft_id', null);
98 } else {
99 $this->records[$draft_id]['draft'] = $draft['subject'];
100 }
101 $this->records[$draft_id]['edited_on'] = new DateTimeImmutable(
102 $draft['post_update']
103 );
104 }
105 }
106 }
107
108 public function getComponent(): DataTable
109 {
110 $query_params_namespace = ['forum', 'drafts', 'delete'];
111 $uri = $this->data_factory->uri(
112 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(ilObjForumGUI::class, 'confirmDeleteThreadDrafts')
113 );
114 $url_builder = new URLBuilder($uri);
115 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
116 $query_params_namespace,
117 'table_action',
118 'draft_ids'
119 );
120
121 return $this->ui_factory
122 ->table()
123 ->data(
124 $this,
125 $this->lng->txt('drafts'),
126 $this->getColumns(),
127 )
128 ->withId(
129 'frm_drafts_' . substr(
130 md5($this->parent_cmd),
131 0,
132 3
133 ) . '_' . $this->forum->getId()
134 )
135 ->withRequest($this->httpRequest)
136 ->withActions(
137 [
138 'delete' => $this->ui_factory->table()->action()->multi(
139 $this->lng->txt('delete'),
140 $url_builder->withParameter($action_parameter_token, 'delete'),
141 $row_id_token
142 )
143 ]
144 );
145 }
146
147 public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
148 {
149 $this->initRecords();
150
151 return count((array) $this->records);
152 }
153
157 private function getRecords(Range $range, Order $order): array
158 {
159 $this->initRecords();
160
161 return $this->limitRecords($this->records, $range);
162 }
163
168 private function limitRecords(array $records, Range $range): array
169 {
170 return array_slice($records, $range->getStart(), $range->getLength());
171 }
172
179 private function getColumns(): array
180 {
181 return [
182 'draft' => $this->ui_factory->table()->column()->link($this->lng->txt('drafts'))->withIsSortable(
183 false
184 )->withIsSortable(false),
185 'edited_on' => $this->ui_factory->table()->column()->date(
186 $this->lng->txt('edited_on'),
187 $this->user->getDateTimeFormat()
188 )->withIsSortable(false)
189 ];
190 }
191}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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
__construct(private readonly ilObjForum $forum, private readonly UIFactory $ui_factory, private readonly ServerRequestInterface $httpRequest, private readonly ilLanguage $lng, private readonly string $parent_cmd, private readonly ilCtrlInterface $ctrl, private readonly DataFactory $data_factory, private readonly ilObjUser $user, private readonly bool $mayEdit, private readonly ilObjForumGUI $parent_object,)
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(Range $range, Order $order)
limitRecords(array $records, Range $range)
getRows(\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters,)
Definition: UI.php:24
Stores all calendar relevant settings.
Class ilForumPostDraft.
static getThreadDraftData(int $post_author_id, int $forum_id)
language handling
@ilCtrl_Calls ilObjForumGUI: ilPermissionGUI, ilForumExportGUI, ilInfoScreenGUI @ilCtrl_Calls ilObjFo...
Class ilObjForum.
static lookupForumIdByObjId(int $obj_id)
User class.
This describes a Data Table.
Definition: Data.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
$url
Definition: shib_logout.php:68