refactored export functionality

This commit is contained in:
2026-05-22 14:17:02 +02:00
parent 52d4ef42dc
commit 2616238dc8
6 changed files with 206 additions and 157 deletions

View File

@ -1,5 +1,7 @@
<?php
require_once __DIR__ . '/../lib/questionnaire_reachability.php';
$tokenRec = require_valid_token();
if ($method !== 'GET') {
@ -79,21 +81,19 @@ foreach ($clients as $c) {
$answerMap = [];
foreach ($answers as $a) $answerMap[$a['questionID']] = $a;
$reachable = qrb_reachable_question_ids($pdo, $qnID, $answerMap, $optionTextMap);
foreach ($questions as $q) {
$qid = $q['questionID'];
$header = $q['defaultText'];
if (!isset($reachable[$qid])) {
$row[$header] = '';
continue;
}
if (isset($answerMap[$qid])) {
$a = $answerMap[$qid];
if ($a['answerOptionID'] && isset($optionTextMap[$a['answerOptionID']])) {
$row[$q['defaultText']] = $optionTextMap[$a['answerOptionID']];
} elseif ($a['freeTextValue'] !== null && $a['freeTextValue'] !== '') {
$row[$q['defaultText']] = $a['freeTextValue'];
} elseif ($a['numericValue'] !== null) {
$row[$q['defaultText']] = $a['numericValue'];
} else {
$row[$q['defaultText']] = '';
}
$row[$header] = qrb_format_cell($answerMap[$qid], $optionTextMap);
} else {
$row[$q['defaultText']] = '';
$row[$header] = '';
}
}
$rows[] = $row;