ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilBTPopOverGUI Class Reference

Class ilBTPopOverGUI. More...

+ Collaboration diagram for ilBTPopOverGUI:

Public Member Functions

 __construct (\ILIAS\DI\Container $dic)
 
 getNotificationItem (int $nr_buckets)
 Get the Notification Items. More...
 
 getItemForObserver (Bucket $observer)
 

Protected Member Functions

 getAggregateItems ()
 
 getItemWithOnCloseDecoration (ILIAS\UI\Component\Item\Notification $item)
 

Protected Attributes

 $dic
 

Private Member Functions

 getDefaultCardContent (Bucket $observer)
 
 getProgressbar (Bucket $observer)
 
 getCloseButtonAction (UserInteraction\Option $option, $redirect_uri, Bucket $observer)
 
 getRefreshUrl (Bucket $observer)
 
 addFromUrlToNextRequest (string $redirect_uri)
 
 txt (string $id)
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilBTPopOverGUI::__construct ( \ILIAS\DI\Container  $dic)

Definition at line 27 of file class.ilBTPopOverGUI.php.

References $dic.

28  {
29  $this->dic = $dic;
30  }

Member Function Documentation

◆ addFromUrlToNextRequest()

ilBTPopOverGUI::addFromUrlToNextRequest ( string  $redirect_uri)
private

Definition at line 264 of file class.ilBTPopOverGUI.php.

References ilBTControllerGUI\FROM_URL, and ilBTControllerGUI\hash().

Referenced by getCloseButtonAction(), and getDefaultCardContent().

