Skip to content

Commit

Permalink
Merge branch 'MDL-61519-master' of https://github.com/MartinGauk/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 21, 2018
2 parents bb0ca2c + ef780a0 commit c06c1a4
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions lib/coursecatlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,20 +1178,15 @@ public function get_children($options = array()) {
* @return int[]
*/
public function get_all_children_ids() {
$coursecattreecache = cache::make('core', 'coursecattree');
$children = $coursecattreecache->get($this->id . 'allchildren');
if ($children === false) {
$children = [];
$walk = [$this->id];
while (count($walk) > 0) {
$catid = array_pop($walk);
$directchildren = self::get_tree($catid);
if ($directchildren !== false && count($directchildren) > 0) {
$walk = array_merge($walk, $directchildren);
$children = array_merge($children, $directchildren);
}
$children = [];
$walk = [$this->id];
while (count($walk) > 0) {
$catid = array_pop($walk);
$directchildren = self::get_tree($catid);
if ($directchildren !== false && count($directchildren) > 0) {
$walk = array_merge($walk, $directchildren);
$children = array_merge($children, $directchildren);
}
$coursecattreecache->set($this->id . 'allchildren', $children);
}

return $children;
Expand Down

0 comments on commit c06c1a4

Please sign in to comment.