From f1f08168b325605a489b5f21cfdfff96312d55f8 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sat, 23 Oct 2010 15:01:00 +0000 Subject: moved cover code into album class --- actions/edit.php | 2 +- actions/edit_multi.php | 2 +- lib/album.php | 38 ++++++++++++++++++++++++++++- views/default/object/album.php | 12 ++++----- views/default/river/object/album/create.php | 5 ++-- views/default/river/object/image/create.php | 3 --- views/default/tidypics/albums.php | 5 ++-- views/default/tidypics/forms/edit.php | 2 +- views/default/tidypics/forms/edit_multi.php | 2 +- views/rss/object/album.php | 6 ++--- 10 files changed, 56 insertions(+), 21 deletions(-) diff --git a/actions/edit.php b/actions/edit.php index db6e26ab9..cca66941a 100644 --- a/actions/edit.php +++ b/actions/edit.php @@ -65,7 +65,7 @@ if (is_array($tagarray)) { //if cover meta is sent from image save as metadata if ($subtype == 'image' && $cover == elgg_echo('album:cover')) { $album = get_entity($container_guid); - $album->cover = $entity->guid; + $album->setCoverImageGuid($entity->guid); } // Success message diff --git a/actions/edit_multi.php b/actions/edit_multi.php index c938e6065..1d0e537b0 100644 --- a/actions/edit_multi.php +++ b/actions/edit_multi.php @@ -49,7 +49,7 @@ foreach($image_guid_array as $key => $im) { //if cover meta is sent from image save as metadata if ($cover == $im) { - $album_entity->cover = $im; + $album_entity->setCoverImageGuid($im); } } } diff --git a/lib/album.php b/lib/album.php index 472bf69d8..916ccbc31 100644 --- a/lib/album.php +++ b/lib/album.php @@ -67,7 +67,43 @@ class TidypicsAlbum extends ElggObject { $count = $this->getSize(); - return elgg_view_entity_list($images, $count, $offset, $limit, FALSE, FALSE, TRUE); + return elgg_view_entity_list($images, $count, $offset, $limit, false, false, true); + } + + /** + * Get the GUID of the album cover + * + * @return int + */ + public function getCoverImageGuid() { + if ($this->getSize() == 0) { + return 0; + } + + $guid = $this->cover; + $imageList = $this->getImageList(); + if (!in_array($guid, $imageList)) { + // select random photo to be cover + $index = array_rand($imageList, 1); + $guid = $imageList[$index]; + $this->cover = $guid; + } + return $guid; + } + + /** + * Set the GUID for the album cover + * + * @param int $guid + * @return bool + */ + public function setCoverImageGuid($guid) { + $imageList = $this->getImageList(); + if (!in_array($guid, $imageList)) { + return false; + } + $this->cover = $guid; + return true; } /** diff --git a/views/default/object/album.php b/views/default/object/album.php index b87bef444..7c43c4e96 100644 --- a/views/default/object/album.php +++ b/views/default/object/album.php @@ -27,9 +27,9 @@ if (get_context() == "search") { * *****************************************************************************/ - //get album cover if one was set - if ($album->cover) { - $album_cover = '' . $title . ''; + $album_cover_guid = $album->getCoverImageGuid(); + if ($album_cover_guid) { + $album_cover = '' . $title . ''; } else { $album_cover = 'new album'; } @@ -69,9 +69,9 @@ if (get_context() == "search") { } $info .= "

"; - //get album cover if one was set - if ($album->cover) { - $icon = "getURL()}\">" . 'thumbnail'; + $album_cover_guid = $album->getCoverImageGuid(); + if ($album_cover_guid) { + $icon = "getURL()}\">" . 'thumbnail'; } else { $icon = "getURL()}\">" . 'new album'; } diff --git a/views/default/river/object/album/create.php b/views/default/river/object/album/create.php index ef50f9988..47d20f3ae 100644 --- a/views/default/river/object/album/create.php +++ b/views/default/river/object/album/create.php @@ -20,8 +20,9 @@ if ($group_album) { $album_river_view = get_plugin_setting('album_river_view', 'tidypics'); if ($album_river_view == "cover") { - if ($album->cover) { - $string .= "
wwwroot . 'mod/tidypics/thumbnail.php?file_guid=' . $album->cover . '&size=thumb" class="tidypics_album_cover" alt="thumbnail"/>' . "
"; + $album_cover_guid = $album->getCoverImageGuid(); + if ($album_cover_guid) { + $string .= "
wwwroot . 'mod/tidypics/thumbnail.php?file_guid=' . $album_cover_guid . '&size=thumb" class="tidypics_album_cover" alt="thumbnail"/>' . "
"; } } else { diff --git a/views/default/river/object/image/create.php b/views/default/river/object/image/create.php index 188fc6ff1..8a0a8deff 100644 --- a/views/default/river/object/image/create.php +++ b/views/default/river/object/image/create.php @@ -18,9 +18,6 @@ $string = sprintf(elgg_echo("image:river:created"), $url, $image_link, $album_li $string .= "
"; -/* // this adds the album cover to the river display - $string .= "getURL() . "\"> wwwroot . 'mod/tidypics/thumbnail.php?file_guid=' . $album->cover . '&size=thumb" class="tidypics_album_cover" alt="thumbnail"/> '; -*/ $string .= "getURL() . "\"> wwwroot . 'mod/tidypics/thumbnail.php?file_guid=' . $image->guid . '&size=thumb" class="tidypics_album_cover" alt="thumbnail"/> '; $string .= "
"; diff --git a/views/default/tidypics/albums.php b/views/default/tidypics/albums.php index a4b2ee906..7e0cd2d6c 100644 --- a/views/default/tidypics/albums.php +++ b/views/default/tidypics/albums.php @@ -14,8 +14,9 @@ echo '
'; if ($owner_albums) { foreach ($owner_albums as $album) { - if ($album->cover) { - $album_cover = '' . $album->title . ''; + $album_cover_guid = $album->getCoverImageGuid(); + if ($album_cover_guid) { + $album_cover = '' . $album->title . ''; } else { $album_cover = '' . $album->title . ''; } diff --git a/views/default/tidypics/forms/edit.php b/views/default/tidypics/forms/edit.php index 74d8e85ec..8e2bd9bcc 100644 --- a/views/default/tidypics/forms/edit.php +++ b/views/default/tidypics/forms/edit.php @@ -75,7 +75,7 @@ $container_guid = page_owner(); // determine if it is already the cover $img_guid = $vars['entity']->guid; $album = get_entity($container_guid); - $cover_guid = $album->cover; + $cover_guid = $album->getCoverImageGuid(); if ($cover_guid != $img_guid) { diff --git a/views/default/tidypics/forms/edit_multi.php b/views/default/tidypics/forms/edit_multi.php index c16c8eea9..8c3e40242 100644 --- a/views/default/tidypics/forms/edit_multi.php +++ b/views/default/tidypics/forms/edit_multi.php @@ -11,7 +11,7 @@ // make sure one of the images becomes the cover if there isn't one already $album_entity = get_entity($vars['album_guid']); - if (!$album_entity->cover) { + if (!$album_entity->getCoverImageGuid()) { $no_cover = true; } diff --git a/views/rss/object/album.php b/views/rss/object/album.php index 34cf58395..8a8f97cc2 100644 --- a/views/rss/object/album.php +++ b/views/rss/object/album.php @@ -22,8 +22,8 @@ if (get_context() == "search" && get_input('search_viewtype') == "gallery") { // use fullsize image $base_url_fullsize = $vars['url'] . 'pg/photos/download/'; - // insert cover image if it exists image - if ($album->cover) { + $album_cover_guid = $album->getCoverImageGuid(); + if ($album_cover_guid) { // Set title $vars['title'] = $album->title; if (empty($vars['title'])) { @@ -33,7 +33,7 @@ if (get_context() == "search" && get_input('search_viewtype') == "gallery") { } else { $title = $vars['config']->sitename . ": " . $vars['title']; } - $album_cover_url = $vars['url'] . 'mod/tidypics/thumbnail.php?file_guid=' . $album->cover . '&size=thumb'; + $album_cover_url = $vars['url'] . 'mod/tidypics/thumbnail.php?file_guid=' . $album_cover_guid . '&size=thumb'; ?> <![CDATA[<?php echo $title; ?>]]> -- cgit v1.2.3