ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilLSCompletionNotificationProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
27 {
28  public const NOTIFICATION_TYPE = 'lso_completion';
29  public const NOTIFICATION_TIME_PREFERENCE_KEY = 'lso_completion_note_ts';
30 
31  public function getNotifications(): array
32  {
33  $current_user = $this->dic['ilUser'];
34 
35  if ($current_user->getId() === 0 || $current_user->isAnonymous()) {
36  return [];
37  }
38 
39  $osd_notification_handler = new ilNotificationOSDHandler(new ilNotificationOSDRepository($this->dic->database()));
40  $left_interval_timestamp = $current_user->getPref(self::NOTIFICATION_TIME_PREFERENCE_KEY);
41  $notifications = $osd_notification_handler->getOSDNotificationsForUser(
42  $current_user->getId(),
43  false,
44  time() - $left_interval_timestamp,
45  self::NOTIFICATION_TYPE
46  );
47 
48  if (count($notifications) === 0) {
49  return [];
50  }
51 
52  $icon = $this->dic['ui.factory']->symbol()->icon()->standard(Standard::LSO, 'lso_completion');
53  $item_factory = $this->dic['ui.factory']->item();
54  $lng = $this->dic['lng'];
55  $lng->loadLanguageModule('lso');
56 
57 
58  $group = $this->globalScreen()->notifications()->factory()->standardGroup(
59  $this->if->identifier('lso_bucket_group')
60  )
61  ->withTitle($lng->txt('obj_lso'));
62 
63  foreach ($notifications as $notification) {
64  $lso_title = $notification->getObject()->title;
65  $title = sprintf($lng->txt('notification_lso_completed_title'), $lso_title);
66  $notification_item = $item_factory->notification($title, $icon);
67 
68  $group->addNotification(
69  $this->globalScreen()->notifications()->factory()->standard(
70  $this->if->identifier('lso_bucket')
71  )
72  ->withNotificationItem($notification_item)
73  ->withClosedCallable(
74  function () use ($current_user, $osd_notification_handler): void {
75  $current_user->writePref(self::NOTIFICATION_TIME_PREFERENCE_KEY, (string) time());
76  $osd_notification_handler->deleteStaleNotificationsForUserAndType(
77  $current_user->getId(),
78  self::NOTIFICATION_TYPE
79  );
80  }
81  )
82  ->withNewAmount(count($notifications))
83  );
84  }
85 
86  return [$group];
87  }
88 }
standard()
description: > This is an example, of how the Notification Slate is generated by assigning Notificat...
Definition: standard.php:38
factory()
if(!file_exists('../ilias.ini.php'))
global $lng
Definition: privfeed.php:31