showing quesiton-keys instead of ids

This commit is contained in:
2026-05-26 17:13:32 +02:00
parent ea3a423186
commit 25851c4b86
6 changed files with 74 additions and 12 deletions

View File

@ -34,10 +34,17 @@ if (!$questionnaire) {
json_error('NOT_FOUND', 'Questionnaire not found', 404);
}
$qStmt = $pdo->prepare("SELECT questionID, defaultText, type, orderIndex FROM question WHERE questionnaireID = :id ORDER BY orderIndex");
$qStmt = $pdo->prepare("SELECT questionID, defaultText, type, orderIndex, configJson FROM question WHERE questionnaireID = :id ORDER BY orderIndex");
$qStmt->execute([':id' => $qnID]);
$questions = $qStmt->fetchAll(PDO::FETCH_ASSOC);
$questionIDs = array_column($questions, 'questionID');
$questionColumnLabels = [];
foreach ($questions as &$q) {
$cfg = json_decode($q['configJson'] ?? '{}', true) ?: [];
$label = qdb_question_column_label($cfg, $q['defaultText'], $q['questionID'], $qnID);
$questionColumnLabels[$q['questionID']] = $label;
}
unset($q);
$optionTextMap = [];
foreach ($questionIDs as $qid) {
@ -119,7 +126,9 @@ if (!empty($rows)) {
}
} else {
$header = ['clientCode', 'coachID', 'status', 'sumPoints', 'startedAt', 'completedAt'];
foreach ($questions as $q) $header[] = $q['defaultText'];
foreach ($questions as $q) {
$header[] = $questionColumnLabels[$q['questionID']] ?? $q['defaultText'];
}
fputcsv($out, $header);
}
fclose($out);