MDL-66009 mod_feedback: Nested dependency fails again
authorAndreas Grabs <moodle@grabs-edv.de>
Tue, 25 Jun 2019 20:04:14 +0000 (22:04 +0200)
committerAndreas Grabs <moodle@grabs-edv.de>
Thu, 17 Oct 2019 07:19:55 +0000 (09:19 +0200)
mod/feedback/classes/completion.php
mod/feedback/lib.php

index 7c27de8..f492e3c 100644 (file)
@@ -178,7 +178,11 @@ class mod_feedback_completion extends mod_feedback_structure {
             }
             return null;
         }
-        return $itemobj->compare_value($ditem, $value, $item->dependvalue) ? true : false;
+        $check = $itemobj->compare_value($ditem, $value, $item->dependvalue) ? true : false;
+        if ($check) {
+            return $this->can_see_item($ditem);
+        }
+        return false;
     }
 
     /**
index 89ea0ef..a318641 100644 (file)
@@ -1926,10 +1926,23 @@ function feedback_save_tmp_values($feedbackcompletedtmp, $feedbackcompleted) {
         //check if there are depend items
         $item = $DB->get_record('feedback_item', array('id'=>$value->item));
         if ($item->dependitem > 0 && isset($allitems[$item->dependitem])) {
-            $check = feedback_compare_item_value($tmpcplid,
-                                        $allitems[$item->dependitem],
-                                        $item->dependvalue,
-                                        true);
+            $ditem = $allitems[$item->dependitem];
+            while ($ditem !== null) {
+                $check = feedback_compare_item_value($tmpcplid,
+                                            $ditem,
+                                            $item->dependvalue,
+                                            true);
+                if (!$check) {
+                    break;
+                }
+                if ($ditem->dependitem > 0 && isset($allitems[$ditem->dependitem])) {
+                    $item = $ditem;
+                    $ditem = $allitems[$ditem->dependitem];
+                } else {
+                    $ditem = null;
+                }
+            }
+
         } else {
             $check = true;
         }