feat: build the questionnaire form from its definition
This commit is contained in:
1 parent
d06b647dac
commit
8070fda64d
4 files changed
+435
No files matched your search
@@ -41,6 +41,30 @@ readonly class Definition
|
||||
return $this->getQuestions()[$key] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The answers worth keeping once the questionnaire is submitted: those to questions that are
|
||||
* shown, and not empty. A draft keeps everything, so switching an answer back restores the
|
||||
* follow-up the respondent had already written.
|
||||
*
|
||||
* @param array<string, mixed> $answers keyed by question key
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function withoutHiddenAnswers(array $answers): array
|
||||
{
|
||||
$kept = [];
|
||||
|
||||
foreach ($this->getQuestions() as $key => $question) {
|
||||
$answer = $answers[$key] ?? null;
|
||||
|
||||
if (null !== $answer && '' !== $answer && [] !== $answer && $this->isVisible($question, $answers)) {
|
||||
$kept[$key] = $answer;
|
||||
}
|
||||
}
|
||||
|
||||
return $kept;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a question is shown for these answers: it has no show_if, or its condition is met
|
||||
* and the question it depends on is shown in turn. A hidden question's answer counts for
|
||||
|
||||
Reference in new issue
Block a user