Skip to content

Commit 9c984be

Browse files
timedin-demickenordin
authored andcommitted
fix: show conditional answers in detail view
fix: export of subquestions Signed-off-by: TimedIn <git@timedin.net>
1 parent d9a7149 commit 9c984be

4 files changed

Lines changed: 70 additions & 14 deletions

File tree

lib/Db/QuestionMapper.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,21 @@ public function __construct(
2828
* @throws DoesNotExistException if not found
2929
* @return Question[]
3030
*/
31-
public function findByForm(int $formId, bool $loadDeleted = false): array {
31+
public function findByForm(int $formId, bool $loadDeleted = false, bool $loadSubquestions = false): array {
3232
$qb = $this->db->getQueryBuilder();
3333

3434
$qb->select('*')
3535
->from($this->getTableName())
3636
->where(
3737
$qb->expr()->eq('form_id', $qb->createNamedParameter($formId, IQueryBuilder::PARAM_INT))
38-
)
38+
);
39+
40+
if (!$loadSubquestions) {
3941
// Only load top-level questions (not subquestions of conditional questions)
40-
->andWhere(
42+
$qb->andWhere(
4143
$qb->expr()->isNull('parent_question_id')
4244
);
45+
}
4346

4447
if (!$loadDeleted) {
4548
// Don't load questions, that are marked as deleted (marked by order==0).

lib/Service/SubmissionService.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function getSubmissionsData(Form $form, string $fileFormat, ?File $file =
228228
// Oldest first
229229
$submissionEntities = array_reverse($submissionEntities);
230230

231-
$questions = $this->questionMapper->findByForm($form->getId());
231+
$questions = $this->questionMapper->findByForm($form->getId(), false, true);
232232
$defaultTimeZone = $this->config->getSystemValueString('default_timezone', 'UTC');
233233

234234
if (!$this->currentUser) {
@@ -848,7 +848,6 @@ private function evaluateBranchConditions(string $triggerType, array $triggerAns
848848
}
849849
}
850850
return false;
851-
852851
case Constants::ANSWER_TYPE_MULTIPLE:
853852
// Multi-select: all condition option IDs must be selected
854853
foreach ($conditions as $condition) {
@@ -864,7 +863,6 @@ private function evaluateBranchConditions(string $triggerType, array $triggerAns
864863
return true;
865864
}
866865
return false;
867-
868866
case Constants::ANSWER_TYPE_SHORT:
869867
case Constants::ANSWER_TYPE_LONG:
870868
// Text-based: evaluate regex/string conditions
@@ -892,7 +890,6 @@ private function evaluateBranchConditions(string $triggerType, array $triggerAns
892890
}
893891
}
894892
return false;
895-
896893
case Constants::ANSWER_TYPE_LINEARSCALE:
897894
$numValue = (float)($triggerAnswer[0] ?? 0);
898895
foreach ($conditions as $condition) {
@@ -910,7 +907,6 @@ private function evaluateBranchConditions(string $triggerType, array $triggerAns
910907
}
911908
}
912909
return false;
913-
914910
case Constants::ANSWER_TYPE_COLOR:
915911
$colorValue = $triggerAnswer[0] ?? '';
916912
foreach ($conditions as $condition) {
@@ -919,7 +915,6 @@ private function evaluateBranchConditions(string $triggerType, array $triggerAns
919915
}
920916
}
921917
return false;
922-
923918
case Constants::ANSWER_TYPE_FILE:
924919
$hasFile = !empty($triggerAnswer);
925920
foreach ($conditions as $condition) {
@@ -928,7 +923,6 @@ private function evaluateBranchConditions(string $triggerType, array $triggerAns
928923
}
929924
}
930925
return false;
931-
932926
case Constants::ANSWER_TYPE_DATE:
933927
case Constants::ANSWER_TYPE_DATETIME:
934928
case Constants::ANSWER_TYPE_TIME:
@@ -959,7 +953,6 @@ private function evaluateBranchConditions(string $triggerType, array $triggerAns
959953
}
960954
}
961955
return false;
962-
963956
default:
964957
return false;
965958
}

src/components/Results/Answer.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@
7474
<p v-else class="answer__text" dir="auto">
7575
<NcHighlight :text="answerText" :search="highlight" />
7676
</p>
77+
<template v-if="question.conditional && question.answers">
78+
<div
79+
v-for="(branchAnswers, branchAnswersKey) in question.answers"
80+
:key="branchAnswersKey"
81+
class="branch__subquestions">
82+
<div class="answer__subquestion">
83+
<Answer
84+
v-for="subquestion in branchAnswers"
85+
:key="subquestion.id"
86+
:question="subquestion"
87+
:highlight="highlight"
88+
:answerText="subquestion.squashedAnswers"
89+
:answers="subquestion.answer"
90+
:questionText="subquestion.text"
91+
:gridCellType="subquestion.gridCellType"
92+
:gridColumns="subquestion.gridColumns"
93+
:gridRows="subquestion.gridRows"
94+
:gridValue="subquestion.gridValue"
95+
:questionType="subquestion.type" />
96+
</div>
97+
</div>
98+
</template>
7799
</div>
78100
</template>
79101

@@ -93,6 +115,11 @@ export default {
93115
},
94116
95117
props: {
118+
question: {
119+
type: Object,
120+
required: true,
121+
},
122+
96123
answers: {
97124
type: Array,
98125
required: false,
@@ -215,5 +242,11 @@ export default {
215242
left: 0;
216243
}
217244
}
245+
246+
&__subquestion {
247+
margin-top: 16px;
248+
padding-left: 16px;
249+
border-left: 3px solid var(--color-primary-element);
250+
}
218251
}
219252
</style>

src/components/Results/Submission.vue

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<Answer
3737
v-for="question in answeredQuestions"
3838
:key="question.id"
39+
:question="question"
3940
:highlight="highlight"
4041
:answerText="question.squashedAnswers"
4142
:answers="question.answers"
@@ -126,9 +127,15 @@ export default {
126127
* @return {Array}
127128
*/
128129
answeredQuestions() {
130+
return this.parseQuestions(this.questions)
131+
},
132+
},
133+
134+
methods: {
135+
parseQuestions(questions) {
129136
const answeredQuestionsArray = []
130137
131-
this.questions.forEach((question) => {
138+
questions.forEach((question) => {
132139
const answers = this.submission.answers.filter(
133140
(answer) => answer.questionId === question.id,
134141
)
@@ -220,6 +227,28 @@ export default {
220227
(option) => option.optionType === OptionType.Column,
221228
),
222229
})
230+
} else if (question.type === 'conditional') {
231+
const branches = question.extraSettings?.branches ?? []
232+
if (branches.length === 0) return
233+
const subQuestions = branches.map((branch) =>
234+
branch.subQuestions
235+
.map((sub) => ({
236+
...sub,
237+
answer: this.submission.answers.find(
238+
(answer) => answer.questionId === sub.id,
239+
),
240+
}))
241+
.filter((sub) => sub.answer),
242+
)
243+
answeredQuestionsArray.push({
244+
id: question.id,
245+
text: question.text,
246+
type: question.extraSettings.triggerType,
247+
conditional: true,
248+
extraSettings: question.extraSettings,
249+
squashedAnswers: answers[0].text,
250+
answers: subQuestions.map((sub) => this.parseQuestions(sub)),
251+
})
223252
} else if (['date', 'time'].includes(question.type)) {
224253
const squashedAnswers = answers
225254
.map((answer) => answer.text)
@@ -269,9 +298,7 @@ export default {
269298
})
270299
return answeredQuestionsArray
271300
},
272-
},
273301
274-
methods: {
275302
onDelete() {
276303
this.$emit('delete')
277304
},

0 commit comments

Comments
 (0)