ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ADNProvider.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
29 use Closure;
31 
36 {
37  protected \ILIAS\GlobalScreen\Helper\BasicAccessCheckClosures $access;
38 
39  public function __construct(Container $dic)
40  {
41  parent::__construct($dic);
43  }
44 
48  public function getNotifications(): array
49  {
50  return [];
51  }
52 
56  public function getAdministrativeNotifications(): array
57  {
58  $adns = [];
59 
60  $i = fn (string $id): IdentificationInterface => $this->if->identifier($id);
65  foreach (ilADNNotification::get() as $item) {
66  $adn = $this->notification_factory->administrative($i((string) $item->getId()))->withTitle($item->getTitle())->withSummary($item->getBody());
67  $adn = $this->handleDenotation($item, $adn);
68 
69  $is_visible = static fn (): bool => true;
70 
71  // is limited to roles
72  if ($item->isLimitToRoles()) {
73  $is_visible = $this->combineClosure($is_visible, fn () => $this->dic->rbac()->review()->isAssignedToAtLeastOneGivenRole(
74  $this->dic->user()->getId(),
75  $item->getLimitedToRoleIds()
76  ));
77  }
78 
79  // is dismissale
80  if ($item->getDismissable() && $this->access->isUserLoggedIn()()) {
81  $adn = $adn->withClosedCallable(function () use ($item): void {
82  $item->dismiss($this->dic->user());
83  });
84  $is_visible = $this->combineClosure($is_visible, fn (): bool => !\ilADNDismiss::hasDimissed($this->dic->user(), $item));
85  }
86 
87  $is_visible = $this->combineClosure($is_visible, fn (): bool => $item->isVisibleForUser($this->dic->user()));
88 
89  $adns[] = $adn->withVisibilityCallable($is_visible);
90  }
91  return $adns;
92  }
93 
94  private function handleDenotation(
95  ilADNNotification $item,
98  $settype = static function (int $type, AdministrativeNotification $adn): AdministrativeNotification {
99  switch ($type) {
101  return $adn->withBreakingDenotation();
103  return $adn->withImportantDenotation();
105  default:
106  return $adn->withNeutralDenotation();
107  }
108  };
109 
110  // denotation during event
111  if (!$item->isPermanent() && $item->isDuringEvent()) {
112  return $settype($item->getTypeDuringEvent(), $adn);
113  }
114  return $settype($item->getType(), $adn);
115  }
116 
117  private function combineClosure(Closure $closure, ?Closure $additional = null): Closure
118  {
119  if ($additional instanceof Closure) {
120  return static fn (): bool => $additional() && $closure();
121  }
122 
123  return $closure;
124  }
125 }
static hasDimissed(ilObjUser $ilObjUser, ilADNNotification $ilADNNotification)
$type
ILIAS GlobalScreen Helper BasicAccessCheckClosures $access
Definition: ADNProvider.php:37
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ADNProvider.php:21
$additional
Definition: goto.php:53
handleDenotation(ilADNNotification $item, AdministrativeNotification $adn)
Definition: ADNProvider.php:94
combineClosure(Closure $closure, ?Closure $additional=null)
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$i
Definition: metadata.php:41