improved questionnaire editor glass scales
Some checks failed
PHPUnit / test (push) Has been cancelled

This commit is contained in:
2026-06-06 16:28:10 +02:00
parent d68b2b267d
commit e5ae48c02e
7 changed files with 388 additions and 30 deletions

View File

@ -1145,6 +1145,85 @@ function qdb_parse_config_json($configJson): array {
return $config;
}
/**
* @return list<array{key: string, labelDe: string}>
*/
function qdb_parse_glass_symptoms_body(array $body, array $config): array {
if (isset($body['glassSymptoms']) && is_array($body['glassSymptoms'])) {
$rows = [];
foreach ($body['glassSymptoms'] as $row) {
if (!is_array($row)) {
continue;
}
$key = trim((string)($row['key'] ?? ''));
if ($key === '') {
continue;
}
$key = qdb_validate_stable_key($key, 'Symptom key');
$rows[] = [
'key' => $key,
'labelDe' => trim((string)($row['labelDe'] ?? '')),
];
}
return $rows;
}
$out = [];
foreach ($config['symptoms'] ?? [] as $symptomKey) {
$key = trim((string)$symptomKey);
if ($key !== '') {
$out[] = ['key' => $key, 'labelDe' => ''];
}
}
return $out;
}
/** Apply ordered symptom keys from editor rows into question config. */
function qdb_apply_glass_symptoms_config(array $config, array $glassSymptoms): array {
$keys = [];
foreach ($glassSymptoms as $row) {
$keys[] = $row['key'];
}
if ($keys) {
$config['symptoms'] = $keys;
} else {
unset($config['symptoms']);
}
return $config;
}
/** Upsert German labels for glass-scale symptom string keys. */
function qdb_sync_glass_symptom_strings(PDO $pdo, array $glassSymptoms): void {
foreach ($glassSymptoms as $row) {
$key = $row['key'] ?? '';
$label = trim((string)($row['labelDe'] ?? ''));
if ($key === '' || $label === '') {
continue;
}
qdb_put_translation($pdo, 'string', $key, QDB_SOURCE_LANGUAGE, $label);
}
}
/**
* Symptom keys with German labels for editor / API consumers.
*
* @return list<array{key: string, labelDe: string}>
*/
function qdb_glass_symptoms_with_labels(PDO $pdo, array $config): array {
$rows = [];
foreach ($config['symptoms'] ?? [] as $symptomKey) {
$key = trim((string)$symptomKey);
if ($key === '') {
continue;
}
$label = qdb_string_german_label($pdo, $key);
if ($label === $key) {
$label = '';
}
$rows[] = ['key' => $key, 'labelDe' => $label];
}
return $rows;
}
/** Sync note German text into string_translation rows for the app. */
function qdb_sync_question_note_strings(PDO $pdo, string $questionKey, array $config): void {
if ($questionKey === '') {
@ -1360,6 +1439,8 @@ function qdb_translation_entry_lists(PDO $pdo, string $qnID): array {
$stringKeys = [];
$stringEntries = [];
$contentEntries = [];
$addedSymptomKeys = [];
$appKeySet = qdb_app_string_key_set();
foreach ($dbQuestions as $dbQ) {
$qOrder = (int)($dbQ['orderIndex'] ?? 0);
@ -1406,9 +1487,24 @@ function qdb_translation_entry_lists(PDO $pdo, string $qnID): array {
$stringKeys[$config[$field]] = true;
}
}
if (!empty($config['symptoms']) && is_array($config['symptoms'])) {
if (($dbQ['type'] ?? '') === 'glass_scale_question'
&& !empty($config['symptoms']) && is_array($config['symptoms'])) {
$symIdx = 0;
foreach ($config['symptoms'] as $s) {
$stringKeys[$s] = true;
$sk = trim((string)$s);
if ($sk === '' || isset($appKeySet[$sk]) || isset($addedSymptomKeys[$sk])) {
continue;
}
$addedSymptomKeys[$sk] = true;
$parentLabel = $qKey !== '' ? $qKey : $qLocal;
$stringEntries[] = [
'key' => $sk,
'displayKey' => $qLocal . ' · ' . $parentLabel . ' · ' . $sk,
'type' => 'string',
'entityId' => $sk,
'sortOrder' => $qOrder * 1000 + 5 + $symIdx,
];
$symIdx++;
}
}
if ($qKey !== '') {
@ -1421,7 +1517,6 @@ function qdb_translation_entry_lists(PDO $pdo, string $qnID): array {
}
}
$appKeySet = qdb_app_string_key_set();
$stringOrder = 0;
$skList = array_keys($stringKeys);
sort($skList, SORT_STRING);