71 lines
2.4 KiB
PHP
71 lines
2.4 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
require_once dirname(dirname(__DIR__)) . '/bootstrap.php';
|
||
|
|
|
||
|
|
function task_cert_admin_task_list_action(): array
|
||
|
|
{
|
||
|
|
$auth = TaskCertAuthContext::fromGlobals();
|
||
|
|
if (!$auth->hasPermission('r-task-cert-admin')) {
|
||
|
|
return [
|
||
|
|
'error' => 'Keine Berechtigung für die Aufgaben-Administration.',
|
||
|
|
'tasks' => [],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
$services = task_cert_services();
|
||
|
|
$searchQuery = TaskCertRequest::queryString('q', '');
|
||
|
|
$categoryIdFilter = TaskCertRequest::queryInt('category_id', 0);
|
||
|
|
if ($categoryIdFilter < 0) {
|
||
|
|
$categoryIdFilter = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
$tasks = $services['taskDefinitionService']->listTasksForAdmin($searchQuery, $categoryIdFilter);
|
||
|
|
$categoryFilter = null;
|
||
|
|
|
||
|
|
if ($categoryIdFilter > 0) {
|
||
|
|
$categoryService = $services['taskCategoryService'] ?? null;
|
||
|
|
if ($categoryService instanceof TaskCategoryService) {
|
||
|
|
$categoryFilter = $categoryService->getById($categoryIdFilter);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$myTasks = [];
|
||
|
|
$contactId = $auth->contactId();
|
||
|
|
if ($contactId > 0) {
|
||
|
|
$myTasks = $services['taskDefinitionService']->listTasksForResponsible($contactId);
|
||
|
|
}
|
||
|
|
|
||
|
|
$lookupRepo = $services['lookupRepo'] ?? null;
|
||
|
|
|
||
|
|
$selectedContactId = TaskCertRequest::queryInt('contact_id', 0);
|
||
|
|
$contactAssignments = [];
|
||
|
|
$selectedContactName = '';
|
||
|
|
if ($selectedContactId > 0 && $lookupRepo instanceof TaskLookupRepository) {
|
||
|
|
$contact = $lookupRepo->getContactById($selectedContactId);
|
||
|
|
if (is_array($contact)) {
|
||
|
|
$selectedContactName = trim((string) ($contact['name'] ?? ''));
|
||
|
|
if ($selectedContactName === '') {
|
||
|
|
$selectedContactName = trim((string) ($contact['email'] ?? 'Kontakt #' . $selectedContactId));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ($selectedContactName === '') {
|
||
|
|
$selectedContactName = 'Kontakt #' . $selectedContactId;
|
||
|
|
}
|
||
|
|
$contactAssignments = $services['assignmentRepo']->listByContactId($selectedContactId);
|
||
|
|
}
|
||
|
|
|
||
|
|
return [
|
||
|
|
'error' => null,
|
||
|
|
'tasks' => $tasks,
|
||
|
|
'my_tasks' => $myTasks,
|
||
|
|
'search_query' => $searchQuery,
|
||
|
|
'category_id_filter' => $categoryIdFilter,
|
||
|
|
'category_filter' => $categoryFilter,
|
||
|
|
'selected_contact_id' => $selectedContactId,
|
||
|
|
'selected_contact_name' => $selectedContactName,
|
||
|
|
'contact_assignments' => $contactAssignments,
|
||
|
|
'csrf_token' => TaskCertCsrf::token(),
|
||
|
|
];
|
||
|
|
}
|