Permalink
Browse files

[#217] Add default cover when using GalleryAlbums with cover displays…

… and no item is in the album
  • Loading branch information...
2 parents b894382 + 41a0364 commit 5bf0bb43f29e6607a2e25ffc694cec41ee88bf4e Shaun McCormick committed Jul 3, 2012
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -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
@@ -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(
@@ -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);
@@ -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);
@@ -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;

0 comments on commit 5bf0bb4

Please sign in to comment.