264  : void
265  {
266  $this->dic->ctrl()->setParameterByClass(ilBTControllerGUI::class, ilBTControllerGUI::FROM_URL, ilBTControllerGUI::hash($redirect_uri));
267  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAggregateItems()

ilBTPopOverGUI::getAggregateItems ( )
protected
Returns
ILIAS[]

Definition at line 54 of file class.ilBTPopOverGUI.php.

References getItemForObserver().

Referenced by getNotificationItem().

54  : array
55  {
56  $persistence = $this->dic->backgroundTasks()->persistence();
57  $items = [];
58  $observer_ids = $persistence->getBucketIdsOfUser($this->dic->user()->getId(), 'id', 'DESC');
59  foreach ($persistence->loadBuckets($observer_ids) as $observer) {
60  $items[] = $this->getItemForObserver($observer);
61  }
62 
63  return $items;
64  }
getItemForObserver(Bucket $observer)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCloseButtonAction()

ilBTPopOverGUI::getCloseButtonAction ( UserInteraction\Option  $option,
  $redirect_uri,
Bucket  $observer 
)
private

Definition at line 229 of file class.ilBTPopOverGUI.php.

References addFromUrlToNextRequest(), ilBTControllerGUI\CMD_ABORT, ilBTControllerGUI\CMD_REMOVE, ilBTControllerGUI\CMD_USER_INTERACTION, ilBTControllerGUI\IS_ASYNC, ilBTControllerGUI\OBSERVER_ID, and ilBTControllerGUI\SELECTED_OPTION.

Referenced by getItemForObserver().

229  : string
230  {
231  $ctrl = $this->dic->ctrl();
232  $persistence = $this->dic->backgroundTasks()->persistence();
233  $ctrl->setParameterByClass(ilBTControllerGUI::class, ilBTControllerGUI::OBSERVER_ID, $persistence->getBucketContainerId($observer));
234  $this->addFromUrlToNextRequest($redirect_uri);
235  $ctrl->setParameterByClass(ilBTControllerGUI::class, ilBTControllerGUI::IS_ASYNC, "true");
236 
237  switch ($option->getValue()) {
238  case AbstractTask::MAIN_ABORT:
239  $action = $ctrl->getLinkTargetByClass([ilBTControllerGUI::class], ilBTControllerGUI::CMD_ABORT);
240  break;
241  case AbstractTask::MAIN_REMOVE:
242  $action = $ctrl->getLinkTargetByClass([ilBTControllerGUI::class], ilBTControllerGUI::CMD_REMOVE);
243  break;
244  default:
245  $ctrl->setParameterByClass(ilBTControllerGUI::class, ilBTControllerGUI::SELECTED_OPTION, $option->getValue());
246  $action = $ctrl->getLinkTargetByClass([ilBTControllerGUI::class], ilBTControllerGUI::CMD_USER_INTERACTION);
247  break;
248  }
249 
250  return $action;
251  }
addFromUrlToNextRequest(string $redirect_uri)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultCardContent()

ilBTPopOverGUI::getDefaultCardContent ( Bucket  $observer)
private

Definition at line 146 of file class.ilBTPopOverGUI.php.

References $factory, addFromUrlToNextRequest(), ilBTControllerGUI\CMD_USER_INTERACTION, ilBTControllerGUI\FROM_URL, ILIAS\BackgroundTasks\Bucket\getCurrentTask(), getProgressbar(), ilBTControllerGUI\hash(), ilBTControllerGUI\OBSERVER_ID, and ilBTControllerGUI\SELECTED_OPTION.

Referenced by getItemForObserver().

146  : Legacy
147  {
148  return $this->getProgressbar($observer);
149  }
getProgressbar(Bucket $observer)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getItemForObserver()

ilBTPopOverGUI::getItemForObserver ( Bucket  $observer)

Definition at line 67 of file class.ilBTPopOverGUI.php.

References Vendor\Package\$f, $message, $url, getCloseButtonAction(), ILIAS\BackgroundTasks\Bucket\getCurrentTask(), getDefaultCardContent(), getItemWithOnCloseDecoration(), ILIAS\BackgroundTasks\Bucket\getLastHeartbeat(), getProgressbar(), getRefreshUrl(), ILIAS\BackgroundTasks\Bucket\getState(), ILIAS\BackgroundTasks\Bucket\getTitle(), and txt().

Referenced by getAggregateItems().

68  {
69  $redirect_uri = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
70 
71  $f = $this->dic->ui()->factory();
72 
73  $state = (int) $observer->getState();
74  $current_task = $observer->getCurrentTask();
75 
76  $icon = $f->symbol()->icon()->standard("bgtk", $this->txt("bg_task"));
77  $title = $observer->getTitle() . ($state === State::SCHEDULED ? " ({$this->txt('scheduled')})" : "");
78 
79 
80  $description_text = $this->txt('background_tasks');
81 
82  if ($state === State::USER_INTERACTION) {
83  $actions = $this->getUserInteractionContent($observer, $redirect_uri);
84  $primary_action = array_pop($actions);
85  if ($primary_action instanceof Button) {
86  $title = $primary_action->withLabel($title);
87  }
88 
89  $item = $f->item()->notification($title, $icon);
90  $item = $this->getItemWithOnCloseDecoration($item);
91 
92 // $item = $item->withProperties([
93 // $this->dic->language()->txt('nc_mail_prop_time') => \ilDatePresentation::formatDate(
94 // new \ilDateTime(time(), IL_CAL_UNIX)
95 // )
96 // ]);
97 
98  $item = $item->withActions($f->dropdown()->standard($actions));
99  $input = $current_task->getInput();
100  $message = $current_task->getMessage($input);
101 
102  if ((!empty($message)) and ($message != null)) {
103  $item = $item->withDescription($message);
104  } else {
105  $item = $item->withAdditionalContent($this->getProgressbar($observer));
106  }
107 
108  return $item->withCloseAction(
109  $this->getCloseButtonAction($current_task->getRemoveOption(), $redirect_uri, $observer)
110  );
111  }
112 
113  $item = $f->item()->notification($title, $icon);
114  $item = $this->getItemWithOnCloseDecoration($item);
115 
116  if ($state === State::RUNNING) {
117  $url = $this->getRefreshUrl($observer);
118  //Running Items probably need to refresh themselves, right?
119  $item = $item->withAdditionalOnLoadCode(function ($id) use ($url) {
120  //Note this is only for demo purposes, adapt as needed.
121  return "var notification_item = il.UI.item.notification.getNotificationItemObject($('#$id'));
122  il.BGTask.refreshItem(notification_item,'$url');";
123  });
124 
125  $expected = $current_task->getExpectedTimeOfTaskInSeconds();
126  $possibly_failed = ($observer->getLastHeartbeat() < (time() - $expected));
127  if ($possibly_failed === true) {
128  $item = $item->withDescription($this->txt('task_might_be_failed'));
129  $item = $item->withCloseAction(
130  $this->getCloseButtonAction($current_task->getAbortOption(), $redirect_uri, $observer)
131  );
132  }
133  }
134 
135  return $item->withAdditionalContent($this->getDefaultCardContent($observer));
136  }
getDefaultCardContent(Bucket $observer)
getLastHeartbeat()
When was the last time that something happened on this bucket?
getProgressbar(Bucket $observer)
getRefreshUrl(Bucket $observer)
getCloseButtonAction(UserInteraction\Option $option, $redirect_uri, Bucket $observer)
$message
Definition: xapiexit.php:14
$url
getItemWithOnCloseDecoration(ILIAS\UI\Component\Item\Notification $item)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getItemWithOnCloseDecoration()

ilBTPopOverGUI::getItemWithOnCloseDecoration ( ILIAS\UI\Component\Item\Notification  $item)
protected

Definition at line 138 of file class.ilBTPopOverGUI.php.

References txt().

Referenced by getItemForObserver().

139  {
140  $description_text = $this->txt('background_tasks');
141  return $item->withAdditionalOnLoadCode(function ($id) use ($description_text) {
142  return "il.BGTask.updateDescriptionOnClose('#$id','$description_text');";
143  });
144  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNotificationItem()

ilBTPopOverGUI::getNotificationItem ( int  $nr_buckets)

Get the Notification Items.

DOES NOT DO ANY PERMISSION CHECKS.

Definition at line 36 of file class.ilBTPopOverGUI.php.

References getAggregateItems(), and txt().

37  {
38  $ui_factory = $this->dic->ui()->factory();
39 
40  $title = $ui_factory->link()->standard($this->txt('background_tasks'), '#');
41  $icon = $ui_factory->symbol()->icon()->standard('bgtk', $this->txt('background_tasks'));
42 
43  return $this->dic->ui()->factory()
44  ->item()
45  ->notification($title, $icon)
46  ->withDescription("$nr_buckets {$this->txt('background_tasks')}")
47  ->withAggregateNotifications($this->getAggregateItems());
48  }
+ Here is the call graph for this function:

◆ getProgressbar()

ilBTPopOverGUI::getProgressbar ( Bucket  $observer)
private

Definition at line 201 of file class.ilBTPopOverGUI.php.

References ILIAS\BackgroundTasks\Bucket\getOverallPercentage(), and ILIAS\BackgroundTasks\Bucket\getState().

Referenced by getDefaultCardContent(), and getItemForObserver().

201  : Legacy
202  {
203  $percentage = $observer->getOverallPercentage();
204 
205  switch (true) {
206  case ((int) $percentage === 100):
207  $running = "";
208  $content = $this->dic->language()->txt("completed");
209  break;
210  case ((int) $observer->getState() === State::USER_INTERACTION):
211  $running = "";
212  $content = $this->dic->language()->txt("waiting");
213  break;
214  default:
215  $running = "active";
216  $content = "{$percentage}%";
217  break;
218  }
219 
220  return $this->dic->ui()->factory()->legacy(" <div class='progress'>
221  <div class='progress-bar progress-bar-striped {$running}' role='progressbar' aria-valuenow='{$percentage}'
222  aria-valuemin='0' aria-valuemax='100' style='width:{$percentage}%'>
223  {$content}
224  </div>
225  </div> ");
226  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRefreshUrl()

ilBTPopOverGUI::getRefreshUrl ( Bucket  $observer)
private

Definition at line 254 of file class.ilBTPopOverGUI.php.

References ilBTControllerGUI\CMD_GET_REPLACEMENT_ITEM, and ilBTControllerGUI\OBSERVER_ID.

Referenced by getItemForObserver().

254  : string
255  {
256  $ctrl = $this->dic->ctrl();
257  $persistence = $this->dic->backgroundTasks()->persistence();
258  $ctrl->setParameterByClass(ilBTControllerGUI::class, ilBTControllerGUI::OBSERVER_ID, $persistence->getBucketContainerId($observer));
259 
260  return $ctrl->getLinkTargetByClass([ilBTControllerGUI::class], ilBTControllerGUI::CMD_GET_REPLACEMENT_ITEM);
261  }
+ Here is the caller graph for this function:

◆ txt()

ilBTPopOverGUI::txt ( string  $id)
private

Definition at line 270 of file class.ilBTPopOverGUI.php.

Referenced by getItemForObserver(), getItemWithOnCloseDecoration(), and getNotificationItem().

270  : string
271  {
272  return $this->dic->language()->txt($id);
273  }
+ Here is the caller graph for this function:

Field Documentation

◆ $dic

ilBTPopOverGUI::$dic
protected

Definition at line 24 of file class.ilBTPopOverGUI.php.

Referenced by __construct().


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