ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilBTControllerGUI.php
Go to the documentation of this file.
1 <?php
2 
5 
13 {
14  use DIC;
15  const FROM_URL = 'from_url';
16  const OBSERVER_ID = 'observer_id';
17  const SELECTED_OPTION = 'selected_option';
18  const CMD_ABORT = 'abortBucket';
19  const CMD_REMOVE = 'abortBucket';
20  const CMD_USER_INTERACTION = 'userInteraction';
21  const IS_ASYNC = 'bt_task_is_async';
22  const CMD_GET_REPLACEMENT_ITEM = "getAsyncReplacementItem";
23 
24 
25  public function executeCommand() : void
26  {
27  $cmd = $this->ctrl()->getCmd();
28  switch ($cmd) {
29  case self::CMD_GET_REPLACEMENT_ITEM:
30  $this->getAsyncReplacementItem();
31  break;
32  case self::CMD_USER_INTERACTION:
33  $this->userInteraction();
34  break;
35  case self::CMD_ABORT:
36  case self::CMD_REMOVE:
37  $this->abortBucket();
38  break;
39  default:
40  break;
41  }
42  }
43 
44 
45  protected function userInteraction() : void
46  {
47  $observer_id = (int) $this->http()->request()->getQueryParams()[self::OBSERVER_ID];
48  $selected_option = $this->http()->request()->getQueryParams()[self::SELECTED_OPTION];
49  $from_url = $this->getFromURL();
50 
51  $observer = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
52  if ((int) $observer->getUserId() !== (int) $this->user()->getId()) {
53  return;
54  }
55  $option = new UserInteractionOption("", $selected_option);
56  $this->dic()->backgroundTasks()->taskManager()->continueTask($observer, $option);
57  if ($this->http()->request()->getQueryParams()[self::IS_ASYNC] === "true") {
58  $this->http()->close();
59  }
60  $this->ctrl()->redirectToURL($from_url);
61  }
62 
63 
64  protected function abortBucket()
65  {
66  $observer_id = (int) $this->http()->request()->getQueryParams()[self::OBSERVER_ID];
67  $from_url = $this->getFromURL();
68 
69  $bucket = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
70 
71  $this->dic()->backgroundTasks()->taskManager()->quitBucket($bucket);
72  if ($this->http()->request()->getQueryParams()[self::IS_ASYNC] === "true") {
73  exit;
74  }
75  $this->ctrl()->redirectToURL($from_url);
76  }
77 
78 
83  protected function getAsyncReplacementItem()
84  {
85  $observer_id = (int) $this->http()->request()->getQueryParams()[self::OBSERVER_ID];
86  $bucket = $this->dic()->backgroundTasks()->persistence()->loadBucket($observer_id);
87 
88  $item_source = new ilBTPopOverGUI($this->dic());
89  $this->dic()->language()->loadLanguageModule('background_tasks');
90  $item = $item_source->getItemForObserver($bucket);
91  echo $this->dic()->ui()->renderer()->renderAsync($item);
92  exit;
93  }
94 
95 
99  protected function getFromURL()
100  {
101  $from_url = self::unhash($this->http()->request()->getQueryParams()[self::FROM_URL]);
102 
103  return $from_url;
104  }
105 
106 
112  public static function hash($url)
113  {
114  return base64_encode($url);
115  }
116 
117 
123  public static function unhash($url)
124  {
125  return base64_decode($url);
126  }
127 }
exit
Definition: login.php:29
user()
Definition: user.php:4
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.
$url