ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
Table.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data\Factory as DataFactory;
28use ILIAS\UI\Factory as UIFactory;
29use ILIAS\UI\Renderer as UIRenderer;
32
33class Table
34{
35 private UIFactory $ui_factory;
36 private UIRenderer $ui_renderer;
37 private \ilCtrlInterface $ctrl;
38 private \ilLanguage $lng;
41 private \ILIAS\HTTP\Services $http;
42 private DataFactory $data_factory;
43
44 public function __construct(
45 private readonly \ilFileVersionsGUI $calling_gui
46 ) {
47 global $DIC;
48 $this->ui_factory = $DIC['ui.factory'];
49 $this->ui_renderer = $DIC['ui.renderer'];
50 $this->ctrl = $DIC['ilCtrl'];
51 $this->lng = $DIC['lng'];
52 $this->http = $DIC->http();
53 $this->data_factory = new DataFactory();
54
55 $this->url_builder = $this->initURIBuilder();
56 }
57
58 public function getIdToken(): URLBuilderToken
59 {
60 return $this->id_token;
61 }
62
63 public function getUrlBuilder(): URLBuilder
64 {
65 return $this->url_builder;
66 }
67
68 public function getHTML(): string
69 {
70 return $this->ui_renderer->render([$this->buildTable()]);
71 }
72
73 private function buildTable(): \ILIAS\UI\Component\Table\Data
74 {
75 $file = $this->calling_gui->getFile();
76 $irss = $this->getIRSS();
77 $rid = $irss->manage()->find($file->getResourceId());
78 $revision = $irss->manage()->getCurrentRevisionIncludingDraft($rid);
79 $amount_of_versions = count($irss->manage()->getResource($rid)->getAllRevisionsIncludingDraft());
80 $current_version_is_draft = $revision->getStatus() === RevisionStatus::DRAFT;
81 $current_version = $file->getVersion(true);
82
83 $data_retrieval = new DataRetrieval(
84 $file,
85 $current_version,
86 $current_version_is_draft,
87 $amount_of_versions,
88 $this->ctrl,
89 $this->calling_gui,
90 $this->lng,
91 $this->ui_factory
92 );
93
94 return $this->ui_factory->table()
95 ->data($data_retrieval, $this->lng->txt('versions'), $this->initColumns())
96 ->withActions($this->initActions())
97 ->withOrder(new Order('version', Order::DESC))
98 ->withRequest($this->http->request());
99 }
100
101 private function initURIBuilder(): URLBuilder
102 {
105 ['file', 'versions'],
107 );
108 return $url_builder;
109 }
110
114 private function initColumns(): array
115 {
117 $col = $this->ui_factory->table()->column();
118
119 return [
120 'version' => $col->number($this->lng->txt('version')),
121 'filename' => $col->link($this->lng->txt('filename')),
122 'date' => $col->date($this->lng->txt('date'), $df->dateFormat()->withTime24($df->dateFormat()->germanShort())),
123 'uploaded_by' => $col->text($this->lng->txt('file_uploaded_by')),
124 'versionname' => $col->text($this->lng->txt('versionname')),
125 'filesize' => $col->text($this->lng->txt('filesize'))->withIsSortable(false),
126 'status' => $col->text($this->lng->txt('status'))->withIsSortable(false),
127 ];
128 }
129
133 private function initActions(): array
134 {
135 $a = $this->ui_factory->table()->action();
136
137 return [
138 DataRetrieval::ACTION_DELETE => $a->standard(
139 $this->lng->txt('delete'),
140 $this->url_builder->withURI($this->getURI(\ilFileVersionsGUI::CMD_RENDER_DELETE_SELECTED_VERSIONS_MODAL)),
141 $this->id_token
142 )->withAsync(true),
144 $this->lng->txt('file_rollback'),
145 $this->url_builder->withURI($this->getURI(\ilFileVersionsGUI::CMD_ROLLBACK_VERSION)),
146 $this->id_token
147 ),
149 $this->lng->txt('file_publish'),
150 $this->url_builder->withURI($this->getURI(\ilFileVersionsGUI::CMD_PUBLISH)),
151 $this->id_token
152 ),
154 $this->lng->txt('file_unpublish'),
155 $this->url_builder->withURI($this->getURI(\ilFileVersionsGUI::CMD_UNPUBLISH)),
156 $this->id_token
157 ),
158 ];
159 }
160
161 private function getURI(string $command): URI
162 {
163 return new URI(
164 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTarget($this->calling_gui, $command)
165 );
166 }
167
168 private function getIRSS(): IRSS
169 {
170 global $DIC;
171 return $DIC->resourceStorage();
172 }
173}
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
const DESC
Definition: Order.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
__construct(private readonly \ilFileVersionsGUI $calling_gui)
Definition: Table.php:44
URLBuilderToken $id_token
Definition: Table.php:40
getURI(string $command)
Definition: Table.php:161
ILIAS HTTP Services $http
Definition: Table.php:41
ilCtrlInterface $ctrl
Definition: Table.php:37
acquireParameters(array $namespace, string ... $names)
Definition: URLBuilder.php:138
Definition: UI.php:24
An entity that renders components to a string output.
Definition: Renderer.php:31
static http()
Fetches the global http state from ILIAS.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26