/** * Private method used to retrieve all children of this category recursively * * @param grade_category $category Source of current recursion * @return array An array of child grade categories */ private static function _get_children_recursion($category) { $children_array = array(); foreach ($category->children as $sortorder => $child) { if (array_key_exists('itemtype', $child)) { $grade_item = new grade_item($child, false); if (in_array($grade_item->itemtype, array('course', 'category'))) { $type = $grade_item->itemtype . 'item'; $depth = $category->depth; } else { $type = 'item'; $depth = $category->depth; // we use this to set the same colour } $children_array[$sortorder] = array('object' => $grade_item, 'type' => $type, 'depth' => $depth); } else { $children = grade_category::_get_children_recursion($child); $grade_category = new grade_category($child, false); if (empty($children)) { $children = array(); } $children_array[$sortorder] = array('object' => $grade_category, 'type' => 'category', 'depth' => $grade_category->depth, 'children' => $children); } } // sort the array ksort($children_array); return $children_array; }