ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 mixed $additional_viewcontrol_data,
66 mixed $filter_data,
67 mixed $additional_parameters,
68 ): Generator {
69 $records = $this->getRecords($range, $order);
70 foreach ($records as $record) {
71 yield $row_builder->buildDataRow((string) $record['draft_id'], $record);
72 }
73 }
74
75 public function initRecords(): void
76 {
77 if ($this->records === null) {
78 $this->records = [];
80 $this->user->getId(),
81 ilObjForum::lookupForumIdByObjId($this->forum->getId())
82 );
83
84 foreach ($drafts as $draft) {
85 if (!isset($draft['draft_id'], $draft['subject'], $draft['post_update'])) {
86 continue;
87 }
88
89 $draft_id = $draft['draft_id'];
90 $this->records[$draft_id] = ['draft_id' => $draft_id];
91 if ($this->mayEdit) {
92 $this->ctrl->setParameter($this->parent_object, 'draft_id', $draft_id);
93 $url = $this->ctrl->getLinkTarget($this->parent_object, 'editThreadDraft');
94 $this->records[$draft_id]['draft'] = $this->ui_factory->link()->standard(
95 $draft['subject'],
96 $url
97 );
98 $this->ctrl->setParameter($this->parent_object, 'draft_id', null);
99 } else {
100 $this->records[$draft_id]['draft'] = $draft['subject'];
101 }
102 $this->records[$draft_id]['edited_on'] = new DateTimeImmutable(
103 $draft['post_update']
104 );
105 }
106 }
107 }
108
109 public function getComponent(): DataTable
110 {
111 $query_params_namespace = ['forum', 'drafts', 'delete'];
112 $uri = $this->data_factory->uri(
113 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(ilObjForumGUI::class, 'confirmDeleteThreadDrafts')
114 );
115 $url_builder = new URLBuilder($uri);
116 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
117 $query_params_namespace,
118 'table_action',
119 'draft_ids'
120 );
121
122 return $this->ui_factory
123 ->table()
124 ->data(
125 $this,
126 $this->lng->txt('drafts'),
127 $this->getColumns(),
128 )
129 ->withId(
130 'frm_drafts_' . substr(
131 md5($this->parent_cmd),
132 0,
133 3
134 ) . '_' . $this->forum->getId()
135 )
136 ->withRequest($this->httpRequest)
137 ->withActions(
138 [
139 'delete' => $this->ui_factory->table()->action()->multi(
140 $this->lng->txt('delete'),
141 $url_builder->withParameter($action_parameter_token, 'delete'),
142 $row_id_token
143 )
144 ]
145 );
146 }
147
148 public function getTotalRowCount(
149 mixed $additional_viewcontrol_data,
150 mixed $filter_data,
151 mixed $additional_parameters
152 ): ?int {
153 $this->initRecords();
154
155 return count((array) $this->records);
156 }
157
161 private function getRecords(Range $range, Order $order): array
162 {
163 $this->initRecords();
164
165 return $this->limitRecords($this->records, $range);
166 }
167
172 private function limitRecords(array $records, Range $range): array
173 {
174 return array_slice($records, $range->getStart(), $range->getLength());
175 }
176
183 private function getColumns(): array
184 {
185 return [
186 'draft' => $this->ui_factory->table()->column()->link($this->lng->txt('drafts'))->withIsSortable(
187 false
188 )->withIsSortable(false),
189 'edited_on' => $this->ui_factory->table()->column()->date(
190 $this->lng->txt('edited_on'),
191 $this->user->getDateTimeFormat()
192 )->withIsSortable(false)
193 ];
194 }
195}
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
getRows(\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters,)
__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,)
getRecords(Range $range, Order $order)
limitRecords(array $records, Range $range)
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: 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:33
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