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