API:getChildIds

From MODx Wiki

Jump to: navigation, search
 API Function Definition: 
getChildIds
Versions 
> 0.9.2 ?
Return Values
Success: id(s) of document's children
Fail: empty array
Data Type 
Array
Object Hierarchy 
DocumentParser
Array getChildIds(mixed $id[, int $depth[, array $children]]);


  • $id - the parent page to start from
  • $depth - how many levels deep to search for children
  • $children - ?

Examples

Returns an array of child IDs belonging to the specified parent.

Related Functions

Function Source

  1. function getChildIds($id, $depth= 10, $children= array ()) {
  2. $c= null;
  3. foreach ($this->documentMap as $mapEntry) {
  4. if (isset ($mapEntry[$id])) {
  5. $childId= $mapEntry[$id];
  6. $childKey= array_search($childId, $this->documentListing);
  7. if (!$childKey) {
  8. $childKey= "$childId";
  9. }
  10. $c[$childKey]= $childId;
  11. }
  12. }
  13. $depth--;
  14. if (is_array($c)) {
  15. if (is_array($children)) {
  16. $children= $children + $c;
  17. } else {
  18. $children= $c;
  19. }
  20. if ($depth) {
  21. foreach ($c as $child) {
  22. $children= $children + $this->getChildIds($child, $depth, $children);
  23. }
  24. }
  25. }
  26. return $children;
  27. }

Notes

Personal tools