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>
52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Module\AddressBook\Providers;
|
|
|
|
use MintyPHP\App\AppContainer;
|
|
use MintyPHP\App\Module\Contracts\SessionProvider;
|
|
use MintyPHP\Http\SessionStoreInterface;
|
|
use MintyPHP\Service\User\UserTenantContextService;
|
|
|
|
/**
|
|
* Populates session with department-by-tenant hierarchy data used by the
|
|
* address book aside panel.
|
|
*/
|
|
final class AddressBookSessionProvider implements SessionProvider
|
|
{
|
|
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('module.addressbook.departments_by_tenant');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$tenantContext = $container->get(UserTenantContextService::class);
|
|
} catch (\Throwable) {
|
|
return;
|
|
}
|
|
if (!$tenantContext instanceof UserTenantContextService) {
|
|
return;
|
|
}
|
|
|
|
$sessionStore->set(
|
|
'module.addressbook.departments_by_tenant',
|
|
$tenantContext->getAvailableDepartmentsByTenant($userId)
|
|
);
|
|
}
|
|
|
|
public function clear(AppContainer $container): void
|
|
{
|
|
$sessionStore = $container->get(SessionStoreInterface::class);
|
|
if ($sessionStore instanceof SessionStoreInterface) {
|
|
$sessionStore->remove('module.addressbook.departments_by_tenant');
|
|
}
|
|
}
|
|
}
|