We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11283
    • 11 Posts
    Hey there,

    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.

    So here is the code of snippet.galleryalbums.php

    <?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;


    The galAlbumRowTpl Chunk:

    <ul class="albumPreview">
    <li>
    <a href="[[~[[*id]]]]?[[+albumRequestVar]]=[[+id]]">
    [[+albumThumb]]
    </a>
    <h3>
    <a href="[[~[[*id]]]]?[[+albumRequestVar]]=[[+id]]">
    [[+name]]
    </a>
    </h3>
    <p class="meta">
    [[+description]][[+totalPictures]]
    </p>
    </li>
    </ul>
    


    And a second chunk called galAlbumCoverRowTpl to add the thumbnail:

    <img class="[[+imgCls]]" src="[[+thumbnail]]" />


    Best regards,

    greenvisions.at
      • 28475
      • 28 Posts
      Thank you very much for this!! grin grin grin
        • 17523
        • 3 Posts
        Thanks. Exactly what I needed.

        I first tried to solve it with a [[!Gallery? &tags=`cover` &album=`[[+name]] ] call inside of the galAlbumRowTpl, which worked. But then I was running into problems that, everytime I actually loaded a Gallery, the thumbnail of each gallery was replaced with the Image tagged `cover` of the loaded album. You solved my problem
          • 5340
          • 1,624 Posts
          I still don’t get how this is used. Anyone got the time to post some details.

          I want something like this for listing the albums

          <a href=""><h3>Album title<h3/></a>
          <img src="" title="First image from the album"/>
          <p>Album description<p/>

          Thanks
            • 36447
            • 98 Posts
            Ditto, @cipa, I’m a bit lost too. A call example would be a big help.

            Edit: Ok, a closer look at the snippet reveals that images have to be tagged in order to appear, then it works.
              • 11283
              • 11 Posts
              You have to set a "cover" or "albumcover" or anything else to the picture you want to show as a cover in the Gallery snippet,
              defining [[!Galleryß &tags=`cover` ...

                • 28215
                • 4,149 Posts
                FYI, something similar to this was added in the latest Gallery release, 1.0.2-rc2:

                [[GalleryAlbums? &rowTpl=`galAlbumRowWithCoverTpl`]]
                


                or, by using the [[+image]] placeholder in your custom rowTpl chunk.

                There’s also sorting options, all in the official Gallery docs: http://rtfm.modx.com/display/ADDON/Gallery.GalleryAlbums
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 5340
                  • 1,624 Posts
                  FYI, something similar to this was added in the latest Gallery release, 1.0.2-rc2:

                  Thank you,

                  I’ll try it out right now
                    • 36447
                    • 98 Posts
                    Thanks, could you please provide an example of galAlbumRowWithCoverTpl?
                      • 5340
                      • 1,624 Posts
                      Just put [[+image]] in the current one.
                      I will post a detailed one later when I have it smiley