forked from fa/breadcrumb-the-shire
Pass AppContainer to SessionProvider::clear() so all module providers use SessionStoreInterface consistently instead of raw $_SESSION. Also add loading and error states to the notification bell dropdown (GR-UI-014). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45 lines
1.4 KiB
PHP
45 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Module\Notifications\Providers;
|
|
|
|
use MintyPHP\App\AppContainer;
|
|
use MintyPHP\App\Module\Contracts\SessionProvider;
|
|
use MintyPHP\Http\SessionStoreInterface;
|
|
use MintyPHP\Module\Notifications\Service\NotificationService;
|
|
|
|
final class NotificationsSessionProvider implements SessionProvider
|
|
{
|
|
private const SESSION_KEY = 'module.notifications.unread_count';
|
|
|
|
public function populate(array $user, AppContainer $container): void
|
|
{
|
|
$sessionStore = $container->get(SessionStoreInterface::class);
|
|
if (!$sessionStore instanceof SessionStoreInterface) {
|
|
return;
|
|
}
|
|
|
|
$userId = (int) ($user['id'] ?? 0);
|
|
if ($userId <= 0) {
|
|
$sessionStore->remove(self::SESSION_KEY);
|
|
return;
|
|
}
|
|
|
|
$service = $container->get(NotificationService::class);
|
|
if (!$service instanceof NotificationService) {
|
|
return;
|
|
}
|
|
|
|
$currentTenant = $sessionStore->get('current_tenant', []);
|
|
$tenantId = is_array($currentTenant) ? (int) ($currentTenant['id'] ?? 0) : 0;
|
|
$sessionStore->set(self::SESSION_KEY, $service->unreadCount($userId, $tenantId > 0 ? $tenantId : null));
|
|
}
|
|
|
|
public function clear(AppContainer $container): void
|
|
{
|
|
$sessionStore = $container->get(SessionStoreInterface::class);
|
|
if ($sessionStore instanceof SessionStoreInterface) {
|
|
$sessionStore->remove(self::SESSION_KEY);
|
|
}
|
|
}
|
|
}
|