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

@ -54,10 +54,16 @@ if (!$questionnaire) {
}
// Questions ordered
$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) ?: [];
$questionColumnLabels[$q['questionID']] = qdb_question_column_label($cfg, $q['defaultText'], $q['questionID'], $qnID);
}
unset($q);
// Build answer-option lookup for resolving display text
$optionTextMap = [];
@ -118,7 +124,7 @@ foreach ($clients as $c) {
foreach ($questions as $q) {
$qid = $q['questionID'];
$a = $answerMap[$qid] ?? null;
$row[$q['defaultText']] = qdb_format_client_answer_display($q, $a, $optionTextMap);
$row[$questionColumnLabels[$qid]] = qdb_format_client_answer_display($q, $a, $optionTextMap);
}
$rows[] = $row;
}
@ -143,7 +149,9 @@ if (!empty($rows)) {
}
} else {
$header = ['clientCode', 'coach', 'supervisor', '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);