ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ADNProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30use Closure;
32
37{
40
41 public function __construct(Container $dic)
42 {
45 $this->markdown = $dic->refinery()->string()->markdown();
46 }
47
48 protected function getSummary(ilADNNotification|\ActiveRecord $item): string
49 {
50 return $this->markdown->toHTML()->transform(
51 $item->getBody()
52 );
53 }
54
58 public function getNotifications(): array
59 {
60 return [];
61 }
62
66 #[\Override]
67 public function getAdministrativeNotifications(): array
68 {
69 $adns = [];
70
71 $i = fn(string $id): IdentificationInterface => $this->if->identifier($id);
76 foreach (ilADNNotification::get() as $item) {
77 $adn = $this->notification_factory->administrative($i((string) $item->getId()))->withTitle($item->getTitle())->withSummary(
78 $this->getSummary($item)
79 );
80 $adn = $this->handleDenotation($item, $adn);
81
82 $is_visible = static fn(): bool => true;
83
84 // is limited to roles
85 if ($item->isLimitToRoles()) {
86 $is_visible = $this->combineClosure($is_visible, fn(): bool => $this->dic->rbac()->review()->isAssignedToAtLeastOneGivenRole(
87 $this->dic->user()->getId(),
88 $item->getLimitedToRoleIds()
89 ));
90 }
91
92 // is dismissale
93 if ($item->getDismissable() && $this->access->isUserLoggedIn()()) {
94 $adn = $adn->withClosedCallable(function () use ($item): void {
95 $item->dismiss($this->dic->user());
96 });
97 $is_visible = $this->combineClosure($is_visible, fn(): bool => !\ilADNDismiss::hasDimissed($this->dic->user(), $item));
98 }
99
100 $is_visible = $this->combineClosure($is_visible, fn(): bool => $item->isVisibleForUser($this->dic->user()));
101
102 $adns[] = $adn->withVisibilityCallable($is_visible);
103 }
104 return $adns;
105 }
106
107 private function handleDenotation(
108 ilADNNotification $item,
111 $settype = (static fn(int $type, AdministrativeNotification $adn): AdministrativeNotification => match ($type) {
114 default => $adn->withNeutralDenotation(),
115 });
116
117 // denotation during event
118 if (!$item->isPermanent() && $item->isDuringEvent()) {
119 return $settype($item->getTypeDuringEvent(), $adn);
120 }
121 return $settype($item->getType(), $adn);
122 }
123
124 private function combineClosure(Closure $closure, ?Closure $additional = null): Closure
125 {
126 if ($additional instanceof Closure) {
127 return static fn(): bool => $additional() && $closure();
128 }
129
130 return $closure;
131 }
132}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
handleDenotation(ilADNNotification $item, AdministrativeNotification $adn)
combineClosure(Closure $closure, ?Closure $additional=null)
getSummary(ilADNNotification|\ActiveRecord $item)
Definition: ADNProvider.php:48
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
This class provides a transformation that converts Markdown formatting to HTML using the CommonMark L...
return true
static hasDimissed(ilObjUser $ilObjUser, ilADNNotification $ilADNNotification)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(!file_exists('../ilias.ini.php'))