ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ADNProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 use Closure;
31 
36 {
37  protected \ILIAS\Refinery\String\MarkdownFormattingToHTML $markdown;
38  protected \ILIAS\GlobalScreen\Helper\BasicAccessCheckClosures $access;
39 
40  public function __construct(Container $dic)
41  {
42  parent::__construct($dic);
43  $this->access = BasicAccessCheckClosuresSingleton::getInstance();
44  $this->markdown = $dic->refinery()->string()->markdown();
45  }
46 
47  protected function getSummary(ilADNNotification|\ActiveRecord $item): string
48  {
49  return $this->markdown->toHTML()->transform(
50  $item->getBody()
51  );
52  }
53 
57  public function getNotifications(): array
58  {
59  return [];
60  }
61 
65  public function getAdministrativeNotifications(): array
66  {
67  $adns = [];
68 
69  $i = fn (string $id): IdentificationInterface => $this->if->identifier($id);
74  foreach (ilADNNotification::get() as $item) {
75  $adn = $this->notification_factory->administrative($i((string) $item->getId()))->withTitle($item->getTitle())->withSummary(
76  $this->getSummary($item)
77  );
78  $adn = $this->handleDenotation($item, $adn);
79 
80  $is_visible = static fn (): bool => true;
81 
82  // is limited to roles
83  if ($item->isLimitToRoles()) {
84  $is_visible = $this->combineClosure($is_visible, fn () => $this->dic->rbac()->review()->isAssignedToAtLeastOneGivenRole(
85  $this->dic->user()->getId(),
86  $item->getLimitedToRoleIds()
87  ));
88  }
89 
90  // is dismissale
91  if ($item->getDismissable() && $this->access->isUserLoggedIn()()) {
92  $adn = $adn->withClosedCallable(function () use ($item): void {
93  $item->dismiss($this->dic->user());
94  });
95  $is_visible = $this->combineClosure($is_visible, fn (): bool => !\ilADNDismiss::hasDimissed($this->dic->user(), $item));
96  }
97 
98  $is_visible = $this->combineClosure($is_visible, fn (): bool => $item->isVisibleForUser($this->dic->user()));
99 
100  $adns[] = $adn->withVisibilityCallable($is_visible);
101  }
102  return $adns;
103  }
104 
105  private function handleDenotation(
106  ilADNNotification $item,
109  $settype = static function (int $type, AdministrativeNotification $adn): AdministrativeNotification {
110  switch ($type) {
112  return $adn->withBreakingDenotation();
114  return $adn->withImportantDenotation();
116  default:
117  return $adn->withNeutralDenotation();
118  }
119  };
120 
121  // denotation during event
122  if (!$item->isPermanent() && $item->isDuringEvent()) {
123  return $settype($item->getTypeDuringEvent(), $adn);
124  }
125  return $settype($item->getType(), $adn);
126  }
127 
128  private function combineClosure(Closure $closure, ?Closure $additional = null): Closure
129  {
130  if ($additional instanceof Closure) {
131  return static fn (): bool => $additional() && $closure();
132  }
133 
134  return $closure;
135  }
136 }
getSummary(ilADNNotification|\ActiveRecord $item)
Definition: ADNProvider.php:47
static hasDimissed(ilObjUser $ilObjUser, ilADNNotification $ilADNNotification)
ILIAS GlobalScreen Helper BasicAccessCheckClosures $access
Definition: ADNProvider.php:38
ILIAS Refinery String MarkdownFormattingToHTML $markdown
Definition: ADNProvider.php:37
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)
$dic
Definition: ltiresult.php:33
combineClosure(Closure $closure, ?Closure $additional=null)
handleDenotation(ilADNNotification $item, AdministrativeNotification $adn)