ILIAS  release_8 Revision v8.26
ilBTControllerGUI Class Reference

Class ilBTControllerGUI. More...

+ Inheritance diagram for ilBTControllerGUI:
+ Collaboration diagram for ilBTControllerGUI:

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()

ilBTControllerGUI::abortBucket ( )
protected

Definition at line 101 of file class.ilBTControllerGUI.php.

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

References enforceBucketBelongsToCurrentUser(), redirectToCallerOrClose(), respondWithError(), and retrieveObserverIdFromRequest().

Referenced by executeCommand().

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

◆ defaultReturnUrl()

ilBTControllerGUI::defaultReturnUrl ( )
private

Definition at line 199 of file class.ilBTControllerGUI.php.

199 : string
200 {
201 return ilUtil::_getHttpPath();
202 }
static _getHttpPath()

References ilUtil\_getHttpPath().

Referenced by getFromURL(), and respondWithError().

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

◆ enforceBucketBelongsToCurrentUser()

ilBTControllerGUI::enforceBucketBelongsToCurrentUser ( Bucket  $bucket)
private

Definition at line 192 of file class.ilBTControllerGUI.php.

192 : void
193 {
194 if ($bucket->getUserId() !== $this->user()->getId()) {
195 $this->respondWithError(StatusCode::HTTP_FORBIDDEN, 'Forbidden');
196 }
197 }

References ILIAS\BackgroundTasks\Bucket\getUserId(), and respondWithError().

Referenced by abortBucket(), getAsyncReplacementItem(), and userInteraction().

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

◆ executeCommand()

ilBTControllerGUI::executeCommand ( )

Definition at line 47 of file class.ilBTControllerGUI.php.

47 : void
48 {
49 $cmd = $this->ctrl()->getCmd();
50 switch ($cmd) {
53 break;
55 $this->userInteraction();
56 break;
57 case self::CMD_ABORT:
59 $this->abortBucket();
60 break;
61 default:
62 break;
63 }
64 }
getAsyncReplacementItem()
Loads one single aggregate notification item representing a button async to replace an existing one.

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

+ Here is the call graph for this function:

◆ getAsyncReplacementItem()

ilBTControllerGUI::getAsyncReplacementItem ( )
protected

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

Definition at line 122 of file class.ilBTControllerGUI.php.

122 : void
123 {
124 $observer_id = $this->retrieveObserverIdFromRequest();
125 if ($observer_id === null) {
126 $this->respondWithError(StatusCode::HTTP_BAD_REQUEST, 'Bad Request');
127 }
128
129 $bucket = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
130
131 $this->enforceBucketBelongsToCurrentUser($bucket);
132
133 $item_source = new ilBTPopOverGUI($this->dic());
134 $this->dic()->language()->loadLanguageModule('background_tasks');
135 $item = $item_source->getItemForObserver($bucket);
136
137 $this->sendSuccessResponse(
138 Streams::ofString(
139 $this->dic()->ui()->renderer()->renderAsync($item)
140 )
141 );
142 }
sendSuccessResponse(Stream $stream)
Class ilBTPopOverGUI.

References enforceBucketBelongsToCurrentUser(), respondWithError(), retrieveObserverIdFromRequest(), sendSuccessResponse(), and ILIAS\Repository\ui().

Referenced by executeCommand().

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

◆ getFromURL()

ilBTControllerGUI::getFromURL ( )
private

Definition at line 145 of file class.ilBTControllerGUI.php.

145 : URI
146 {
147 $uri = (new Factory())->uri($this->defaultReturnUrl());
148
149 $decoded_from_url = $this->retrieveFromUrlFromRequest();
150 if ($decoded_from_url === null || $decoded_from_url === '') {
151 return $uri;
152 }
153
154 $from_url = self::unhash($decoded_from_url);
155 if ($from_url === false) {
156 return $uri;
157 }
158
159 $from_url_parts = parse_url($from_url);
160 if (!is_array($from_url_parts)) {
161 return $uri;
162 }
163
164 $uri = $uri->withPath(null)->withQuery(null)->withFragment(null);
165
166 $mutators = [
167 'path' => static fn(URI $u, string $v): URI => $u->withPath($v),
168 'query' => static fn(URI $u, string $v): URI => $u->withQuery($v),
169 'fragment' => static fn(URI $u, string $v): URI => $u->withFragment($v),
170 ];
171
172 foreach ($mutators as $key => $apply) {
173 $value = $from_url_parts[$key] ?? null;
174 if (is_string($value) && $value !== '') {
175 $uri = $apply($uri, $value);
176 }
177 }
178
179 return $uri;
180 }
Builds data types.
Definition: Factory.php:21
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
static unhash(string $url)
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key, defaultReturnUrl(), retrieveFromUrlFromRequest(), unhash(), ILIAS\Data\URI\withFragment(), ILIAS\Data\URI\withPath(), and ILIAS\Data\URI\withQuery().

Referenced by redirectToCallerOrClose().

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

◆ getSafePostCommands()

ilBTControllerGUI::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 75 of file class.ilBTControllerGUI.php.

75 : array
76 {
77 return [];
78 }

◆ getUnsafeGetCommands()

ilBTControllerGUI::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 66 of file class.ilBTControllerGUI.php.

