From: vyshane Date: Thu, 8 Feb 2007 08:06:08 +0000 (+0000) Subject: Merged from 1.7. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=2327b9df74b3020589825e1a53ebb030e0f1ebcd;p=moodle.git Merged from 1.7. --- diff --git a/lib/datalib.php b/lib/datalib.php index bd39d65d9e..28c6c030c6 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -888,6 +888,26 @@ function get_categories($parent='none', $sort='sortorder ASC') { } +/** + * Returns an array of category ids of all the subcategories for a given + * category. + * @param $catid - The id of the category whose subcategories we want to find. + * @return array of category ids. + */ +function get_all_subcategories($catid) { + + $subcats = array(); + + if ($categories = get_records('course_categories', 'parent', $catid)) { + foreach ($categories as $cat) { + array_push($subcats, $cat->id); + $subcats = array_merge($subcats, get_all_subcategories($cat->id)); + } + } + return $subcats; +} + + /** * This recursive function makes sure that the courseorder is consecutive *