diff --git a/classes/local/helpers/webservicehelper.php b/classes/local/helpers/webservicehelper.php index 96f114a..145728c 100644 --- a/classes/local/helpers/webservicehelper.php +++ b/classes/local/helpers/webservicehelper.php @@ -1,6 +1,8 @@ dirroot.'/webservice/lib.php'); + class webservicehelper { /** @var \context_system */ @@ -53,19 +55,23 @@ class webservicehelper { } $children = $parent->get_children(); + // Since the change for a category permission is greatest at the lower levels, + // we scan in two stages, to focus the search more on the lower levels instead of diving deep into the first category + // Stage one (surface check): check all children for the capability foreach($children as $child){ // Check if we should add this category if(has_capability($capability,$child->get_context())){ return true; - } else { - if($child->get_children_count() > 0){ - if(self::has_capability_in_any_category($capability,$child)){ - return true; - } + } + } + // Stage two (deep dive): recurse into the child categories + foreach($children as $child){ + if($child->get_children_count() > 0){ + if(self::has_capability_in_any_category($capability,$child)){ + return true; } } } - return false; }