ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilBTControllerGUI.php
Go to the documentation of this file.
1 <?php
2 
21 
29 {
30  use DIC;
31  public const FROM_URL = 'from_url';
32  public const OBSERVER_ID = 'observer_id';
33  public const SELECTED_OPTION = 'selected_option';
34  public const CMD_ABORT = 'abortBucket';
35  public const CMD_REMOVE = 'abortBucket';
36  public const CMD_USER_INTERACTION = 'userInteraction';
37  public const IS_ASYNC = 'bt_task_is_async';
38  public const CMD_GET_REPLACEMENT_ITEM = "getAsyncReplacementItem";
39 
40 
41  public function executeCommand(): void
42  {
43  $cmd = $this->ctrl()->getCmd();
44  switch ($cmd) {
45  case self::CMD_GET_REPLACEMENT_ITEM:
46  $this->getAsyncReplacementItem();
47  break;
48  case self::CMD_USER_INTERACTION:
49  $this->userInteraction();
50  break;
51  case self::CMD_ABORT:
52  case self::CMD_REMOVE:
53  $this->abortBucket();
54  break;
55  default:
56  break;
57  }
58  }
59 
60 
61  protected function userInteraction(): void
62  {
63  $observer_id = (int) $this->http()->request()->getQueryParams()[self::OBSERVER_ID];
64  $selected_option = $this->http()->request()->getQueryParams()[self::SELECTED_OPTION];
65  $from_url = $this->getFromURL();
66 
67  $observer = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
68  if ($observer->getUserId() !== $this->user()->getId()) {
69  return;
70  }
71  $option = new UserInteractionOption("", $selected_option);
72  $this->dic()->backgroundTasks()->taskManager()->continueTask($observer, $option);
73  if ($this->http()->request()->getQueryParams()[self::IS_ASYNC] === "true") {
74  $this->http()->close();
75  }
76  $this->ctrl()->redirectToURL($from_url);
77  }
78 
79 
80  protected function abortBucket(): void
81  {
82  $observer_id = (int) $this->http()->request()->getQueryParams()[self::OBSERVER_ID];
83  $from_url = $this->getFromURL();
84 
85  $bucket = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
86 
87  $this->dic()->backgroundTasks()->taskManager()->quitBucket($bucket);
88  if ($this->http()->request()->getQueryParams()[self::IS_ASYNC] === "true") {
89  exit;
90  }
91  $this->ctrl()->redirectToURL($from_url);
92  }
93 
94 
99  protected function getAsyncReplacementItem(): void
100  {
101  $observer_id = (int) $this->http()->request()->getQueryParams()[self::OBSERVER_ID];
102  $bucket = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
103 
104  $item_source = new ilBTPopOverGUI($this->dic());
105  $this->dic()->language()->loadLanguageModule('background_tasks');
106  $item = $item_source->getItemForObserver($bucket);
107  echo $this->dic()->ui()->renderer()->renderAsync($item);
108  exit;
109  }
110 
111 
112  protected function getFromURL(): string
113  {
114  return self::unhash($this->http()->request()->getQueryParams()[self::FROM_URL]);
115  }
116 
117 
121  public static function hash($url): string
122  {
123  return base64_encode((string) $url);
124  }
125 
126 
130  public static function unhash($url): string
131  {
132  return base64_decode((string) $url);
133  }
134 }
$url
Definition: shib_logout.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAsyncReplacementItem()
Loads one single aggregate notification item representing a button async to replace an existing one...
static http()
Fetches the global http state from ILIAS.
Class ilBTControllerGUI.
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...