Module tasks + knowledgecenter_update aus Kundenprojekt übernehmen (bereinigt)
Beide Module wurden aus einem anderen Kundenprojekt kopiert und bereinigt: Knowledgecenter: - Bild-Cache (1.985 Dateien) geleert, Ordnerstruktur mit .gitkeep behalten - Files-Gallery-Lizenzschlüssel entfernt (config.php) - Kundenspezifische Kategorien gelöscht: Teil I/II/III QM-Struktur, nummerierte QM-Kapitel, Gremien (Präsidium/Finanzausschuss/Landesausschuss), Sitzungsservice-Serie, Protokoll-Abteilungen, Testeinträge - 56 generische Kategorien bleiben (Downloads, Onboarding, Personalthemen …) Tasks: - Alle Betriebsdaten gelöscht (114 Tasks, 914 Submissions, 579 Assignments) - Task-Definitionen und Verlinkungen geleert - Kategoriestruktur bleibt (Allgemein, IT, Personal, Buchhaltung …) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
125
module/tasks/actions/user/task_detail_action.php
Normal file
125
module/tasks/actions/user/task_detail_action.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once dirname(dirname(__DIR__)) . '/bootstrap.php';
|
||||
|
||||
function task_cert_user_task_detail_action(): array
|
||||
{
|
||||
$auth = TaskCertAuthContext::fromGlobals();
|
||||
if (!$auth->isLoggedIn()) {
|
||||
return [
|
||||
'error' => 'Nicht eingeloggt.',
|
||||
];
|
||||
}
|
||||
|
||||
$assignmentId = TaskCertRequest::queryInt('assignment_id', 0);
|
||||
if ($assignmentId <= 0) {
|
||||
return [
|
||||
'error' => 'Ungültige Assignment-ID.',
|
||||
];
|
||||
}
|
||||
|
||||
$services = task_cert_services();
|
||||
$assignment = $services['assignmentRepo']->findById($assignmentId);
|
||||
|
||||
if ($assignment === null) {
|
||||
return [
|
||||
'error' => 'Assignment nicht gefunden.',
|
||||
];
|
||||
}
|
||||
|
||||
if ((int) $assignment['main_contact_id'] !== $auth->contactId()) {
|
||||
return [
|
||||
'error' => 'Keine Berechtigung für dieses Assignment.',
|
||||
];
|
||||
}
|
||||
|
||||
$task = $services['definitionRepo']->findById((int) $assignment['task_id']);
|
||||
if ($task === null) {
|
||||
return [
|
||||
'error' => 'Aufgabe nicht gefunden.',
|
||||
];
|
||||
}
|
||||
|
||||
$methods = $services['ruleRepo']->getMethodsByTask((int) $assignment['task_id']);
|
||||
$methods = array_values(array_filter($methods, static function (array $method): bool {
|
||||
return (int) ($method['active'] ?? 1) === 1;
|
||||
}));
|
||||
$submissions = $services['submissionRepo']->listByAssignment($assignmentId);
|
||||
|
||||
$postIds = [];
|
||||
foreach ($methods as $method) {
|
||||
if ((string) ($method['method_type'] ?? '') !== 'knowledge_read') {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ((array) ($method['knowledge_posts'] ?? []) as $post) {
|
||||
$postId = (int) ($post['knowledge_post_id'] ?? 0);
|
||||
if ($postId > 0) {
|
||||
$postIds[] = $postId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$knowledgePostTitleMap = [];
|
||||
$lookupService = $services['lookupService'] ?? null;
|
||||
if ($lookupService instanceof TaskLookupService) {
|
||||
$languageId = (int) ($GLOBALS['language']['id'] ?? 1);
|
||||
$knowledgePostTitleMap = $lookupService->getKnowledgePostTitleMapByIds($languageId, $postIds);
|
||||
}
|
||||
|
||||
foreach ($methods as &$method) {
|
||||
if ((string) ($method['method_type'] ?? '') !== 'knowledge_read') {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ((array) ($method['knowledge_posts'] ?? []) as &$post) {
|
||||
$postId = (int) ($post['knowledge_post_id'] ?? 0);
|
||||
$post['title'] = $knowledgePostTitleMap[$postId] ?? ('Beitrag #' . $postId);
|
||||
}
|
||||
unset($post);
|
||||
}
|
||||
unset($method);
|
||||
|
||||
$responsibles = $services['ruleRepo']->getResponsiblesWithContactData((int) $assignment['task_id']);
|
||||
|
||||
$neededPrefillColumns = [];
|
||||
foreach ($methods as $m) {
|
||||
foreach ((array) ($m['form_fields'] ?? []) as $ff) {
|
||||
$col = trim((string) ($ff['prefill_column'] ?? ''));
|
||||
if ($col !== '' && ContactPrefillColumns::isValid($col)) {
|
||||
$neededPrefillColumns[$col] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$contactData = [];
|
||||
if ($neededPrefillColumns !== []) {
|
||||
try {
|
||||
$contactRow = TaskCertDb::fetchOne(
|
||||
'SELECT * FROM main_contact WHERE id = ? LIMIT 1',
|
||||
'i',
|
||||
[$auth->contactId()]
|
||||
);
|
||||
if (is_array($contactRow)) {
|
||||
$contactData = $contactRow;
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$contactData = [];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'error' => null,
|
||||
'assignment' => $assignment,
|
||||
'task' => $task,
|
||||
'methods' => $methods,
|
||||
'submissions' => $submissions,
|
||||
'task_certificates_history' => $services['certificateService']->listUserTaskCertificates(
|
||||
$auth->contactId(),
|
||||
(int) $assignment['task_id']
|
||||
),
|
||||
'responsibles' => $responsibles,
|
||||
'contact_data' => $contactData,
|
||||
'csrf_token' => TaskCertCsrf::token(),
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user