ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI Class Reference
+ Inheritance diagram for ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI:
+ Collaboration diagram for ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI:

Public Member Functions

 executeCommand ()
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 
 getUnsafeGetCommands ()
 This method must return a list of unsafe GET commands. More...
 
 getSafePostCommands ()
 This method must return a list of safe POST commands. More...
 

Static Public Member Functions

static hash (string $url)
 
static unhash (string $url)
 

Data Fields

const FROM_URL = 'from_url'
 
const OBSERVER_ID = 'observer_id'
 
const SELECTED_OPTION = 'selected_option'
 
const CMD_ABORT = 'abortBucket'
 
const CMD_REMOVE = 'abortBucket'
 
const CMD_USER_INTERACTION = 'userInteraction'
 
const IS_ASYNC = 'bt_task_is_async'
 
const CMD_GET_REPLACEMENT_ITEM = "getAsyncReplacementItem"
 

Protected Member Functions

 userInteraction ()
 
 abortBucket ()
 
 getAsyncReplacementItem ()
 Loads one single aggregate notification item representing a button async to replace an existing one. More...
 

Private Member Functions

 getFromURL ()
 
 enforceBucketBelongsToCurrentUser (Bucket $bucket)
 
 defaultReturnUrl ()
 
 sendSuccessResponse (Stream $stream)
 
 redirectToCallerOrClose ()
 
 respondWithError (int $error_status_code, string $message)
 
 retrieveSelectedInteractionOption ()
 
 wasInvokedAsynchronously ()
 
 retrieveObserverIdFromRequest ()
 
 retrieveFromUrlFromRequest ()
 

Detailed Description

Member Function Documentation

◆ abortBucket()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::abortBucket ( )
protected

Definition at line 104 of file ControllerGUI.php.

104 : void
105 {
106 $observer_id = $this->retrieveObserverIdFromRequest();
107 if ($observer_id === null) {
108 $this->respondWithError(StatusCode::HTTP_BAD_REQUEST, 'Bad Request');
109 }
110
111 $bucket = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
112
113 $this->enforceBucketBelongsToCurrentUser($bucket);
114
115 $this->dic()->backgroundTasks()->taskManager()->quitBucket($bucket);
116
118 }
respondWithError(int $error_status_code, string $message)

References ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\enforceBucketBelongsToCurrentUser(), ILIAS\HTTP\StatusCode\HTTP_BAD_REQUEST, ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\redirectToCallerOrClose(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\respondWithError(), and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\retrieveObserverIdFromRequest().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ defaultReturnUrl()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::defaultReturnUrl ( )
private

Definition at line 202 of file ControllerGUI.php.

202 : string
203 {
204 return ilUtil::_getHttpPath();
205 }
static _getHttpPath()

References ilUtil\_getHttpPath().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\getFromURL(), and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\respondWithError().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ enforceBucketBelongsToCurrentUser()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::enforceBucketBelongsToCurrentUser ( Bucket  $bucket)
private

◆ executeCommand()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::executeCommand ( )

Definition at line 50 of file ControllerGUI.php.

50 : void
51 {
52 $cmd = $this->ctrl()->getCmd();
53 switch ($cmd) {
56 break;
58 $this->userInteraction();
59 break;
60 case self::CMD_ABORT:
62 $this->abortBucket();
63 break;
64 default:
65 break;
66 }
67 }
getAsyncReplacementItem()
Loads one single aggregate notification item representing a button async to replace an existing one.

References ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\abortBucket(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\CMD_ABORT, ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\CMD_GET_REPLACEMENT_ITEM, ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\CMD_REMOVE, ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\CMD_USER_INTERACTION, ILIAS\Repository\ctrl(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\getAsyncReplacementItem(), and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\userInteraction().

+ Here is the call graph for this function:

◆ getAsyncReplacementItem()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::getAsyncReplacementItem ( )
protected

Loads one single aggregate notification item representing a button async to replace an existing one.

Definition at line 125 of file ControllerGUI.php.

125 : void
126 {
127 $observer_id = $this->retrieveObserverIdFromRequest();
128 if ($observer_id === null) {
129 $this->respondWithError(StatusCode::HTTP_BAD_REQUEST, 'Bad Request');
130 }
131
132 $bucket = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
133
134 $this->enforceBucketBelongsToCurrentUser($bucket);
135
136 $item_source = new PopOverGUI($this->dic());
137 $this->dic()->language()->loadLanguageModule('background_tasks');
138 $item = $item_source->getItemForObserver($bucket);
139
140 $this->sendSuccessResponse(
142 $this->dic()->ui()->renderer()->renderAsync($item)
143 )
144 );
145 }
renderer()
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41

References ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\enforceBucketBelongsToCurrentUser(), ILIAS\HTTP\StatusCode\HTTP_BAD_REQUEST, ILIAS\Filesystem\Stream\Streams\ofString(), renderer(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\respondWithError(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\retrieveObserverIdFromRequest(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\sendSuccessResponse(), and ILIAS\Repository\ui().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFromURL()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::getFromURL ( )
private

Definition at line 148 of file ControllerGUI.php.

148 : URI
149 {
150 $uri = (new Factory())->uri($this->defaultReturnUrl());
151
152 $decoded_from_url = $this->retrieveFromUrlFromRequest();
153 if ($decoded_from_url === null || $decoded_from_url === '') {
154 return $uri;
155 }
156
157 $from_url = self::unhash($decoded_from_url);
158 if ($from_url === false) {
159 return $uri;
160 }
161
162 $from_url_parts = parse_url($from_url);
163 if (!is_array($from_url_parts)) {
164 return $uri;
165 }
166
167 $uri = $uri->withPath(null)->withQuery(null)->withFragment(null);
168
169 $mutators = [
170 'path' => static fn(URI $u, string $v): URI => $u->withPath($v),
171 'query' => static fn(URI $u, string $v): URI => $u->withQuery($v),
172 'fragment' => static fn(URI $u, string $v): URI => $u->withFragment($v),
173 ];
174
175 foreach ($mutators as $key => $apply) {
176 $value = $from_url_parts[$key] ?? null;
177 if (is_string($value) && $value !== '') {
178 $uri = $apply($uri, $value);
179 }
180 }
181
182 return $uri;
183 }

References ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\defaultReturnUrl(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\retrieveFromUrlFromRequest(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\unhash(), ILIAS\Data\URI\withFragment(), ILIAS\Data\URI\withPath(), and ILIAS\Data\URI\withQuery().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\redirectToCallerOrClose().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSafePostCommands()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::getSafePostCommands ( )

This method must return a list of safe POST commands.

Safe post commands returned by this method will no longer be CSRF protected and will NOT be appended by an ilCtrlToken.

Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 78 of file ControllerGUI.php.

78 : array
79 {
80 return [];
81 }

◆ getUnsafeGetCommands()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::getUnsafeGetCommands ( )

This method must return a list of unsafe GET commands.

Unsafe get commands returned by this method will now be CSRF protected, which means an ilCtrlToken is appended each time a link-target is generated to the class implementing this interface with a command from that list.

Tokens will be validated in

See also
ilCtrlInterface::getCmd(), whereas the fallback command will be used if the CSRF validation fails.
Returns
string[]

Implements ilCtrlSecurityInterface.

Definition at line 69 of file ControllerGUI.php.

69 : array
70 {
71 return array_unique([
72 self::CMD_ABORT,
73 self::CMD_REMOVE,
74 self::CMD_USER_INTERACTION,
75 ]);
76 }

◆ hash()

static ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::hash ( string  $url)
static

Definition at line 185 of file ControllerGUI.php.

185 : string
186 {
187 return base64_encode((string) $url);
188 }

Referenced by ILIAS\BackgroundTasks\Implementation\UI\PopOverGUI\addFromUrlToNextRequest().

+ Here is the caller graph for this function:

◆ redirectToCallerOrClose()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::redirectToCallerOrClose ( )
private

Definition at line 220 of file ControllerGUI.php.

220 : never
221 {
222 if (!$this->wasInvokedAsynchronously()) {
223 $this->ctrl()->redirectToURL((string) $this->getFromURL());
224 }
225
226 $this->http()->close();
227 }
static http()
Fetches the global http state from ILIAS.

References ILIAS\Repository\ctrl(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\getFromURL(), ILIAS\FileDelivery\http(), and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\wasInvokedAsynchronously().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\abortBucket(), and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\userInteraction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ respondWithError()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::respondWithError ( int  $error_status_code,
string  $message 
)
private

Definition at line 229 of file ControllerGUI.php.

229 : never
230 {
231 $response = $this->http()->response()->withStatus($error_status_code, $message);
232 if ($error_status_code === StatusCode::HTTP_FORBIDDEN && !$this->wasInvokedAsynchronously()) {
233 $this->tpl()->setOnScreenMessage(
234 $this->tpl()::MESSAGE_TYPE_FAILURE,
235 $this->lng()->txt('permission_denied'),
236 true
237 );
239 ->withStatus(StatusCode::HTTP_FOUND, 'Found')
240 ->withHeader(ResponseHeader::LOCATION, $this->defaultReturnUrl());
241 }
242
243 $this->http()->saveResponse($response);
244 $this->http()->sendResponse();
245 $this->http()->close();
246 }
$response
Definition: xapitoken.php:92

References $message, $response, ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\defaultReturnUrl(), ILIAS\FileDelivery\http(), ILIAS\HTTP\StatusCode\HTTP_FORBIDDEN, ILIAS\HTTP\StatusCode\HTTP_FOUND, ILIAS\Repository\lng(), ILIAS\HTTP\Response\ResponseHeader\LOCATION, and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\wasInvokedAsynchronously().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\abortBucket(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\enforceBucketBelongsToCurrentUser(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\getAsyncReplacementItem(), and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\userInteraction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieveFromUrlFromRequest()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::retrieveFromUrlFromRequest ( )
private

Definition at line 281 of file ControllerGUI.php.

281 : ?string
282 {
283 return $this->http()->wrapper()->query()->retrieve(
284 self::FROM_URL,
285 $this->dic()->refinery()->byTrying([
286 $this->dic()->refinery()->kindlyTo()->string(),
287 $this->dic()->refinery()->always(null)
288 ])
289 );
290 }

References ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\getFromURL().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieveObserverIdFromRequest()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::retrieveObserverIdFromRequest ( )
private

Definition at line 270 of file ControllerGUI.php.

270 : ?int
271 {
272 return $this->http()->wrapper()->query()->retrieve(
273 self::OBSERVER_ID,
274 $this->dic()->refinery()->byTrying([
275 $this->dic()->refinery()->kindlyTo()->int(),
276 $this->dic()->refinery()->always(null)
277 ])
278 );
279 }

References ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\abortBucket(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\getAsyncReplacementItem(), and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\userInteraction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ retrieveSelectedInteractionOption()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::retrieveSelectedInteractionOption ( )
private

Definition at line 248 of file ControllerGUI.php.

248 : ?string
249 {
250 return $this->http()->wrapper()->query()->retrieve(
251 self::SELECTED_OPTION,
252 $this->dic()->refinery()->byTrying([
253 $this->dic()->refinery()->kindlyTo()->string(),
254 $this->dic()->refinery()->always(null)
255 ])
256 );
257 }

References ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\userInteraction().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendSuccessResponse()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::sendSuccessResponse ( Stream  $stream)
private

Definition at line 207 of file ControllerGUI.php.

207 : void
208 {
209 $response = $this->http()->response()
210 ->withStatus(StatusCode::HTTP_OK, 'OK')
211 ->withBody($stream);
212 $this->http()->saveResponse($response);
213
214 if ($this->wasInvokedAsynchronously()) {
215 $this->http()->sendResponse();
216 $this->http()->close();
217 }
218 }

References $response, ILIAS\FileDelivery\http(), ILIAS\HTTP\StatusCode\HTTP_OK, and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\wasInvokedAsynchronously().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\getAsyncReplacementItem().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unhash()

static ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::unhash ( string  $url)
static

Definition at line 190 of file ControllerGUI.php.

190 : string|false
191 {
192 return base64_decode((string) $url);
193 }

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\getFromURL().

+ Here is the caller graph for this function:

◆ userInteraction()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::userInteraction ( )
protected

Definition at line 83 of file ControllerGUI.php.

83 : void
84 {
85 $observer_id = $this->retrieveObserverIdFromRequest();
86 $selected_option = $this->retrieveSelectedInteractionOption();
87 if ($observer_id === null || $selected_option === null) {
89 }
90
91 $bucket = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
92
94
95 $this->dic()->backgroundTasks()->taskManager()->continueTask(
96 $bucket,
97 new UserInteractionOption('', $selected_option)
98 );
99
101 }

References ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\enforceBucketBelongsToCurrentUser(), ILIAS\HTTP\StatusCode\HTTP_BAD_REQUEST, ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\redirectToCallerOrClose(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\respondWithError(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\retrieveObserverIdFromRequest(), and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\retrieveSelectedInteractionOption().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\executeCommand().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wasInvokedAsynchronously()

ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::wasInvokedAsynchronously ( )
private

Definition at line 259 of file ControllerGUI.php.

259 : bool
260 {
261 return $this->http()->wrapper()->query()->retrieve(
262 self::IS_ASYNC,
263 $this->dic()->refinery()->byTrying([
264 $this->dic()->refinery()->kindlyTo()->bool(),
265 $this->dic()->refinery()->always(false)
266 ])
267 );
268 }

References ILIAS\FileDelivery\http(), and ILIAS\Repository\refinery().

Referenced by ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\redirectToCallerOrClose(), ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\respondWithError(), and ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI\sendSuccessResponse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ CMD_ABORT

const ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::CMD_ABORT = 'abortBucket'

◆ CMD_GET_REPLACEMENT_ITEM

const ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::CMD_GET_REPLACEMENT_ITEM = "getAsyncReplacementItem"

◆ CMD_REMOVE

const ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::CMD_REMOVE = 'abortBucket'

◆ CMD_USER_INTERACTION

const ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::CMD_USER_INTERACTION = 'userInteraction'

◆ FROM_URL

const ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::FROM_URL = 'from_url'

◆ IS_ASYNC

const ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::IS_ASYNC = 'bt_task_is_async'

◆ OBSERVER_ID

const ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::OBSERVER_ID = 'observer_id'

◆ SELECTED_OPTION

const ILIAS\BackgroundTasks\Implementation\UI\ControllerGUI::SELECTED_OPTION = 'selected_option'

The documentation for this class was generated from the following file: