Files

52 lines
2.1 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
class TaskLookupService
{
private TaskLookupRepository $lookupRepo;
public function __construct(TaskLookupRepository $lookupRepo)
{
$this->lookupRepo = $lookupRepo;
}
public function getAdminFormLookups(int $languageId): array
{
$languageId = $languageId > 0 ? $languageId : 1;
return [
'task_categories' => $this->safeFetch('task_categories', fn(): array => $this->lookupRepo->listTaskCategories(true)),
'mandants' => $this->safeFetch('mandants', fn(): array => $this->lookupRepo->listMandants()),
'departments' => $this->safeFetch('departments', fn(): array => $this->lookupRepo->listDepartments()),
'roles' => $this->safeFetch('roles', fn(): array => $this->lookupRepo->listRoles()),
'einrichts' => $this->safeFetch('einrichts', fn(): array => $this->lookupRepo->listEinrichts()),
'fachbereiche' => $this->safeFetch('fachbereiche', fn(): array => $this->lookupRepo->listFachbereiche()),
'contacts' => $this->safeFetch('contacts', fn(): array => $this->lookupRepo->listActiveContacts()),
'knowledge_posts' => $this->safeFetch('knowledge_posts', fn(): array => $this->lookupRepo->listKnowledgePosts($languageId)),
];
}
public function getKnowledgePostTitleMapByIds(int $languageId, array $postIds): array
{
$languageId = $languageId > 0 ? $languageId : 1;
try {
return $this->lookupRepo->mapKnowledgePostTitlesByIds($languageId, $postIds);
} catch (Throwable $throwable) {
error_log('task_cert lookup fetch failed (knowledge_post_title_map): ' . $throwable->getMessage());
return [];
}
}
private function safeFetch(string $lookupName, callable $fetcher): array
{
try {
$rows = $fetcher();
return is_array($rows) ? $rows : [];
} catch (Throwable $throwable) {
error_log('task_cert lookup fetch failed (' . $lookupName . '): ' . $throwable->getMessage());
return [];
}
}
}