today I add a new photogallery to my site based on JQuery and the Gallery Snippet.
There was no function to add pictures to the album row, so I edited the snippet.galleryAlbum.
Don’t know if already a solution had been existed, but I found some posts of user, who are in need of this too.
<?php
/**
* Gallery
*
* Copyright 2010 by Shaun McCormick <[email protected]>
*
* Gallery is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* Gallery is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Gallery; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package gallery
*/
/**
* Loads a list of Albums
*
* @package gallery
*/
$gallery = $modx->getService('gallery','Gallery',$modx->getOption('gallery.core_path',null,$modx->getOption('core_path').'components/gallery/').'model/gallery/',$scriptProperties);
if (!($gallery instanceof Gallery)) return '';
/* setup default properties */
$rowTpl = $modx->getOption('rowTpl',$scriptProperties,'galAlbumRowTpl');
$tplCover = $modx->getOption('albumCover',$scriptProperties,'galAlbumCoverRowTpl');
$showInactive = $modx->getOption('showInactive',$scriptProperties,false);
$prominentOnly = $modx->getOption('prominentOnly',$scriptProperties,true);
$toPlaceholder = $modx->getOption('toPlaceholder',$scriptProperties,false);
$sort = $modx->getOption('sort',$scriptProperties,'createdon');
$sortAlias = $modx->getOption('sortAlias',$scriptProperties,'galAlbum');
$dir = $modx->getOption('dir',$scriptProperties,'DESC');
$limit = $modx->getOption('limit',$scriptProperties,10);
$start = $modx->getOption('start',$scriptProperties,0);
$parent = $modx->getOption('parent',$scriptProperties,0);
$showAll = $modx->getOption('showAll',$scriptProperties,false);
$albumRequestVar = $modx->getOption('albumRequestVar',$scriptProperties,'galAlbum');
$tag = $modx->getOption('tag',$scriptProperties,'');
// NOT NECESSARY, MAYBE FOR ANOTHER NEW PROJECT
/*$tagc = $modx->newQuery('galItem');
$tagc->setClassAlias('ItemsJoin');
$tagc->select($modx->getSelectColumns('galItem','ItemsJoin','',array('filename')));
$tagc->innerJoin('galAlbumItem','AlbumItems');
$tagc->innerJoin('galAlbum','Album',$modx->getSelectColumns('galAlbumItem','AlbumItems','',array('album')).' = '.$modx->getSelectColumns('galAlbum','Album','',array('id')));
$tagc->innerJoin('galTag','Tags');
$tagc->where($modx->getSelectColumns('galItem','ItemsJoin','',array('id')).' = '.$modx->getSelectColumns('galAlbumItem','AlbumItems','',array('item')));
$tagc->where(array(
'Tags.tag' => "albumcover"
));
$tagc->where(array(
'Album.id' => 'galAlbum.'.'id'
));
$tagc->prepare();
$tagSql = $tagc->toSql();*/
/* build query */
$c = $modx->newQuery('galAlbum');
$c->select(array('galAlbum.*'));
if (!$showInactive) {
$c->where(array(
'active' => true,
));
}
if ($prominentOnly) {
$c->where(array(
'prominent' => true,
));
}
if (empty($showAll)) {
$c->where(array(
'parent' => $parent,
));
}
$c->sortby($sortAlias.'.'.$sort,$dir);
if ($limit > 0) { $c->limit($limit,$start); }
$albums = $modx->getCollection('galAlbum',$c);
/* iterate */
/* CODE PART ADDED BY greenVisions ([email protected]) BASED ON Shaun McCormick's GALLERYALBUM SNIPPET */
$output = '';
foreach ($albums as $album) {
$albumArray = $album->toArray();
$albumArray['totalPictures'] = 0;
$albumItems = $album->getMany('AlbumItems');
foreach ($albumItems as $albumItem) {
$albumArray['totalPictures'] += 1;
$item = $albumItem->getOne('Item');
$tags = $item->getMany('Tags');
foreach ($tags as $tag) {
$tagArray = $tag->toArray();
if(!empty($tagArray) && $tagArray['tag'] = $tag){
$itemArray = $item->toArray();
$itemArray['filename'] = basename($item->get('filename'));
$itemArray['image_absolute'] = $modx->getOption('gallery.files_url').$item->get('filename');
$itemArray['filesize'] = $item->get('filesize');
$itemArray['thumbnail'] = $item->get('thumbnail',array(
'w' => (int)$modx->getOption('thumbWidth',$scriptProperties,100),
'h' => (int)$modx->getOption('thumbHeight',$scriptProperties,100),
'zc' => (boolean)$modx->getOption('thumbZoomCrop',$scriptProperties,1),
'far' => (boolean)$modx->getOption('thumbFar',$scriptProperties,'C'),
));
$itemArray['image'] = $item->get('thumbnail',array(
'w' => (int)$modx->getOption('imageWidth',$scriptProperties,500),
'h' => (int)$modx->getOption('imageHeight',$scriptProperties,500),
'zc' => (boolean)$modx->getOption('imageZoomCrop',$scriptProperties,false),
'far' => (string)$modx->getOption('imageFar',$scriptProperties,''),
));
$thumbOutput = $modx->getChunk($tplCover,$itemArray);
$albumArray['albumThumb'] = $thumbOutput;
}
}
}
$albumArray['albumRequestVar'] = $albumRequestVar;
$output .= $gallery->getChunk($rowTpl,$albumArray);
}
if ($toPlaceholder) {
$modx->setPlaceholder($toPlaceholder,$output);
return '';
}
return $output;