ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BadgeNotificationProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27
29{
30 final public const NOTIFICATION_TYPE = 'badge_received';
31
32 public function getNotifications(): array
33 {
34 $lng = $this->dic->language();
35 $ui = $this->dic->ui();
36 $user = $this->dic->user();
37 $ctrl = $this->dic->ctrl();
38
39 $lng->loadLanguageModule("badge");
40
41 $factory = $this->globalScreen()->notifications()->factory();
42 $id = function (string $id): IdentificationInterface {
43 return $this->if->identifier($id);
44 };
45
46 $new_badges = \ilBadgeAssignment::getNewCounter($user->getId());
47 if ($new_badges === 0) {
48 return [];
49 }
50
51 //Creating a badge Notification Item
52 $badge_icon = $this->dic->ui()->factory()->symbol()->icon()->standard("bdga", $lng->txt("badge_badge"));
53 $badge_title = $ui->factory()->link()->standard(
54 $lng->txt("mm_badges"),
55 $ctrl->getLinkTargetByClass(["ilDashboardGUI"], "jumpToBadges")
56 );
57 $latest = new \ilDateTime(\ilBadgeAssignment::getLatestTimestamp($user->getId()), IL_CAL_UNIX);
59 $badge_notification_item = $ui->factory()->item()->notification($badge_title, $badge_icon)
60 ->withDescription(str_replace("%1", (string) $new_badges, $lng->txt("badge_new_badges")))
61 ->withProperties([$lng->txt("time") => \ilDatePresentation::formatDate($latest)]);
62
63 $osd_notification_handler = new ilNotificationOSDHandler(new ilNotificationOSDRepository($this->dic->database()));
64
65 $group = $factory->standardGroup($id('badge_bucket_group'))->withTitle($lng->txt('badge_badge'))
66 ->addNotification(
67 $factory->standard($id('badge_bucket'))->withNotificationItem($badge_notification_item)
68 ->withClosedCallable(
69 function () use ($user, $osd_notification_handler): void {
70 // Stuff we do, when the notification is closed
71 $noti_repo = new \ILIAS\Badge\Notification\BadgeNotificationPrefRepository($user);
72 $noti_repo->updateLastCheckedTimestamp();
73
74 $osd_notification_handler->deleteStaleNotificationsForUserAndType(
75 $this->dic->user()->getId(),
76 self::NOTIFICATION_TYPE
77 );
78 }
79 )
80 ->withNewAmount($new_badges)
81 )
82 ->withOpenedCallable(static function () {
83 // Stuff we do, when the notification is opened
84 });
85
86 return [
87 $group,
88 ];
89 }
90}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_UNIX
static getNewCounter(int $a_user_id)
static getLatestTimestamp(int $a_user_id)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
global $lng
Definition: privfeed.php:31