Files
awo-hamburg-intranet/module/tasks/endpoints/admin/mark_completed_methods.php
Moritz Weinmann 743476f64a 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>
2026-06-22 09:20:02 +02:00

103 lines
3.5 KiB
PHP

<?php
declare(strict_types=1);
require_once dirname(dirname(__DIR__)) . '/bootstrap.php';
$auth = TaskCertAuthContext::fromGlobals();
if (!$auth->hasPermission('r-task-cert-admin')) {
TaskCertResponse::json(['error' => 'Keine Berechtigung'], 403);
}
$assignmentId = (int) ($_GET['assignment_id'] ?? 0);
if ($assignmentId <= 0) {
TaskCertResponse::json(['error' => 'Ungültige assignment_id'], 400);
}
$services = task_cert_services();
$assignment = $services['assignmentRepo']->findById($assignmentId);
if ($assignment === null) {
TaskCertResponse::json(['error' => 'Zuweisung nicht gefunden'], 404);
}
$taskId = (int) ($assignment['task_id'] ?? 0);
$task = $services['definitionRepo']->findById($taskId);
if ($task === null) {
TaskCertResponse::json(['error' => 'Aufgabe nicht gefunden'], 404);
}
$contactId = (int) ($assignment['main_contact_id'] ?? 0);
$contact = null;
if ($contactId > 0) {
$contact = TaskCertDb::fetchOne(
'SELECT id, name, email FROM main_contact WHERE id = ?',
'i',
[$contactId]
);
}
$methods = array_values(array_filter(
$services['ruleRepo']->getMethodsByTask($taskId),
static fn(array $m): bool => (int) ($m['active'] ?? 1) === 1
));
$existingSubmissions = $services['submissionRepo']->listByAssignment($assignmentId);
$fulfilledMethodIds = [];
foreach ($existingSubmissions as $sub) {
$subStatus = (string) ($sub['status'] ?? '');
if (in_array($subStatus, ['auto_passed', 'approved'], true)) {
$fulfilledMethodIds[(int) ($sub['method_id'] ?? 0)] = true;
}
}
$methodsOut = [];
foreach ($methods as $method) {
$methodId = (int) ($method['id'] ?? 0);
$methodType = (string) ($method['method_type'] ?? '');
$formFields = [];
if ($methodType === 'form_submit') {
foreach ((array) ($method['form_fields'] ?? []) as $field) {
$options = [];
$rawOptions = is_array($field['options'] ?? null) ? $field['options'] : [];
foreach ($rawOptions as $opt) {
$options[] = [
'value' => (string) ($opt['value'] ?? ''),
'label' => (string) ($opt['label'] ?? $opt['value'] ?? ''),
];
}
$formFields[] = [
'field_key' => (string) ($field['field_key'] ?? ''),
'label' => (string) ($field['label'] ?? ''),
'field_type' => (string) ($field['field_type'] ?? 'text'),
'is_required' => (int) ($field['is_required'] ?? 0),
'options' => $options,
'placeholder' => (string) ($field['placeholder'] ?? ''),
];
}
}
$methodsOut[] = [
'id' => $methodId,
'method_type' => $methodType,
'is_required' => (int) ($method['is_required'] ?? 1),
'already_fulfilled' => isset($fulfilledMethodIds[$methodId]),
'knowledge_post_count' => count((array) ($method['knowledge_posts'] ?? [])),
'quiz_question_count' => count((array) ($method['quiz_questions'] ?? [])),
'form_fields' => $formFields,
];
}
TaskCertResponse::json([
'task_id' => $taskId,
'task_title' => (string) ($task['title'] ?? ''),
'assignment_id' => $assignmentId,
'contact_name' => (string) ($contact['name'] ?? '-'),
'contact_email' => (string) ($contact['email'] ?? ''),
'cycle_key' => (string) ($assignment['cycle_key'] ?? ''),
'status' => (string) ($assignment['status'] ?? ''),
'due_at' => (string) ($assignment['due_at'] ?? ''),
'methods' => $methodsOut,
'csrf_token' => TaskCertCsrf::token(),
]);