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 --- lib/album.php | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'lib') 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; } /** -- cgit v1.2.3