<?php
$mycomponent = $modx->getService('mycomponent','MyComponent',$modx->getOption('mycomponent.core_path',null,$modx->getOption('core_path').'components/mycomponent/').'model/mycomponent/',$scriptProperties);
if (!($mycomponent instanceof MyComponent)) return '';
/* setup default properties */
$tpl = $modx->getOption('tpl',$scriptProperties,'currentGalleryFirstPage');
$sort = $modx->getOption('sort',$scriptProperties,'id');
$dir = $modx->getOption('dir',$scriptProperties,'ASC');
$limit = $modx->getOption('limit',$scriptProperties,6);
$offset = $modx->getOption('offset',$scriptProperties,0);
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
$record = $modx->query("SELECT MAX(id) FROM {$modx->getTableName('galleries')} WHERE phase=0");
$highestId = (integer) $record->fetch(PDO::FETCH_COLUMN);
$record->closeCursor();
$galleryId = $highestId;
// Get total number of records
$c = $modx->newQuery('artworks');
if(!empty($galleryId)) {
$c->where(array(
'gallery_id' => $galleryId
));
}
$total = $modx->getCount('artworks',$c);
$modx->setPlaceholder($totalVar,$total);
$c->limit($limit,$offset);
$c->sortby($sort,$dir);
$artworks = $modx->getCollection('artworks',$c);
$output = '';
foreach ($artworks as $artwork) {
$artworkArray = $artwork->toArray();
$output .= $sovereign->getChunk($tpl,$artworkArray);
}
return $output;
<a href="#" data-id="[[+id]]" class="gallery_item fancybox-gallery fancybox.inline" rel="gallery">
<img src="[[++assets_url]]components/mycomponent/galleries/[[+gallery_id]]/thumbnails/[[+filename]]_medium.jpeg" alt="[[+art_title]]" />
<div class="item_curtain">
<h1>[[+art_title]]</h1>
<h2>[[+title]] [[+first_name]] [[+surname]]</h2>
</div>
</a>
<?php
$mycomponent = $modx->getService('mycomponent','MyComponent',$modx->getOption('mycomponent.core_path',null,$modx->getOption('core_path').'components/mycomponent/').'model/mycomponent/',$scriptProperties);
if (!($mycomponent instanceof MyComponent)) return '';
/* setup default properties */
$tpl = $modx->getOption('tpl',$scriptProperties,'currentGallerySplitSlides');
$record = $modx->query("SELECT MAX(id) FROM {$modx->getTableName('galleries')} WHERE phase=0");
$highestId = (integer) $record->fetch(PDO::FETCH_COLUMN);
$record->closeCursor();
$galleryId = $highestId;
// Get total number of records
$c = $modx->newQuery('artworks');
if(!empty($galleryId)) {
$c->where(array(
'gallery_id' => $galleryId
));
}
$total = $modx->getCount('artworks',$c);
//Divide total by 6 and round up to get the number of slides required
if($total < 7) {
$numOfSlides = 1;
} else {
$numOfSlides = ceil($total/6);
}
// now I need to somehow set placeholders for [[+slideNum]] and [[+offset]] in the tpl below but they need to be different for each iteration!
<div>
<h2 class="title">Slide [[+slideNum]]</h2>
[[!getLatestGallery? &limit=`6` &offset=`[[+offset]]` &tpl=`currentGalleryOtherPage`]]
</div>
This question has been answered by Bruno17. See the first response.
[[pdoResources?
&loadModels=`mycomponent`
&class=`artworks`
&where=`{"gallery_id":"[[getTheGalleryIDhere]]"}`
&tpl=`galleryItemTpl`
&tpl_n6=`galleryItemTpl_6`
&tpl_n7=`galleryItemTpl_7`
&tplLast=`galleryItemTpl_last`
]]
[[+idx:is=`1`:then=`
<div>
<h2 class="title">Slide</h2>
`:else=``]]
[[$galleryItem? &idx=`[[+idx]]`]]
[[$galleryItem? &idx=`[[+idx]]`]] </div>
<div>
<h2 class="title">Slide</h2>
[[$galleryItem? &idx=`[[+idx]]`]]
[[+idx:is=`1`:then=`
<div>
<h2 class="title">Slide</h2>
`:else=``]]
[[$galleryItem? &idx=`[[+idx]]`]]
</div>
<a href="#" data-id="[[+id]]" class="gallery_item fancybox-gallery fancybox.inline" rel="gallery">
<img src="[[++assets_url]]components/mycomponent/galleries/[[+gallery_id]]/thumbnails/[[+filename]]_medium.jpeg" alt="[[+art_title]]" />
<div class="item_curtain">
<h1>[[+art_title]]</h1>
<h2>[[+title]] [[+first_name]] [[+surname]]</h2>
</div>
</a>