showing quesiton-keys instead of ids
This commit is contained in:
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user