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.

Widgets

Discuss SilverStripe Widgets.

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

Modifying Gallery Widget : Latest Pictures


Reply

2 Posts   476 Views

Avatar
Fraser

11 June 2012 at 12:22pm Community Member, 46 Posts

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

11 June 2012 at 12:40pm Community Member, 46 Posts

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;
   }