This commit is contained in:
39
common.php
39
common.php
@ -1562,9 +1562,23 @@ function qdb_glass_symptoms_with_labels(PDO $pdo, array $config): array {
|
||||
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 {
|
||||
/** Sync note German text into string_translation rows for the app. Removes rows when notes are cleared. */
|
||||
function qdb_sync_question_note_strings(
|
||||
PDO $pdo,
|
||||
string $questionKey,
|
||||
array $config,
|
||||
?string $previousQuestionKey = null
|
||||
): void {
|
||||
$keysToDelete = [];
|
||||
if ($previousQuestionKey !== null) {
|
||||
$prev = trim($previousQuestionKey);
|
||||
if ($prev !== '' && $prev !== $questionKey) {
|
||||
$keysToDelete[] = qdb_note_before_key($prev);
|
||||
$keysToDelete[] = qdb_note_after_key($prev);
|
||||
}
|
||||
}
|
||||
if ($questionKey === '') {
|
||||
qdb_delete_string_translation_keys($pdo, $keysToDelete);
|
||||
return;
|
||||
}
|
||||
foreach ([
|
||||
@ -1574,8 +1588,29 @@ function qdb_sync_question_note_strings(PDO $pdo, string $questionKey, array $co
|
||||
$text = trim((string)($config[$field] ?? ''));
|
||||
if ($text !== '') {
|
||||
qdb_put_translation($pdo, 'string', $stringKey, QDB_SOURCE_LANGUAGE, $text);
|
||||
} else {
|
||||
$keysToDelete[] = $stringKey;
|
||||
}
|
||||
}
|
||||
qdb_delete_string_translation_keys($pdo, $keysToDelete);
|
||||
}
|
||||
|
||||
/** @param list<string> $stringKeys */
|
||||
function qdb_delete_string_translation_keys(PDO $pdo, array $stringKeys): void {
|
||||
$keys = [];
|
||||
foreach ($stringKeys as $key) {
|
||||
$key = trim((string)$key);
|
||||
if ($key !== '') {
|
||||
$keys[$key] = true;
|
||||
}
|
||||
}
|
||||
if ($keys === []) {
|
||||
return;
|
||||
}
|
||||
$list = array_keys($keys);
|
||||
$ph = implode(',', array_fill(0, count($list), '?'));
|
||||
$stmt = $pdo->prepare("DELETE FROM string_translation WHERE stringKey IN ($ph)");
|
||||
$stmt->execute($list);
|
||||
}
|
||||
|
||||
function qdb_assert_unique_question_key(PDO $pdo, string $qnID, string $questionKey, ?string $excludeQuestionID = null): void {
|
||||
|
||||
Reference in New Issue
Block a user