Files
breadcrumb-the-shire/modules/addressbook/pages/address-book/index().php

88 lines
3.4 KiB
PHP
Raw Normal View History

2026-02-04 23:31:53 +01:00
<?php
use MintyPHP\Buffer;
use MintyPHP\Http\SessionStoreInterface;
use MintyPHP\Module\AddressBook\Service\AddressBookService;
2026-02-23 12:58:19 +01:00
use MintyPHP\Session;
use MintyPHP\Support\Guard;
2026-02-04 23:31:53 +01:00
$session = app(SessionStoreInterface::class)->all();
2026-02-04 23:31:53 +01:00
Guard::requireLogin();
Guard::requireAbilityOrForbidden(\MintyPHP\Module\AddressBook\AddressBookAuthorizationPolicy::ABILITY_VIEW);
2026-02-04 23:31:53 +01:00
2026-03-04 15:56:58 +01:00
$filterSchema = require __DIR__ . '/filter-schema.php';
$query = requestInput()->queryAll();
$currentUserId = (int) ($session['user']['id'] ?? 0);
$addressBookService = app(AddressBookService::class);
2026-03-04 15:56:58 +01:00
$context = $addressBookService->buildIndexContext($currentUserId, $query);
2026-02-23 12:58:19 +01:00
$activeTenants = $context['activeTenants'] ?? [];
$activeRoles = $context['activeRoles'] ?? [];
$activeDepartments = $context['activeDepartments'] ?? [];
$tenantItems = $context['tenantItems'] ?? [];
$departments = $context['departments'] ?? [];
$roles = $context['roles'] ?? [];
$customFieldFilterDefinitions = $context['customFieldFilterDefinitions'] ?? [];
$customFieldFilterQuery = $context['customFieldFilterQuery'] ?? [];
$tenantDepartmentMap = $context['tenantDepartmentMap'] ?? [];
2026-03-04 15:56:58 +01:00
$toolbarOptionSets = [
'tenant_items' => (array) $tenantItems,
'department_items' => (array) $departments,
'role_items' => (array) $roles,
];
$toolbarFilterStateOverrides = [
'search' => (string) gridQueryString($query, 'search', ''),
'tenants' => array_map('strval', (array) $activeTenants),
'departments' => array_map('strval', (array) $activeDepartments),
'roles' => array_map('strval', (array) $activeRoles),
];
$listFilterContext = gridBuildListFilterContext($filterSchema, [
'query' => $query,
'search_keys' => ['search'],
'toolbar_state_overrides' => $toolbarFilterStateOverrides,
'toolbar_option_sets' => $toolbarOptionSets,
]);
$toolbarFilterSchema = $listFilterContext['toolbarFilterSchema'];
$toolbarFilterState = $listFilterContext['toolbarFilterState'];
$searchToolbarFilterSchema = $listFilterContext['searchToolbarFilterSchema'];
$drawerToolbarFilterSchema = $listFilterContext['drawerToolbarFilterSchema'];
$toolbarOptionSets = $listFilterContext['toolbarOptionSets'];
$clientFilterSchema = $listFilterContext['clientFilterSchema'];
$searchConfig = $listFilterContext['searchConfig'];
$customFieldChipMeta = $addressBookService->buildCustomFieldChipMeta($customFieldFilterDefinitions);
2026-03-04 15:56:58 +01:00
$filterChipMeta = [
'search' => [
'label' => t('Search'),
'type' => 'text',
],
'tenants' => [
'label' => t('Tenants'),
'type' => 'multi_csv',
'options' => gridOptionMapFromItems((array) $tenantItems),
],
'departments' => [
'label' => t('Departments'),
'type' => 'multi_csv',
'options' => gridOptionMapFromItems((array) $departments),
],
'roles' => [
'label' => t('Roles'),
'type' => 'multi_csv',
'options' => gridOptionMapFromItems((array) $roles),
],
'custom_fields' => $customFieldChipMeta,
];
2026-02-04 23:31:53 +01:00
$csrfKey = Session::$csrfSessionKey;
$csrfToken = $session[$csrfKey] ?? '';
2026-02-04 23:31:53 +01:00
Buffer::set('title', t('Address book'));
$breadcrumbs = [
['label' => t('Home'), 'path' => 'admin'],
['label' => t('Address book')],
];
2026-02-04 23:31:53 +01:00
Buffer::set('grid_lang', json_encode(gridLang(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
Buffer::set(
'grid_csrf',
json_encode(['key' => $csrfKey, 'token' => $csrfToken], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
);