ILIAS  release_7 Revision v7.30-3-g800a261c036
ADNProvider.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
13use Closure;
15
20{
24 protected $access;
25
26 public function __construct(Container $dic)
27 {
30 }
31
35 public function getNotifications() : array
36 {
37 return [];
38 }
39
43 public function getAdministrativeNotifications() : array
44 {
45 $adns = [];
46
47 $i = function (string $id) : IdentificationInterface {
48 return $this->if->identifier($id);
49 };
54 foreach (ilADNNotification::get() as $item) {
55 $adn = $this->notification_factory->administrative($i((string) $item->getId()))->withTitle($item->getTitle())->withSummary($item->getBody());
56 $adn = $this->handleDenotation($item, $adn);
57
58 $is_visible = static function () : bool {
59 return true;
60 };
61
62 // is limited to roles
63 if ($item->isLimitToRoles()) {
64 $is_visible = $this->combineClosure($is_visible, function () use ($item) {
65 return $this->dic->rbac()->review()->isAssignedToAtLeastOneGivenRole($this->dic->user()->getId(),
66 $item->getLimitedToRoleIds());
67 });
68 }
69
70 // is dismissale
71 if ($item->getDismissable() && $this->access->isUserLoggedIn()()) {
72 $adn = $adn->withClosedCallable(function () use ($item) {
73 $item->dismiss($this->dic->user());
74 });
75 $is_visible = $this->combineClosure($is_visible, function () use ($item) : bool {
76 return !\ilADNDismiss::hasDimissed($this->dic->user(), $item);
77 });
78 }
79
80 $is_visible = $this->combineClosure($is_visible, function () use ($item) : bool {
81 return $item->isVisibleForUser($this->dic->user());
82 });
83
84 $adns[] = $adn->withVisibilityCallable($is_visible);
85 }
86 return $adns;
87 }
88
89 private function handleDenotation(
93 $settype = static function (int $type, AdministrativeNotification $adn) : AdministrativeNotification {
94 switch ($type) {
96 return $adn->withBreakingDenotation();
98 return $adn->withImportantDenotation();
100 default:
101 return $adn->withNeutralDenotation();
102 }
103 };
104
105 // denotation during event
106 if (!$item->isPermanent() && $item->isDuringEvent()) {
107 return $settype($item->getTypeDuringEvent(), $adn);
108 }
109 return $settype($item->getType(), $adn);
110 }
111
112 private function combineClosure(Closure $closure, ?Closure $additional = null) : Closure
113 {
114 if ($additional instanceof Closure) {
115 return static function () use ($closure, $additional) : bool {
116 return $additional() && $closure();
117 };
118 }
119
120 return $closure;
121 }
122
123}
An exception for terminatinating execution or to throw for unit testing.
handleDenotation(ilADNNotification $item, AdministrativeNotification $adn)
Definition: ADNProvider.php:89
combineClosure(Closure $closure, ?Closure $additional=null)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:19
static hasDimissed(ilObjUser $ilObjUser, ilADNNotification $ilADNNotification)
$additional
Definition: goto.php:52
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type