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
33
37final class ActionBuilder
38{
39 use URLSerializer;
40
44 private const ACTION_UNZIP = 'unzip';
48 private const ACTION_DOWNLOAD = 'download';
52 private const ACTION_REMOVE = 'remove';
56 public const ACTION_NAMESPACE = 'rcgui';
60 private array $modals = [];
63 private array $single_actions;
64
65 private array $appended_tokens = [];
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 private ActionProvider $action_provider
74 ) {
75 $this->single_actions = $this->action_provider->getSingleActions($this->request);
76 $this->initURIBuilder();
77 }
78
79 private function appendNamespaceToURIBuilder(string $namespace, string $param): URLBuilder
80 {
81 $key = $namespace . $param;
82 if (isset($this->appended_tokens[$key])) {
83 return $this->url_builder;
84 }
85
86 $parameters = $this->url_builder->acquireParameter(
87 [$namespace],
88 $param
89 );
90
91 $this->appended_tokens[$key] = $parameters[1];
92
93 return $this->url_builder = $parameters[0];
94 }
95
96 private function initURIBuilder(): void
97 {
98 $uri_builder = new URLBuilder(
99 new URI(
100 ILIAS_HTTP_PATH . '/' . $this->ctrl->getLinkTargetByClass(
101 \ilContainerResourceGUI::class,
103 )
104 )
105 );
106
107 $parameters = $uri_builder->acquireParameter(
108 [self::ACTION_NAMESPACE],
110 );
111
112 $this->url_builder = $parameters[0];
113 $this->url_token = $parameters[1];
114 }
115
116 public function getUrlBuilder(): URLBuilder
117 {
118 return $this->url_builder;
119 }
120
121 public function getUrlToken(): URLBuilderToken
122 {
123 return $this->url_token;
124 }
125
129 public function getActions(): array
130 {
131 $actions = [];
132
133 foreach ($this->single_actions as $key => $single_action) {
134 if ($single_action instanceof ExternalSingleAction) {
135 $this->url_builder = $this->appendNamespaceToURIBuilder(
136 $single_action->getParameterNamespace(),
137 $single_action->getPathParameterName()
138 );
139
140 $token = $this->appended_tokens[$single_action->getParameterNamespace(
141 ) . $single_action->getPathParameterName()] ?? $this->url_token;
142 } else {
144 }
145
146 if ($single_action->isBulk()) {
147 $action = $this->ui_factory->table()->action()->standard(
148 $single_action->getLabel(),
149 $this->url_builder->withURI($single_action->getAction()),
150 $token
151 );
152 } else {
153 $action = $this->ui_factory->table()->action()->single(
154 $single_action->getLabel(),
155 $this->url_builder->withURI($single_action->getAction()),
156 $token
157 );
158 }
159 $actions[$key] = $action->withAsync($single_action->isAsync());
160 }
161
162 return $actions;
163 }
164
166 {
167 return $this->action_provider;
168 }
169
170}
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
acquireParameter(array $namespace, string $name, ?string $initial_value=null)
Add a new parameter with a namespace and get its token for subsequent changes.
Definition: URLBuilder.php:119
__construct(private Request $request, private \ilCtrlInterface $ctrl, private Factory $ui_factory, private \ilLanguage $language, private Services $irss, private ActionProvider $action_provider)
appendNamespaceToURIBuilder(string $namespace, string $param)
language handling
if($err=$client->getError()) $namespace
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...
$token
Definition: xapitoken.php:70
$param
Definition: xapitoken.php:46