ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
BadgeNotificationProvider.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
10
15{
19 public function getNotifications() : array
20 {
21 $lng = $this->dic->language();
22 $ui = $this->dic->ui();
23 $user = $this->dic->user();
24 $ctrl = $this->dic->ctrl();
25
26 $lng->loadLanguageModule("badge");
27
28 $factory = $this->globalScreen()->notifications()->factory();
29 $id = function (string $id) : IdentificationInterface {
30 return $this->if->identifier($id);
31 };
32
33 $new_badges = \ilBadgeAssignment::getNewCounter($user->getId());
34 if ($new_badges == 0) {
35 return [];
36 }
37
38 //Creating a badge Notification Item
39 $badge_icon = $this->dic->ui()->factory()->symbol()->icon()->standard("bdga", $lng->txt("badge_badge"))->withIsOutlined(true);
40 $badge_title = $ui->factory()->link()->standard(
41 $lng->txt("mm_badges"),
42 $ctrl->getLinkTargetByClass(["ilDashboardGUI"], "jumpToBadges")
43 );
44 $latest = new \ilDateTime(\ilBadgeAssignment::getLatestTimestamp($user->getId()), IL_CAL_UNIX);
45 $badge_notification_item = $ui->factory()->item()->notification($badge_title, $badge_icon)
46 ->withDescription(str_replace("%1", $new_badges, $lng->txt("badge_new_badges")))
47 ->withProperties([$lng->txt("time") => \ilDatePresentation::formatDate($latest)]);
48
49 $group = $factory->standardGroup($id('badge_bucket_group'))->withTitle($lng->txt('badge_badge'))
50 ->addNotification(
51 $factory->standard($id('badge_bucket'))->withNotificationItem($badge_notification_item)
52 ->withClosedCallable(
53 function () use ($user) {
54 // Stuff we do, when the notification is closed
55 $noti_repo = new \ILIAS\Badge\Notification\BadgeNotificationPrefRepository($user);
56 $noti_repo->updateLastCheckedTimestamp();
57 }
58 )
59 ->withNewAmount($new_badges)
60 )
61 ->withOpenedCallable(function () {
62 // Stuff we do, when the notification is opened
63 });
64
65 return [
66 $group,
67 ];
68 }
69}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static getNewCounter(int $a_user_id)
Get new counter.
static getLatestTimestamp(int $a_user_id)
Get latest badge.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
$factory
Definition: metadata.php:58
$lng