ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ActionBuilder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ILIAS\Data\URI;
31 
35 final class ActionBuilder
36 {
38 
39  public const ACTION_UNZIP = 'unzip';
40  private const ACTION_DOWNLOAD = 'download';
41  private const ACTION_REMOVE = 'remove';
42  private const ACTION_EDIT = 'edit';
43  public const ACTION_NAMESPACE = 'rcgui';
47  private array $modals = [];
49  private \ILIAS\UI\URLBuilderToken $url_token;
50 
51  public function __construct(
52  private Request $request,
53  private \ilCtrlInterface $ctrl,
54  private Factory $ui_factory,
55  private \ilLanguage $language,
56  private Services $irss
57  ) {
58  $this->initURIBuilder();
59  }
60 
61  private function initURIBuilder(): void
62  {
63  $uri_builder = new URLBuilder(
64  new URI(
65  ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
66  \ilResourceCollectionGUI::class,
68  )
69  )
70  );
71  $parameters = $uri_builder->acquireParameter(
72  [self::ACTION_NAMESPACE],
74  );
75 
76  $this->url_builder = $parameters[0];
77  $this->url_token = $parameters[1];
78  }
79 
80  public function getUrlBuilder(): URLBuilder
81  {
82  return $this->url_builder;
83  }
84 
85  public function getUrlToken(): \ILIAS\UI\URLBuilderToken
86  {
87  return $this->url_token;
88  }
89 
90  public function getModals(): array
91  {
92  return $this->modals;
93  }
94 
98  public function getActions(): array
99  {
100  // we init the fixed actions here
101  $actions[self::ACTION_DOWNLOAD] =
102  $this->ui_factory->table()->action()->single(
103  $this->language->txt(self::ACTION_DOWNLOAD),
104  $this->url_builder->withURI($this->buildURI(\ilResourceCollectionGUI::CMD_DOWNLOAD)),
106  );
107 
108  if ($this->request->canUserAdministrate()) {
109  $actions[self::ACTION_REMOVE] =
110  $this->ui_factory->table()->action()->standard(
111  $this->language->txt(self::ACTION_REMOVE),
112  $this->url_builder->withURI($this->buildURI(\ilResourceCollectionGUI::CMD_RENDER_CONFIRM_REMOVE)),
114  )->withAsync(true);
115 
116  $actions[self::ACTION_UNZIP] =
117  $this->ui_factory->table()->action()->single(
118  $this->language->txt(self::ACTION_UNZIP),
119  $this->url_builder->withURI($this->buildURI(\ilResourceCollectionGUI::CMD_UNZIP)),
121  );
122 
123  $actions[self::ACTION_EDIT] =
124  $this->ui_factory->table()->action()->single(
125  $this->language->txt(self::ACTION_EDIT),
126  $this->url_builder->withURI($this->buildURI(\ilResourceCollectionGUI::CMD_EDIT)),
128  )->withAsync(true);
129  }
130 
131  return $actions;
132  }
133 
134  public function buildDropDownForResource(
136  ): \ILIAS\UI\Implementation\Component\Dropdown\Standard {
137  $items = [];
138  foreach ($this->getActions() as $index => $a) {
139  $revision = $this->irss->manage()->getCurrentRevision($rid);
140  $mime_type = $revision->getInformation()->getMimeType();
141  if ($index === self::ACTION_UNZIP
142  && !in_array($mime_type, ['application/zip', 'application/x-zip-compressed'])
143  ) {
144  continue;
145  }
146 
147  $target = $a->getTarget();
148  $target = $this->url_builder->withURI($target)
149  ->withParameter(
150  $this->url_token,
151  $this->hash($rid->serialize())
152  )->buildURI();
153 
154  if (!$a->isAsync()) {
155  $items[] = $this->ui_factory->link()->standard(
156  $a->getLabel(),
157  (string) $target
158  );
159  } else {
160  $this->modals[] = $modal = $this->ui_factory->modal()->interruptive(
161  $a->getLabel(),
162  $a->getLabel(),
163  '#'
164  )->withAsyncRenderUrl($target->__toString());
165 
166  $items[] = $this->ui_factory->button()->shy(
167  $a->getLabel(),
168  $modal->getShowSignal()
169  );
170  }
171  }
172  return $this->ui_factory->dropdown()->standard(
173  $items
174  );
175  }
176 
177  private function buildURI(
178  string $command
179  ): URI {
180  return new URI(
181  ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
182  \ilResourceCollectionGUI::class,
183  $command
184  )
185  );
186  }
187 }
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34
__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:25
URLBuilder.
Definition: URLBuilder.php:39