Skip to content

Commit c8f61c7

Browse files
committed
IBX-9060: Added sidebar notifications
1 parent 3e82692 commit c8f61c7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/bundle/Controller/NotificationController.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ public function renderNotificationsPageAction(Request $request, int $page): Resp
111111
$pagerfanta = new Pagerfanta(
112112
new NotificationAdapter($this->notificationService, $query)
113113
);
114-
$pagerfanta->setMaxPerPage($this->configResolver->getParameter('pagination.notification_limit'));
114+
115+
$limit = $this->configResolver->getParameter('pagination.notification_limit');
116+
$pagerfanta->setMaxPerPage($limit);
115117
$pagerfanta->setCurrentPage(min($page, $pagerfanta->getNbPages()));
116118

117119
$notifications = $this->renderNotifications($pagerfanta);
@@ -122,6 +124,7 @@ public function renderNotificationsPageAction(Request $request, int $page): Resp
122124

123125
return $this->render($template, [
124126
'notifications' => $notifications,
127+
'sidebarNotifications' => $this->renderNotificationList($this->notificationService->loadNotifications(0, $limit)->items),
125128
'notifications_count_interval' => $this->configResolver->getParameter('notification_count.interval'),
126129
'pager' => $pagerfanta,
127130
'search_form' => $searchForm->createView(),
@@ -153,6 +156,23 @@ private function getNotificationQuery(Request $request, FormInterface $searchFor
153156
return new NotificationQuery();
154157
}
155158

159+
/**
160+
* @param iterable<\Ibexa\Contracts\Core\Repository\Values\Notification\Notification> $notifications
161+
*
162+
* @return string[]
163+
*/
164+
private function renderNotificationList(iterable $notifications): array
165+
{
166+
$result = [];
167+
foreach ($notifications as $notification) {
168+
if ($this->registry->hasRenderer($notification->type)) {
169+
$result[] = $this->registry->getRenderer($notification->type)->render($notification);
170+
}
171+
}
172+
173+
return $result;
174+
}
175+
156176
/**
157177
* @param \Pagerfanta\Pagerfanta<\Ibexa\Contracts\Core\Repository\Values\Notification\Notification> $pagerfanta
158178
*

0 commit comments

Comments
 (0)