Skip to content

Commit d73a33f

Browse files
author
toanlamt
committed
Questionnaire: All branching shown in View your response (fixing code review)
1 parent bf0576a commit d73a33f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

questionnaire.class.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4196,8 +4196,11 @@ public static function get_user_identity_fields($context, $userid) {
41964196
/**
41974197
* Determines if a question is dependent on another question's choice.
41984198
*
4199-
* Checks if the provided question has dependencies on other questions
4200-
* and if any required answer choices have not been selected.
4199+
* Check whether the given question depends on other question,
4200+
* and see if any answers have been provided for this question.
4201+
*
4202+
* If there is no answer to that question we assume that it was not answered
4203+
* because it depends on another choice and therefore is not displayed in the report.
42014204
*
42024205
* @param object $question The question object containing dependencies
42034206
* @param array $answers An associative array of answers with question IDs as keys
@@ -4206,10 +4209,8 @@ public static function get_user_identity_fields($context, $userid) {
42064209
*/
42074210
public static function is_dependent_on_choices(object $question, array $answers): bool {
42084211
if (!empty($question->dependencies)) {
4209-
foreach ($question->dependencies as $dependency) {
4210-
if (empty($answers[$dependency->dependquestionid][$dependency->dependchoiceid])) {
4211-
return true;
4212-
}
4212+
if (empty($answers[$question->id])) {
4213+
return true;
42134214
}
42144215
}
42154216
return false;

0 commit comments

Comments
 (0)