Revert "refactored export functionality"

This reverts commit 2616238dc8.
This commit is contained in:
2026-05-22 14:23:39 +02:00
parent 2616238dc8
commit e0be2c501f
6 changed files with 157 additions and 206 deletions

View File

@ -88,14 +88,6 @@ if ($method === 'POST') {
$pdo->beginTransaction();
// Latest cache = full replace for this questionnaire (drop answers on unreachable branches)
$pdo->prepare("
DELETE FROM client_answer
WHERE clientCode = :cc AND questionID IN (
SELECT questionID FROM question WHERE questionnaireID = :qn
)
")->execute([':cc' => $clientCode, ':qn' => $qnID]);
$sumPoints = 0;
$parsedAnswers = [];
@ -160,6 +152,11 @@ if ($method === 'POST') {
$answerInsert = $pdo->prepare("
INSERT INTO client_answer (clientCode, questionID, answerOptionID, freeTextValue, numericValue, answeredAt)
VALUES (:cc, :qid, :aoid, :ftv, :nv, :at)
ON CONFLICT(clientCode, questionID) DO UPDATE SET
answerOptionID = excluded.answerOptionID,
freeTextValue = excluded.freeTextValue,
numericValue = excluded.numericValue,
answeredAt = excluded.answeredAt
");
foreach ($parsedAnswers as $pa) {
@ -357,7 +354,7 @@ if ($fetchClients) {
'clientCode' => $code,
'completedQuestionnaires' => $completions[$code] ?? [],
];
}, array_values(array_filter($clientCodes, fn($code) => strcasecmp($code, 'DEVELOPER-SETTINGS') !== 0)));
}, $clientCodes);
qdb_discard($tmpDb, $lockFp);
json_success(['coachID' => $coachID, 'clients' => $clients]);

View File

@ -1,7 +1,5 @@
<?php
require_once __DIR__ . '/../lib/questionnaire_reachability.php';
$tokenRec = require_valid_token();
if ($method !== 'GET') {
@ -81,19 +79,21 @@ 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])) {
$row[$header] = qrb_format_cell($answerMap[$qid], $optionTextMap);
$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']] = '';
}
} else {
$row[$header] = '';
$row[$q['defaultText']] = '';
}
}
$rows[] = $row;

View File

@ -1,7 +1,5 @@
<?php
require_once __DIR__ . '/../lib/questionnaire_reachability.php';
$tokenRec = require_valid_token();
if ($method !== 'GET') {
@ -33,15 +31,6 @@ $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'];
@ -106,14 +95,7 @@ if (!empty($questionIDs) && !empty($clients)) {
'answeredAt' => $a['answeredAt'] !== null ? (int)$a['answeredAt'] : null,
];
}
$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;
$c['answers'] = $answerMap;
}
unset($c);
} else {