From 2327b9df74b3020589825e1a53ebb030e0f1ebcd Mon Sep 17 00:00:00 2001 From: vyshane Date: Thu, 8 Feb 2007 08:06:08 +0000 Subject: [PATCH] Merged from 1.7. --- lib/datalib.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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 * -- 2.39.5