Right now, these methods are only to return a simple set of all parents or all children from the current node. This is simply a shortcut to getting a collection of all these document id’s, so you can, for instance, build a quick IN() clause for the FlexSearchForm snippet by implode()’ing the results. Also, having the full alias path as the index of the resulting array might come in handy for menu snippets. And between the documentListing, aliasListing, and documentMap metadata now available in the DocumentParser class, we should be able to author whatever additional API methods we need to make menu snippets more efficient. And if you’ve got ideas on how to structure the data better so it can be more effectively utilized, please feel free to share.
Some future enhancements to the methods, or additional methods might include
- a limit on the number of levels to get results from
- optional multi-dimensional array results, representing the tree structure
- optional sorting parameters to resort the resulting list by whatever criteria you want
Here is a quick snippet to view this and some of the related data offered up by the current system in a fairly readable format:
$output= "";
$output.= "<p>DocumentMap:<br />";
foreach ($modx->documentMap as $key=>$value) {
$output.= "$key [ ";
foreach ($value as $k=>$v) {
$output.= "$k=>$v";
}
$output.= " ]<br />";
}
$output.= "</p>";
$output.= "<p>Parents:<br />";
foreach ($modx->getParentIds($modx->documentIdentifier) as $docAlias=>$docId) {
$output.= " $docAlias=>$docId<br />";
}
$output.= "</p>";
$output.= "<p>Children:<br />";
foreach ($modx->getChildIds($modx->documentIdentifier) as $docAlias=>$docId) {
$output.= " $docAlias=>$docId<br />";
}
$output.= "</p>";
$output.= "<p>DocumentListing:<br />";
foreach ($modx->documentListing as $docAlias=>$docId) {
$output.= " $docAlias=>$docId<br />";
}
$output.= "</p>";
$output.= "<p>AliasListing:<br />";
foreach ($modx->aliasListing as $docAlias=>$docId) {
$output.= "$docAlias [ <br />";
foreach ($docId as $key=>$value) {
$output.= " $key=>$value, <br />";
}
$output.= " ]<br />";
}
$output.= "</p>";
return $output;