It would go something like this:
1. In the "Index" document, you would make Ditto to list each document that is direct child if index:
[[Ditto? &parents=`[*id*]` &depth=`1` &tpl=`dittoTpl`]]
2. Create "dittoTpl" chunk to template Ditto’s output (to call your snippet):
[[YourSnippet? &docId=`[+id+]`]]
3. Create "YourSnippet" snippet to call MaxiGallery:
<?php
if($docId == null || $docId == '') {
return 'Empty docId';
}
//get gallery ids
$rs = $modx->db->select("DISTINCT gal_id", $modx->db->config['table_prefix'].'maxigallery');
$galIds= array();
while ($row = $modx->db->getRow($rs)) {
array_push($galIds, $row['gal_id']);
}
//if document has gallery, show a random pic from it
if (in_array($docId, $galIds)) {
$mgOutput = $modx->runSnippet('MaxiGallery', array('gal_query_ids' => $docId, 'limit' => '1', 'order_by' => 'random', 'galleryOuterTpl' => '@CODE:[+maxigallery.pictures+]', 'galleryPictureTpl' => 'mgGalleryPictureTpl'));
} else { //else show a random pic from it's childgalleries
$mgOutput = $modx->runSnippet('MaxiGallery', array('childgalleries_ids' => $docId, 'limit' => '1', 'order_by' => 'random', 'galleryOuterTpl' => '@CODE:[+maxigallery.childgalleries+]', 'childgalleryTpl' => 'mgChildgalleryTpl'));
}
return '<div class="thumbscontainer"><ul class="thumbs">'.$mgOutput.'</ul></div>';
?>
4. Then do a "mgGalleryPictureTpl" to link to the gallery index instead of straight to the picture:
<li>
<a href="[~[+maxigallery.picture.gal_id+]~]">
<img src="[(base_url)][+maxigallery.path_to_gal+]tn_[+maxigallery.picture.filename+]" class="thumbnail" title="[+maxigallery.strings.go_to_gallery+]" alt="[+maxigallery.strings.go_to_gallery+]" />
</a>
<p style="width:[+maxigallery.picture_width_thumb+]px;">[+maxigallery.pageinfo.pagetitle:htmlent+]</p>
</li>
5. Do a "mgChildgalleryTpl" to link to the gallery parent (Index subgallery), instead of the gallery itself
<li>
<a href="[~[+maxigallery.pageinfo.parent+]~]">
<img src="[(base_url)][+maxigallery.path_to_gal+]tn_[+maxigallery.picture.filename+]" class="thumbnail" title="[+maxigallery.strings.go_to_gallery+]" alt="[+maxigallery.strings.go_to_gallery+]" />
</a>
<p style="width:[+maxigallery.picture_width_thumb+]px;">[+maxigallery.pageinfo.pagetitle:htmlent+]</p>
</li>
This might not work straight out of the box, but should get you pretty close..