ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ActionBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use ILIAS\components\ResourceStorage\BinToHexSerializer;
32
36final class ActionBuilder
37{
38 use BinToHexSerializer;
39
43 public const ACTION_UNZIP = 'unzip';
47 private const ACTION_DOWNLOAD = 'download';
51 private const ACTION_REMOVE = 'remove';
55 private const ACTION_EDIT = 'edit';
59 public const ACTION_NAMESPACE = 'rcgui';
63 private array $modals = [];
66
67 public function __construct(
68 private Request $request,
69 private \ilCtrlInterface $ctrl,
70 private Factory $ui_factory,
71 private \ilLanguage $language,
72 private Services $irss
73 ) {
74 $this->initURIBuilder();
75 }
76
77 private function initURIBuilder(): void
78 {
79 $uri_builder = new URLBuilder(
80 new URI(
81 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
82 \ilResourceCollectionGUI::class,
84 )
85 )
86 );
87 $parameters = $uri_builder->acquireParameter(
88 [self::ACTION_NAMESPACE],
90 );
91
92 $this->url_builder = $parameters[0];
93 $this->url_token = $parameters[1];
94 }
95
96 public function getUrlBuilder(): URLBuilder
97 {
98 return $this->url_builder;
99 }
100
101 public function getUrlToken(): URLBuilderToken
102 {
103 return $this->url_token;
104 }
105
106 public function getModals(): array
107 {
108 return $this->modals;
109 }
110
114 public function getActions(): array
115 {
116 // we init the fixed actions here
117 $actions[self::ACTION_DOWNLOAD] =
118 $this->ui_factory->table()->action()->single(
119 $this->language->txt(self::ACTION_DOWNLOAD),
120 $this->url_builder->withURI($this->buildURI(\ilResourceCollectionGUI::CMD_DOWNLOAD)),
121 $this->url_token
122 );
123
124 if ($this->request->canUserAdministrate()) {
125 $actions[self::ACTION_REMOVE] =
126 $this->ui_factory->table()->action()->standard(
127 $this->language->txt(self::ACTION_REMOVE),
128 $this->url_builder->withURI($this->buildURI(\ilResourceCollectionGUI::CMD_RENDER_CONFIRM_REMOVE)),
129 $this->url_token
130 )->withAsync(true);
131
132 $actions[self::ACTION_UNZIP] =
133 $this->ui_factory->table()->action()->single(
134 $this->language->txt(self::ACTION_UNZIP),
135 $this->url_builder->withURI($this->buildURI(\ilResourceCollectionGUI::CMD_UNZIP)),
136 $this->url_token
137 );
138
139 $actions[self::ACTION_EDIT] =
140 $this->ui_factory->table()->action()->single(
141 $this->language->txt(self::ACTION_EDIT),
142 $this->url_builder->withURI($this->buildURI(\ilResourceCollectionGUI::CMD_EDIT)),
143 $this->url_token
144 )->withAsync(true);
145 }
146
147 return $actions;
148 }
149
152 ): Standard {
153 $items = [];
154 foreach ($this->getActions() as $index => $a) {
155 $revision = $this->irss->manage()->getCurrentRevision($rid);
156 $mime_type = $revision->getInformation()->getMimeType();
157 if ($index === self::ACTION_UNZIP
158 && !in_array($mime_type, ['application/zip', 'application/x-zip-compressed'])
159 ) {
160 continue;
161 }
162
163 $target = $a->getTarget();
164 $target = $this->url_builder->withURI($target)
165 ->withParameter(
166 $this->url_token,
167 $this->hash($rid->serialize())
168 )->buildURI();
169
170 if (!$a->isAsync()) {
171 $items[] = $this->ui_factory->link()->standard(
172 $a->getLabel(),
173 (string) $target
174 );
175 } else {
176 $this->modals[] = $modal = $this->ui_factory->modal()->interruptive(
177 $a->getLabel(),
178 $a->getLabel(),
179 '#'
180 )->withAsyncRenderUrl($target->__toString());
181
182 $items[] = $this->ui_factory->button()->shy(
183 $a->getLabel(),
184 $modal->getShowSignal()
185 );
186 }
187 }
188 return $this->ui_factory->dropdown()->standard(
189 $items
190 );
191 }
192
193 private function buildURI(
194 string $command
195 ): URI {
196 return new URI(
197 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
199 $command
200 )
201 );
202 }
203}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Class Services.
Definition: Services.php:38
__construct(private Request $request, private \ilCtrlInterface $ctrl, private Factory $ui_factory, private \ilLanguage $language, private Services $irss)
language handling
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes a standard form.
Definition: Standard.php:29
This describes commonalities between the different modals.
Definition: Modal.php:35
This is how the factory for UI elements looks.
Definition: Factory.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples