MDL-63959 mod_feedback: Fixed nested dependency handling

For example the dependecy chain is the following: A->B->C. When a
question (A) depends on another dependent item (B) and B hasn't
displayed (because of C's response), the $value for the B's response
will be null. In this case the can_see_item() method returned
null. Because the can_see_item() returned null (not false), the
get_pages() method displayed the question A, because it checks for
explicit false: $this->can_see_item($item) !== false.
Now, false is also returned, if the dependent question is not visible.
This commit is contained in:
Zoltán Szarvas 2019-02-04 16:24:22 +01:00 committed by Tobias Reischmann
parent 14cdf51189
commit 5b8d533067
No known key found for this signature in database
GPG key ID: 14715C065F634E33

View file

@ -147,7 +147,10 @@ class mod_feedback_completion extends mod_feedback_structure {
* *
* @param stdClass $item * @param stdClass $item
* @return bool whether user can see item or not, * @return bool whether user can see item or not,
* null if dependency is broken or dependent question is not answered. * true if there is no dependency or dependency is met,
* false if dependent question is visible or broken
* and further it is either not answered or the dependency is not met,
* null if dependency is broken.
*/ */
protected function can_see_item($item) { protected function can_see_item($item) {
if (empty($item->dependitem)) { if (empty($item->dependitem)) {
@ -165,6 +168,10 @@ class mod_feedback_completion extends mod_feedback_structure {
$value = $this->get_values_tmp($ditem); $value = $this->get_values_tmp($ditem);
} }
if ($value === null) { if ($value === null) {
// Cyclic dependencies are no problem here, since they will throw an dependency error above.
if ($this->can_see_item($ditem) === false) {
return false;
}
return null; return null;
} }
return $itemobj->compare_value($ditem, $value, $item->dependvalue) ? true : false; return $itemobj->compare_value($ditem, $value, $item->dependvalue) ? true : false;