UX improvements in data views
This commit is contained in:
67
common.php
67
common.php
@ -532,6 +532,73 @@ function qdb_merge_glass_symptom_json(?string $existingJson, array $symptomLabel
|
||||
return json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/** Single symptom value from glass-scale JSON stored on the parent question row. */
|
||||
function qdb_glass_symptom_answer_value(?string $json, string $symptomKey): string
|
||||
{
|
||||
$symptomKey = trim($symptomKey);
|
||||
if ($symptomKey === '' || $json === null || trim($json) === '') {
|
||||
return '';
|
||||
}
|
||||
$decoded = json_decode($json, true);
|
||||
if (!is_array($decoded)) {
|
||||
return '';
|
||||
}
|
||||
return trim((string)($decoded[$symptomKey] ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flat columns for results / CSV: one column per glass-scale symptom.
|
||||
*
|
||||
* @return list<array{header: string, questionID: string, symptomKey: ?string, kind: string, question: array}>
|
||||
*/
|
||||
function qdb_results_export_columns(array $questions, string $qnID): array
|
||||
{
|
||||
$columns = [];
|
||||
foreach ($questions as $q) {
|
||||
$cfg = json_decode($q['configJson'] ?? '{}', true) ?: [];
|
||||
$type = $q['type'] ?? '';
|
||||
if ($type === 'glass_scale_question') {
|
||||
$symptoms = $cfg['symptoms'] ?? [];
|
||||
if (is_array($symptoms) && $symptoms !== []) {
|
||||
foreach ($symptoms as $symptomKey) {
|
||||
$sk = trim((string)$symptomKey);
|
||||
if ($sk === '') {
|
||||
continue;
|
||||
}
|
||||
$columns[] = [
|
||||
'header' => $sk,
|
||||
'questionID' => $q['questionID'],
|
||||
'symptomKey' => $sk,
|
||||
'kind' => 'glass_symptom',
|
||||
'question' => $q,
|
||||
];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$columns[] = [
|
||||
'header' => qdb_question_column_label($cfg, $q['defaultText'], $q['questionID'], $qnID),
|
||||
'questionID' => $q['questionID'],
|
||||
'symptomKey' => null,
|
||||
'kind' => 'question',
|
||||
'question' => $q,
|
||||
];
|
||||
}
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/** Cell value for one export/results column (including glass symptom columns). */
|
||||
function qdb_results_column_cell_value(array $column, ?array $answerRow, array $optionTextMap): string
|
||||
{
|
||||
if (($column['kind'] ?? '') === 'glass_symptom') {
|
||||
return qdb_glass_symptom_answer_value(
|
||||
$answerRow['freeTextValue'] ?? null,
|
||||
(string)($column['symptomKey'] ?? '')
|
||||
);
|
||||
}
|
||||
return qdb_format_client_answer_display($column['question'], $answerRow, $optionTextMap);
|
||||
}
|
||||
|
||||
/** Format one client_answer row for results table / CSV export. */
|
||||
function qdb_format_client_answer_display(array $question, ?array $answerRow, array $optionTextMap): string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user