ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ADNProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
30 use Closure;
32 
37 {
38  protected MarkdownFormattingToHTML $markdown;
39  protected BasicAccessCheckClosures $access;
40 
41  public function __construct(Container $dic)
42  {
43  parent::__construct($dic);
44  $this->access = BasicAccessCheckClosuresSingleton::getInstance();
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) {
112  ilADNNotification::TYPE_ERROR => $adn->withBreakingDenotation(),
113  ilADNNotification::TYPE_WARNING => $adn->withImportantDenotation(),
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 }
getSummary(ilADNNotification|\ActiveRecord $item)
Definition: ADNProvider.php:48
BasicAccessCheckClosures $access
Definition: ADNProvider.php:39
static hasDimissed(ilObjUser $ilObjUser, ilADNNotification $ilADNNotification)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
$dic
Definition: result.php:31
combineClosure(Closure $closure, ?Closure $additional=null)
handleDenotation(ilADNNotification $item, AdministrativeNotification $adn)
MarkdownFormattingToHTML $markdown
Definition: ADNProvider.php:38