ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ActionBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 use ILIAS\Data\URI;
32 
36 final class ActionBuilder
37 {
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)),
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)),
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)),
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)),
144  )->withAsync(true);
145  }
146 
147  return $actions;
148  }
149 
150  public function buildDropDownForResource(
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(
198  \ilResourceCollectionGUI::class,
199  $command
200  )
201  );
202  }
203 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is how the factory for UI elements looks.
Definition: Factory.php:37
__construct(private Request $request, private \ilCtrlInterface $ctrl, private Factory $ui_factory, private \ilLanguage $language, private Services $irss)
This describes a standard form.
Definition: Standard.php:28
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
URLBuilder.
Definition: URLBuilder.php:40