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') {
@ -31,6 +33,15 @@ $qStmt->execute([':id' => $qnID]);
$questions = $qStmt->fetchAll(PDO::FETCH_ASSOC);
$questionIDs = array_column($questions, 'questionID');
$optionTextMap = [];
foreach ($questionIDs as $qid) {
$aoStmt = $pdo->prepare("SELECT answerOptionID, defaultText FROM answer_option WHERE questionID = :qid");
$aoStmt->execute([':qid' => $qid]);
foreach ($aoStmt->fetchAll(PDO::FETCH_ASSOC) as $ao) {
$optionTextMap[$ao['answerOptionID']] = $ao['defaultText'];
}
}
foreach ($questions as &$q) {
$q['isRequired'] = (int)$q['isRequired'];
$q['orderIndex'] = (int)$q['orderIndex'];
@ -95,7 +106,14 @@ if (!empty($questionIDs) && !empty($clients)) {
'answeredAt' => $a['answeredAt'] !== null ? (int)$a['answeredAt'] : null,
];
}
$c['answers'] = $answerMap;
$reachable = qrb_reachable_question_ids($pdo, $qnID, $answerMap, $optionTextMap);
$filtered = [];
foreach ($answerMap as $qid => $ans) {
if (isset($reachable[$qid])) {
$filtered[$qid] = $ans;
}
}
$c['answers'] = $filtered;
}
unset($c);
} else {