]> git.mjollnir.org Git - moodle.git/commitdiff
Merged from 1.7.
authorvyshane <vyshane>
Thu, 8 Feb 2007 08:06:08 +0000 (08:06 +0000)
committervyshane <vyshane>
Thu, 8 Feb 2007 08:06:08 +0000 (08:06 +0000)
lib/datalib.php

index bd39d65d9e2f9dc64cfe24dd34d9fb37dae8939a..28c6c030c6cff91a34cba64524605929e757399e 100644 (file)
@@ -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
 *