Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Image Gallery Widget

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 2375 Views
  • boombox
    Avatar
    Community Member
    44 Posts

    Image Gallery Widget Link to this post

    Greetings - I'm looking to extend the Image gallery with a widget to allow displaying of x number images from a selected album

    I have been able to create a function for the Calendar Module to display the Latest Events as below - where I added a select box for a Calendar event to be "featured" in the Calendar event Class

    function UpcomingEvent()
       {
          Requirements::css('event_calendar/css/calendar.css');
          Requirements::javascript("event_calendar/javascript/calendar_core.js");
          return DataObject::get_one("Calendar")->upcomingEvents(1,"FeaturedEvent = 1");
       }

    So I would like to create a similar function in the Image Gallery Module for a widget that allows a featured Album(s) to be displayed on any page .

    Uncle Cheese - Can you point me in the direction for creating a function in the Class ImageGalleryAlbum or ImageGalleryPage similar to the upcomingEvents function in the Calendar Class?

    E.g.

    function LatestGallery()
       {
          Requirements::css( based on pop up mode );
          Requirements::javascript( based on pop up mode );
          return DataObject::get_one("ImageGalleryPage")->latestGalleries(1,"FeaturedEvent = 1");
       }

    So need to develop the latestGalleries function

    Thanks

  • boombox
    Avatar
    Community Member
    44 Posts

    Re: Image Gallery Widget Link to this post

    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>

    2375 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.