API:getAllChildren

From MODx Wiki
Jump to: navigation, search
 API Function Definition: 
getAllChildren
Versions 
> ?
Return Values
Success:
Fail:
Data Type 
array
Object Hierarchy 
DocumentParser
array getAllChildren(mixed $id[, string $sort[, string $dir[, string $fields]]]);


$modx->getAllChildren($id= 0, $sort= 'menuindex', $dir= 'ASC', $fields= 'id, pagetitle, description, parent, alias, menutitle')

Gets all child documents of the specified document, including those which are unpublished or deleted.

To get only published document, see getActiveChildren.


Examples

Function Source

File: manager/includes/document.parser.inc.php
Line: 1312
  1. function getAllChildren($id= 0, $sort= 'menuindex', $dir= 'ASC', $fields= 'id, pagetitle, description, parent, alias, menutitle') {
  2. $tblsc= $this->getFullTableName("site_content");
  3. $tbldg= $this->getFullTableName("document_groups");
  4. // modify field names to use sc. table reference
  5. $fields= 'sc.' . implode(',sc.', preg_replace("/^\s/i", "", explode(',', $fields)));
  6. $sort= 'sc.' . implode(',sc.', preg_replace("/^\s/i", "", explode(',', $sort)));
  7. // get document groups for current user
  8. if ($docgrp= $this->getUserDocGroups())
  9. $docgrp= implode(",", $docgrp);
  10. // build query
  11. $access= ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") .
  12. (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
  13. $sql= "SELECT DISTINCT $fields FROM $tblsc sc
  14. LEFT JOIN $tbldg dg on dg.document = sc.id
  15. WHERE sc.parent = '$id'
  16. AND ($access)
  17. GROUP BY sc.id
  18. ORDER BY $sort $dir;";
  19. $result= $this->dbQuery($sql);
  20. $resourceArray= array ();
  21. for ($i= 0; $i < @ $this->recordCount($result); $i++) {
  22. array_push($resourceArray, @ $this->fetchRow($result));
  23. }
  24. return $resourceArray;
  25. }
Personal tools