Good guess.
In the Evolution API there are methods like getAllChildren(), getActiveChildren(), getDocumentChildren(), getChildIds()... I’m looking for the equivalent of this functionality in Revolution. I see no similar-sounding methods. My hunch is that this is because everything is much more abstracted in Revo(?)
<?php
$output = array();
$criteria = $modx->newQuery('modResource', array('parent' => $parent));
// You can set other criteria based on Snippet options or other data
if (empty($showUnpublished)) $criteria->where(array('published' => true));
if (empty($showDeleted)) $criteria->where(array('deleted' => false));
// you can limit the amount of memory you use by specifying the fields you need
if (!empty($fields)) $fields = explode(',', $fields);
// just getting any spaces out of comma-delimited field list
foreach ($fields as $fieldKey => $field) $fields[$fieldKey] = trim($field);
// now add the fields to the criteria
$criteria->select('id'); // id is required when retrieving objects with lazy loading
$criteria->select($fields);
$children = $modx->getCollection('modResource', $criteria);
foreach ($children as $child) {
// here we might skip results based on permissions, for instance:
// if the user does not have permission to "list" a Resource, skip it
if (!$child->checkPolicy('list')) continue;
// here you can process each child against a Chunk serving as a tpl
// note again we are limiting the placeholders to be replaced to the specified fields
$output[]= $modx->getChunk($tpl, $child->get($fields));
}
return implode("\n", $output);
?>$parent = isset($doc) ? $doc : $modx->documentIdentifier;
$criteria->select($fields);
if ($fields) { $criteria->select($fields); }I would recommend this instead, as it’s more proper Revo code:
I wrote a line to set $parent to the current document unless a different doc ID is specified in the snippet call:
$parent = isset($doc) ? $doc : $modx->documentIdentifier;
$parent = $modx->getOption('doc',$scriptProperties,$modx->resource->get('id'));
Actually, that if should surround both select() calls, i.e.:
Also, I think that the line
$criteria->select($fields);
needs to be modified to
if ($fields) { $criteria->select($fields); }
<?php
if ($fields) {
$criteria->select('id');
$criteria->select($fields);
}
?><?php $output[]= $modx->getChunk($tpl, !empty($fields) ? $child->get($fields) : $child->toArray()); ?>