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

@ -88,6 +88,14 @@ 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 = [];
@ -152,11 +160,6 @@ 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) {
@ -354,7 +357,7 @@ if ($fetchClients) {
'clientCode' => $code,
'completedQuestionnaires' => $completions[$code] ?? [],
];
}, $clientCodes);
}, array_values(array_filter($clientCodes, fn($code) => strcasecmp($code, 'DEVELOPER-SETTINGS') !== 0)));
qdb_discard($tmpDb, $lockFp);
json_success(['coachID' => $coachID, 'clients' => $clients]);