Skip to content

Commit

Permalink
[#217] Add default cover when using GalleryAlbums with cover displays…
Browse files Browse the repository at this point in the history
… and no item is in the album
  • Loading branch information
Shaun McCormick committed Jul 3, 2012
2 parents b894382 + 41a0364 commit 5bf0bb4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
Binary file added assets/components/gallery/images/album-empty.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions core/components/gallery/docs/changelog.txt
@@ -1,5 +1,9 @@
Changelog for Gallery.

Gallery 1.5.2
====================================
- [#217] Add default cover when using GalleryAlbums with cover displays and no item is in the album

Gallery 1.5.1
====================================
- Add DB caching to Gallery and GalleryAlbums snippets, reducing page load times
Expand Down
16 changes: 15 additions & 1 deletion core/components/gallery/model/gallery/galalbum.class.php
Expand Up @@ -241,7 +241,7 @@ public function getCoverItem($albumCoverSort = 'rank',$albumCoverSortDir = 'ASC'
if ($this->xpdo->getCacheManager()) {
$cache = $this->xpdo->cacheManager->get($cacheKey);
}
if (!$cache) {
if (!$cache || true) {
$c = $this->xpdo->newQuery('galItem');
$c->innerJoin('galAlbumItem','AlbumItems');
$c->where(array(
Expand All @@ -250,8 +250,22 @@ public function getCoverItem($albumCoverSort = 'rank',$albumCoverSortDir = 'ASC'
$c->sortby($albumCoverSort,$albumCoverSortDir);
$count = $this->xpdo->getCount('galItem', $c);
$c->limit(1);

/** @var galItem $item */
$item = $this->xpdo->getObject('galItem',$c);
if (empty($item)) {
$assetsUrl = $this->xpdo->getOption('gallery.assets_url',null,$this->xpdo->getOption('assets_url',null,MODX_ASSETS_URL).'gallery/');
if (strpos($assetsUrl,'http') === false && defined('MODX_URL_SCHEME') && defined('MODX_HTTP_HOST')) {
$assetsUrl = MODX_URL_SCHEME.MODX_HTTP_HOST.$assetsUrl;
}
$item = $this->xpdo->newObject('galItem');
$item->fromArray(array(
'name' => '',
'filename' => $assetsUrl.'images/album-empty.jpg',
'absolute_filename' => true,
'active' => true,
));
}
$item->set('total',$count);
$cache = $item->toArray();
$this->xpdo->cacheManager->set($cacheKey,$cache);
Expand Down
19 changes: 14 additions & 5 deletions core/components/gallery/model/gallery/galitem.class.php
Expand Up @@ -28,8 +28,13 @@ public function get($k, $format = null, $formatTemplate= null) {
case 'thumbnail':
$value = $this->getPhpThumbUrl();
if (empty($format)) $format = array();
$format['src'] = $this->getSiteUrl();
$format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$this->get('filename');
$filename = $this->get('filename');
if ($this->get('absolute_filename')) {
$format['src'] = $filename;
} else {
$format['src'] = $this->getSiteUrl();
$format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename;
}
$url = $value.'&'.http_build_query($format,'','&');
if ($this->xpdo->getOption('xhtml_urls',null,false)) {
$value = str_replace('&','&',$url);
Expand All @@ -40,9 +45,13 @@ public function get($k, $format = null, $formatTemplate= null) {
break;
case 'image':
if (empty($format)) $format = array();
$format['src'] = $this->getSiteUrl();
$format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$this->get('filename');

$filename = $this->get('filename');
if ($this->get('absolute_filename')) {
$format['src'] = $filename;
} else {
$format['src'] = $this->getSiteUrl();
$format['src'] .= $this->xpdo->call('galAlbum','getFilesUrl',array(&$this->xpdo)).$filename;
}
$value = $this->getPhpThumbUrl().'&'.http_build_query($format,'','&');
$value = $this->xpdo->getOption('xhtml_urls',null,false) ? str_replace('&','&',$value) : $value;
break;
Expand Down

0 comments on commit 5bf0bb4

Please sign in to comment.