2026-02-04 23:31:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
use MintyPHP\DB;
|
|
|
|
|
use MintyPHP\I18n;
|
2026-02-04 23:31:53 +01:00
|
|
|
use MintyPHP\Router;
|
2026-02-23 12:58:19 +01:00
|
|
|
use MintyPHP\Service\Access\PermissionService;
|
|
|
|
|
use MintyPHP\Service\User\UserServicesFactory;
|
2026-02-04 23:31:53 +01:00
|
|
|
use MintyPHP\Support\Guard;
|
|
|
|
|
use MintyPHP\Support\SearchConfig;
|
|
|
|
|
|
|
|
|
|
Guard::requireLogin();
|
|
|
|
|
|
|
|
|
|
$userId = (int) ($_SESSION['user']['id'] ?? 0);
|
|
|
|
|
if ($userId > 0) {
|
2026-02-23 12:58:19 +01:00
|
|
|
permissionGateway()->getUserPermissions($userId);
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$query = trim((string) ($_GET['q'] ?? ''));
|
|
|
|
|
if ($query === '') {
|
|
|
|
|
Router::json([]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$previewLimit = 5;
|
|
|
|
|
$locale = I18n::$locale ?? (I18n::$defaultLocale ?? 'de');
|
2026-02-23 12:58:19 +01:00
|
|
|
$userTenantRepository = (new UserServicesFactory())->createUserTenantRepository();
|
|
|
|
|
$tenantIds = $userId > 0 ? $userTenantRepository->listTenantIdsByUserId($userId) : [];
|
2026-02-04 23:31:53 +01:00
|
|
|
$tenantScoped = !empty($tenantIds);
|
|
|
|
|
|
|
|
|
|
$tenantScopeFilters = SearchConfig::tenantScopeFilters();
|
|
|
|
|
$resources = SearchConfig::resources($query, $locale);
|
|
|
|
|
$results = [];
|
|
|
|
|
|
|
|
|
|
foreach ($resources as $resource) {
|
|
|
|
|
$key = (string) ($resource['key'] ?? '');
|
|
|
|
|
if ($key === '') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tenantFilter = $tenantScopeFilters[$key] ?? '';
|
|
|
|
|
$isTenantScoped = $tenantFilter !== '';
|
|
|
|
|
if ($isTenantScoped && !$tenantScoped) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$perm = (string) ($resource['permission'] ?? '');
|
2026-02-23 12:58:19 +01:00
|
|
|
if ($perm !== '' && !permissionGateway()->userHas($userId, $perm)) {
|
2026-02-04 23:31:53 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$countSql = str_replace('{{tenantFilter}}', $isTenantScoped ? $tenantFilter : '', $resource['countSql'] ?? '');
|
|
|
|
|
$countParams = $resource['countParams'] ?? [];
|
|
|
|
|
if ($isTenantScoped && strpos($countSql, '???') !== false) {
|
|
|
|
|
$countParams[] = $tenantIds;
|
|
|
|
|
}
|
|
|
|
|
$count = $countSql !== '' ? (int) DB::selectValue($countSql, ...$countParams) : 0;
|
|
|
|
|
|
|
|
|
|
$items = [];
|
|
|
|
|
$previewSql = $resource['previewSql'] ?? null;
|
|
|
|
|
if ($previewSql) {
|
|
|
|
|
$previewSql = str_replace('{{tenantFilter}}', $isTenantScoped ? $tenantFilter : '', $previewSql);
|
|
|
|
|
$previewParams = $resource['previewParams'] ?? [];
|
|
|
|
|
if ($isTenantScoped && strpos($previewSql, '???') !== false) {
|
|
|
|
|
$previewParams[] = $tenantIds;
|
|
|
|
|
}
|
|
|
|
|
$previewParams[] = $previewLimit;
|
|
|
|
|
$rows = DB::select($previewSql, ...$previewParams);
|
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
|
$data = $row;
|
|
|
|
|
if (is_array($row) && count($row) === 1) {
|
|
|
|
|
$data = reset($row);
|
|
|
|
|
}
|
|
|
|
|
$data = is_array($data) ? $data : [];
|
|
|
|
|
$mapped = SearchConfig::mapPreviewItem($key, $data, $query);
|
|
|
|
|
if ($mapped !== null) {
|
|
|
|
|
$items[] = $mapped;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = [
|
|
|
|
|
'key' => $key,
|
|
|
|
|
'label' => $resource['label'] ?? '',
|
|
|
|
|
'count' => $count,
|
|
|
|
|
'url' => SearchConfig::listUrl($key, $query),
|
|
|
|
|
'items' => $items,
|
|
|
|
|
];
|
|
|
|
|
if ($key === 'pages' && !empty($items[0]['url'])) {
|
|
|
|
|
$result['url'] = $items[0]['url'];
|
|
|
|
|
}
|
|
|
|
|
$results[] = $result;
|
|
|
|
|
}
|
|
|
|
|
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$hotkeyResource = SearchConfig::hotkeyPreviewResource($query);
|
|
|
|
|
if ($hotkeyResource !== null) {
|
|
|
|
|
$results[] = $hotkeyResource;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
if (permissionGateway()->userHas($userId, PermissionService::DOCS_VIEW)) {
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$docsResource = SearchConfig::docsPreviewResource($query);
|
|
|
|
|
if ($docsResource !== null) {
|
|
|
|
|
$results[] = $docsResource;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-04 23:31:53 +01:00
|
|
|
Router::json($results);
|