From 63a560e80390a6c9f088a9940b260d65bbf8eed9 Mon Sep 17 00:00:00 2001 From: Tom Hempel Date: Fri, 12 Jun 2026 13:07:49 +0200 Subject: [PATCH] added glass scale symptoms to translations --- common.php | 2 +- handlers/app_questionnaires.php | 3 +++ tests/Integration/AppQuestionnairesTest.php | 12 ++++++++++++ tests/Integration/TranslationsWriteTest.php | 21 +++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/common.php b/common.php index 6bea687..12dfaf6 100644 --- a/common.php +++ b/common.php @@ -1430,7 +1430,7 @@ function qdb_format_glass_answer_json_display(PDO $pdo, ?string $raw, array &$st */ function qdb_translation_entry_lists(PDO $pdo, string $qnID): array { $qStmt = $pdo->prepare(" - SELECT q.questionID, q.defaultText, q.configJson, q.orderIndex + SELECT q.questionID, q.defaultText, q.type, q.configJson, q.orderIndex FROM question q WHERE q.questionnaireID = :id ORDER BY q.orderIndex "); $qStmt->execute([':id' => $qnID]); diff --git a/handlers/app_questionnaires.php b/handlers/app_questionnaires.php index ad35ae3..b40f8f1 100644 --- a/handlers/app_questionnaires.php +++ b/handlers/app_questionnaires.php @@ -515,6 +515,9 @@ if ($qnID) { if (isset($config['hint1'])) $q['hint1'] = $config['hint1']; if (isset($config['hint2'])) $q['hint2'] = $config['hint2']; if (isset($config['symptoms'])) $q['symptoms'] = $config['symptoms']; + if ($layout === 'glass_scale_question' && !empty($config['symptoms'])) { + $q['glassSymptoms'] = qdb_glass_symptoms_with_labels($pdo, $config); + } if (isset($config['scaleType'])) $q['scaleType'] = $config['scaleType']; if (isset($config['range'])) $q['range'] = $config['range']; if (isset($config['step'])) $q['step'] = (int)$config['step']; diff --git a/tests/Integration/AppQuestionnairesTest.php b/tests/Integration/AppQuestionnairesTest.php index 316384e..664c9d3 100644 --- a/tests/Integration/AppQuestionnairesTest.php +++ b/tests/Integration/AppQuestionnairesTest.php @@ -27,6 +27,18 @@ final class AppQuestionnairesTest extends QdbTestCase ]); $this->assertApiOk($res); $this->assertNotEmpty($res['data']['questions']); + + $glass = null; + foreach ($res['data']['questions'] as $q) { + if (($q['layout'] ?? '') === 'glass_scale_question') { + $glass = $q; + break; + } + } + $this->assertNotNull($glass); + $this->assertIsArray($glass['glassSymptoms'] ?? null); + $symptomKeys = array_column($glass['glassSymptoms'], 'key'); + $this->assertContains($this->fixture()->glassSymptomKey, $symptomKeys); } public function testCoachListsAssignedClients(): void diff --git a/tests/Integration/TranslationsWriteTest.php b/tests/Integration/TranslationsWriteTest.php index 3d8e161..a9dc9bd 100644 --- a/tests/Integration/TranslationsWriteTest.php +++ b/tests/Integration/TranslationsWriteTest.php @@ -80,4 +80,25 @@ final class TranslationsWriteTest extends QdbTestCase } $this->assertSame('Oui', $fr); } + + public function testAllTranslationsIncludeGlassSymptomKeys(): void + { + $token = $this->api()->loginWebAndGetToken( + DatabaseSeeder::ADMIN_USERNAME, + DatabaseSeeder::PASSWORD + )['token']; + $f = $this->fixture(); + + $res = $this->api()->withToken($token, 'GET', 'translations', null, ['all' => '1']); + $this->assertApiOk($res); + + $stringKeys = []; + foreach ($res['data']['entries'] as $entry) { + if (($entry['type'] ?? '') === 'string') { + $stringKeys[] = $entry['key'] ?? ''; + } + } + $this->assertContains($f->glassSymptomKey, $stringKeys); + $this->assertContains('fatigue', $stringKeys); + } }