Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Widgets /

Discuss SilverStripe Widgets.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Modifying Gallery Widget : Latest Pictures


Go to End


2 Posts   1809 Views

Avatar
Fraser

Community Member, 48 Posts

11 June 2012 at 12:22pm

I need to modify the Gallery>Latest Pictures widget slightly to pass through a thumbnail url and a full image URL. I want them both scaled to a certain size;

I have managed to get the URL for the original image but would like your guys' help with getting a resized image in the same way that the Thumbnail is resized

LatestPicturesWidget.php:


function Pictures() {
    Requirements::css("widgets_gallery/LatestPicturesWidget.css");
		$nrtoshow = (0<$this->NumberToShow) ? $this->NumberToShow : $this->defaults["NumberToShow"];
		$pictures = DB::query("SELECT f.`ID`, f.`Filename`, f.`Name`, f.`Title`, s.`URLSegment` FROM `gallerypage_live` g LEFT JOIN `sitetree_live` s ON g.`ID` = s.`ID` LEFT JOIN `file` f ON f.`ParentID` = g.`FolderID` WHERE f.`ClassName` = 'Image' ORDER BY f.`Created` DESC LIMIT 0,$nrtoshow;");
    	$thumbnails = new DataObjectSet;
      	foreach ($pictures as $picture){
	    	$picture["GalleryLink"] = Director::baseURL().$picture["URLSegment"];
	      	$thumbnail = new Image($picture);
	      	$thumbnail = $thumbnail->getFormattedImage( "PaddedImage", $this->ThumbnailWidth, $this->ThumbnailHeight);
	      	$thumbnail->setField("GalleryLink", Director::baseURL().$picture["URLSegment"]);
	      
	     	$thumbnail->setField("MainLink",Director::baseURL().$picture['Filename']);
				      
	      	$thumbnail->setField("Name", $picture["Name"]);
	      	$thumbnail->setField("Title", $picture["Title"]);
		  	$thumbnails->push($thumbnail);
		  	
    	}
    	unset($pictures);
		return $thumbnails;
	}

LatestPicturesWidget.ss:

<% control Pictures %>
		<li>
			<!--<a href="$GalleryLink"><img src="$Filename" alt="" title="$Title" class="LatestPicturesImage" /></a>-->
			<a href="$MainLink" class="fancybox" rel="group" title="$Title"><img src="$Filename" alt="" title="$Title" class="LatestPicturesImage" /></a>

		</li>
	<% end_control %>

Thanks in advance

Avatar
Fraser

Community Member, 48 Posts

11 June 2012 at 12:40pm

Solved

function Pictures() {
    Requirements::css("widgets_gallery/LatestPicturesWidget.css");
		$nrtoshow = (0<$this->NumberToShow) ? $this->NumberToShow : $this->defaults["NumberToShow"];
		$pictures = DB::query("SELECT f.`ID`, f.`Filename`, f.`Name`, f.`Title`, s.`URLSegment` FROM `gallerypage_live` g LEFT JOIN `sitetree_live` s ON g.`ID` = s.`ID` LEFT JOIN `file` f ON f.`ParentID` = g.`FolderID` WHERE f.`ClassName` = 'Image' ORDER BY f.`Created` DESC LIMIT 0,$nrtoshow;");
		$largeImage = new DataObjectSet;
    	$thumbnails = new DataObjectSet;
      	foreach ($pictures as $picture){
      		
      		$largeImage = new Image($picture);
      		$largeImage = $largeImage->getFormattedImage( "PaddedImage", 632, 418);

	    	$picture["GalleryLink"] = Director::baseURL().$picture["URLSegment"];
	    	
	      	$thumbnail = new Image($picture);
	      	$thumbnail = $thumbnail->getFormattedImage( "PaddedImage", $this->ThumbnailWidth, $this->ThumbnailHeight);
	      	$thumbnail->setField("GalleryLink", Director::baseURL().$picture["URLSegment"]);
	      
	     	$thumbnail -> setField("MainLink",$largeImage);
				      
	      	$thumbnail->setField("Name", $picture["Name"]);
	      	$thumbnail->setField("Title", $picture["Title"]);
		  	$thumbnails->push($thumbnail);
		  	
    	}
    	unset($largeImage);
    	unset($pictures);
		return $thumbnails;
	}