function flatten_category_tree in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/lib/questionlib.php \flatten_category_tree()
Private method, only for the use of add_indented_names().
Recursively adds an indentedname field to each category, starting with the category with id $id, and dealing with that category and all its children, and return a new array, with those categories in the right order.
Parameters
array $categories an array of categories which has had childids: fields added by flatten_category_tree(). Passed by reference for performance only. It is not modfied.
int $id the category to start the indenting process from.:
int $depth the indent depth. Used in recursive calls.:
Return value
array a new array of categories, in the right order for the tree.
1 call to flatten_category_tree()
- add_indented_names in includes/
moodle/ lib/ questionlib.php - Format categories into an indented list reflecting the tree structure.
File
- includes/
moodle/ lib/ questionlib.php, line 1805
Code
function flatten_category_tree(&$categories, $id, $depth = 0, $nochildrenof = -1) {
// Indent the name of this category.
$newcategories = array();
$newcategories[$id] = $categories[$id];
$newcategories[$id]->indentedname = str_repeat(' ', $depth) . $categories[$id]->name;
// Recursively indent the children.
foreach ($categories[$id]->childids as $childid) {
if ($childid != $nochildrenof) {
$newcategories = $newcategories + flatten_category_tree($categories, $childid, $depth + 1, $nochildrenof);
}
}
// Remove the childids array that were temporarily added.
unset($newcategories[$id]->childids);
return $newcategories;
}