Hi
I have tried modifying the Gallery widget for the ImageGallery Module
I created a file LatestAlbumsWidget.php
The orginal code uses a SQL call - I prefer to use a dataObject call so If anyone can assist that would be great!
Here's the code used that does return the latest pictures but what I am looking for is to be able to select the album to be featured and show latest images from that album only
- the function AlbumTitle doesn't currently work
The Template is not displaying the title or the decription of the album
#######################
LatestAlbumsWidget.php
#######################
<?php
class LatestAlbumsWidget extends Widget {
static $db = array(
"AlbumsToShow" => "Int",
"ImagesToShow" => "Int",
"ThumbnailWidth" => "Int",
"ThumbnailHeight" => "Int"
);
static $defaults = array(
"AlbumsToShow" => "2",
"ImagesToShow" => "3",
"ThumbnailWidth" => "120",
"ThumbnailHeight" => "90"
);
function getCMSFields() {
return new FieldSet(
new NumericField("AlbumsToShow", _t("LatestAlbumsWidget.NTS", "Number of albums to show (0 for All)")),
new NumericField("ImagesToShow", _t("LatestAlbumsWidget.NTF", "Number of pictures to show (0 for All)")),
new NumericField("ThumbnailWidth", _t("LatestAlbumsWidget.THUMBWIDTH", "Thumbnail width")),
new NumericField("ThumbnailHeight", _t("LatestAlbumsWidget.THUMBHEIGHT", "Thumbnail height"))
);
}
function DescriptionSegment() {
if(!class_exists("ImageGalleryAlbum")) {
return _t("LatestGalleriesWidget.NOCLASS","You don't have the Image Gallery module installed, which is required by this widget.");
}
return parent::DescriptionSegment();
}
function Title(){
return _t("LatestAlbumsWidget.TITLE","Latest Events");
}
function CMSTitle(){
return _t("LatestAlbumsWidget.CMSTITLE","Latest Albums");
}
function Description(){
return _t("LatestAlbumsWidget.DESCRIPTION","Shows a list of albums that were changed most recently, and shows thumbnails of the pictures that have been added most recently to each gallery.");
}
function Pictures() {
Requirements::css("widgets_gallery/LatestAlbumsWidget.css");
$images_nrtoshow = (0<$this->ImagesToShow) ? $this->ImagesToShow : $this->defaults["ImagesToShow"];
$pictures = DB::query("SELECT f.`ID`, f.`Filename`, f.`Name`, f.`Title`, a.`AlbumName` FROM `ImageGalleryItem` g LEFT JOIN `File` f ON g.`ImageID` = f.`ID` LEFT JOIN `ImageGalleryAlbum` a ON a.`ID` = g.`AlbumID` WHERE f.`ClassName` = 'ImageGalleryImage' ORDER BY g.`SortOrder` AND g.`AlbumID` DESC LIMIT 0,$images_nrtoshow;");
$thumbnails = new DataObjectSet;
foreach ($pictures as $picture){
$picture["GalleryLink"] = Director::baseURL().$picture["Filename"];
$thumbnail = new Image($picture);
$thumbnail = $thumbnail->getFormattedImage( "PaddedImage", $this->ThumbnailWidth, $this->ThumbnailHeight);
$thumbnail->setField("GalleryLink", Director::baseURL().$picture["Filename"]);
$thumbnail->setField("Name", $picture["Name"]);
$thumbnail->setField("Title", $picture["Title"]);
$thumbnails->push($thumbnail);
}
unset($pictures);
return $thumbnails;
}
function AlbumTitle()
{
return $this->Pictures('AlbumID')->AlbumName;
}
}
?>
#########################################
LatestAlbumsWidget.ss
#########################################
<div class="latestAlbum">
<% control AlbumTitle %>
<h1><a class="$LinkingMode" href="$Link" title="$AlbumName">$AlbumName</a></h1>
<% end_control %>
<ul class="latestPictures">
<% control Pictures %>
<li style="height:{$Top.ThumbnailSize}px;width:{$Top.ThumbnailSize}px;">
<a id="ViewLink-$ID" rel="$RelAttr" class="$ClassAttr" title="$Caption" href="$GalleryLink"><img src="$Filename" alt="$Title" class="LatestPicturesImage" /></a>
</li>
<% end_control %>
</ul>
<div id="moreBtn"><a href="/photo-gallery/">view more</a></div>
<div class="clear"></div>
</div>