Skip to content

Commit 55b387d

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

File tree

1 file changed

+2
-23
lines changed

1 file changed

+2
-23
lines changed

questionnaire.class.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ public function view_response($rid, $referer= '', $resps = '', $compare = false,
423423
}
424424
$pdf = ($outputtarget == 'pdf') ? true : false;
425425
foreach ($this->questions as $question) {
426-
if (self::is_dependent_on_choices($question, $this->responses[$rid]->answers)) {
426+
// Only show eligible questions in the response.
427+
if (!$question->dependency_fulfilled($rid, $this->questions)) {
427428
continue;
428429
}
429430
if ($question->type_id < QUESPAGEBREAK) {
@@ -4192,26 +4193,4 @@ public static function get_user_identity_fields($context, $userid) {
41924193
$row = $DB->get_record_sql($sql, array_merge($params, [$userid]));
41934194
return $row;
41944195
}
4195-
4196-
/**
4197-
* Determines if a question is dependent on another question's choice.
4198-
*
4199-
* Checks if the provided question has dependencies on other questions
4200-
* and if any required answer choices have not been selected.
4201-
*
4202-
* @param object $question The question object containing dependencies
4203-
* @param array $answers An associative array of answers with question IDs as keys
4204-
*
4205-
* @return bool True if the question has an unmet dependency; otherwise, false
4206-
*/
4207-
public static function is_dependent_on_choices(object $question, array $answers): bool {
4208-
if (!empty($question->dependencies)) {
4209-
foreach ($question->dependencies as $dependency) {
4210-
if (empty($answers[$dependency->dependquestionid][$dependency->dependchoiceid])) {
4211-
return true;
4212-
}
4213-
}
4214-
}
4215-
return false;
4216-
}
42174196
}

0 commit comments

Comments
 (0)