UX improvements in data views

This commit is contained in:
2026-05-27 09:58:08 +02:00
parent 25851c4b86
commit ff370d0d39
5 changed files with 185 additions and 91 deletions

View File

@ -38,13 +38,7 @@ $qStmt = $pdo->prepare("SELECT questionID, defaultText, type, orderIndex, config
$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);
$resultColumns = qdb_results_export_columns($questions, $qnID);
$optionTextMap = [];
foreach ($questionIDs as $qid) {
@ -99,10 +93,10 @@ foreach ($clients as $c) {
$answerMap = [];
foreach ($answers as $a) $answerMap[$a['questionID']] = $a;
foreach ($questions as $q) {
$qid = $q['questionID'];
foreach ($resultColumns as $col) {
$qid = $col['questionID'];
$a = $answerMap[$qid] ?? null;
$row[$q['defaultText']] = qdb_format_client_answer_display($q, $a, $optionTextMap);
$row[$col['header']] = qdb_results_column_cell_value($col, $a, $optionTextMap);
}
$rows[] = $row;
}
@ -126,8 +120,8 @@ if (!empty($rows)) {
}
} else {
$header = ['clientCode', 'coachID', 'status', 'sumPoints', 'startedAt', 'completedAt'];
foreach ($questions as $q) {
$header[] = $questionColumnLabels[$q['questionID']] ?? $q['defaultText'];
foreach ($resultColumns as $col) {
$header[] = $col['header'];
}
fputcsv($out, $header);
}