66 : array
67 {
68 return array_unique([
69 self::CMD_ABORT,
70 self::CMD_REMOVE,
71 self::CMD_USER_INTERACTION,
72 ]);
73 }

◆ hash()

static ilBTControllerGUI::hash ( string  $url)
static

Definition at line 182 of file class.ilBTControllerGUI.php.

182 : string
183 {
184 return base64_encode($url);
185 }
$url

References $url.

Referenced by ilBTPopOverGUI\addFromUrlToNextRequest().

+ Here is the caller graph for this function:

◆ redirectToCallerOrClose()

ilBTControllerGUI::redirectToCallerOrClose ( )
private

Definition at line 217 of file class.ilBTControllerGUI.php.

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

References ILIAS\Repository\ctrl(), getFromURL(), ILIAS\FileDelivery\http(), and wasInvokedAsynchronously().

Referenced by abortBucket(), and userInteraction().

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

◆ respondWithError()

ilBTControllerGUI::respondWithError ( int  $error_status_code,
string  $message 
)
private

Definition at line 226 of file class.ilBTControllerGUI.php.

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

References $message, $response, defaultReturnUrl(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), and wasInvokedAsynchronously().

Referenced by abortBucket(), enforceBucketBelongsToCurrentUser(), getAsyncReplacementItem(), and userInteraction().

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

◆ retrieveFromUrlFromRequest()

ilBTControllerGUI::retrieveFromUrlFromRequest ( )
private

Definition at line 278 of file class.ilBTControllerGUI.php.

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

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

Referenced by getFromURL().

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

◆ retrieveObserverIdFromRequest()

ilBTControllerGUI::retrieveObserverIdFromRequest ( )
private

Definition at line 267 of file class.ilBTControllerGUI.php.

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

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

Referenced by abortBucket(), getAsyncReplacementItem(), and userInteraction().

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

◆ retrieveSelectedInteractionOption()

ilBTControllerGUI::retrieveSelectedInteractionOption ( )
private

Definition at line 245 of file class.ilBTControllerGUI.php.

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

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

Referenced by userInteraction().

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

◆ sendSuccessResponse()

ilBTControllerGUI::sendSuccessResponse ( Stream  $stream)
private

Definition at line 204 of file class.ilBTControllerGUI.php.

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

References $response, ILIAS\FileDelivery\http(), and wasInvokedAsynchronously().

Referenced by getAsyncReplacementItem().

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

◆ unhash()

static ilBTControllerGUI::unhash ( string  $url)
static

Definition at line 187 of file class.ilBTControllerGUI.php.

187 : mixed
188 {
189 return base64_decode($url);
190 }

References $url.

Referenced by getFromURL().

+ Here is the caller graph for this function:

◆ userInteraction()

ilBTControllerGUI::userInteraction ( )
protected

Definition at line 80 of file class.ilBTControllerGUI.php.

80 : void
81 {
82 $observer_id = $this->retrieveObserverIdFromRequest();
83 $selected_option = $this->retrieveSelectedInteractionOption();
84 if ($observer_id === null || $selected_option === null) {
85 $this->respondWithError(StatusCode::HTTP_BAD_REQUEST, 'Bad Request');
86 }
87
88 $bucket = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
89
91
92 $this->dic()->backgroundTasks()->taskManager()->continueTask(
93 $bucket,
94 new UserInteractionOption('', $selected_option)
95 );
96
98 }

References enforceBucketBelongsToCurrentUser(), redirectToCallerOrClose(), respondWithError(), retrieveObserverIdFromRequest(), and retrieveSelectedInteractionOption().

Referenced by executeCommand().

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

◆ wasInvokedAsynchronously()

ilBTControllerGUI::wasInvokedAsynchronously ( )
private

Definition at line 256 of file class.ilBTControllerGUI.php.

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

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

Referenced by redirectToCallerOrClose(), respondWithError(), and sendSuccessResponse().

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

Field Documentation

◆ CMD_ABORT

const ilBTControllerGUI::CMD_ABORT = 'abortBucket'

◆ CMD_GET_REPLACEMENT_ITEM

const ilBTControllerGUI::CMD_GET_REPLACEMENT_ITEM = "getAsyncReplacementItem"

Definition at line 45 of file class.ilBTControllerGUI.php.

Referenced by executeCommand(), and ilBTPopOverGUI\getRefreshUrl().

◆ CMD_REMOVE

const ilBTControllerGUI::CMD_REMOVE = 'abortBucket'

◆ CMD_USER_INTERACTION

const ilBTControllerGUI::CMD_USER_INTERACTION = 'userInteraction'

◆ FROM_URL

const ilBTControllerGUI::FROM_URL = 'from_url'

Definition at line 38 of file class.ilBTControllerGUI.php.

Referenced by ilBTPopOverGUI\addFromUrlToNextRequest().

◆ IS_ASYNC

const ilBTControllerGUI::IS_ASYNC = 'bt_task_is_async'

Definition at line 44 of file class.ilBTControllerGUI.php.

Referenced by ilBTPopOverGUI\getCloseButtonAction().

◆ OBSERVER_ID

const ilBTControllerGUI::OBSERVER_ID = 'observer_id'

◆ SELECTED_OPTION

const ilBTControllerGUI::SELECTED_OPTION = 'selected_option'

Definition at line 40 of file class.ilBTControllerGUI.php.

Referenced by ilBTPopOverGUI\getCloseButtonAction().


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