@bruno - the output will be a json encoded array & I can't 'rely' on any modx extras being installed.
@bob - luckily we are not formatting anything at all, just handing some json off to the mobile device - so I'm trying to balance how much data is passed [bandwidth] and how much massaging it needs on the modx end [save processing on the client end]
getCollection was way too slow & would have been a huge chunk of data to push. [there are about 3000 resources]
I would up going with something like this for now
function getResourceTree(){
$resourceTree = array();
$results = $this->modx->query(
"SELECT id,parent,published,menuindex,menutitle FROM modx_site_content where published = '1' and hidemenu = '0'"
);
while ($record = $results->fetch(PDO::FETCH_ASSOC)) {
$resourceTree[] = $record;
}
return $resourceTree ? $resourceTree : '';
}
Which of course does not organize the tree at all, and as you suggested I will have to whip through it & organize by id/parentid etc as I will have to check permissions on the individual resources *sigh*
I was just hoping there was another API tool that might give me more to work with than getTree
[Speaking of permissions ~before I start a new thread~ any idea on how to create & grant a user a session VIA the API?

]
Anyway, here is where I started with recursing through the getTree output. Oh, it's messy, and it doesn't really work right now, but you get the idea I was after:
// similar to what getTree outputs
$orgarray = array(
'101' => '101',
'102' => '102',
'103' => '103',
'104' => array(
'201' => '201',
'202' => '202',
'203' => array(
'301' => '301',
'302' => array(
'401' => '401',
'402' => '402',
'501' => array(
'502' => '502',
'503' => '503',
'504' => '504',
'505' => 'special',
'506' => '506'
),
),
),
),
'105' => '105',
'106' => '106',
'107' => '107');
//$orgarray = $modx->getTree(0,3);
function getpath($array, $needle, $stack = array()){
foreach($array as $key => $value) {
if(is_array($value)){
array_push($stack, $key);
return getpath($value, $needle, $stack);
}
if($value == $needle){
array_push($stack, $key);
return '['.implode('][', $stack).']';
}
}
return false;
}
function recursearray($array, &$newarray){
foreach($array as $key => $value){
echo getpath($orgarray, $value);
if (is_array($value)){
recursearray($value, &$newarray);
// add keys id, menutitle to array
}else{
$thiskey = getpath($orgarray, $value);
echo $thiskey;
// change the value [add array]
$thiskey = 'new-value';
}
}
return $array;
}
recursearray($orgarray, $newarray);
echo '<pre>';
print_r($newarray);
echo '</pre>';