Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » trying to get the latest images out of an ImageObject

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: 562 Views
  • benni91
    Avatar
    Community Member
    72 Posts

    trying to get the latest images out of an ImageObject Link to this post

    Hi @ all,

    I'm trying to create my own image gallery. The galleries preview at the holder, should contain the last 4 images of this gallery.
    The way i tried it doesn't work. I hope someone could help me.

    The relations between the single pages and objects
    GalleryHolder.php -> GalleryPage.php -> GalleryImagesObject.php -> Image Image Image ...

    The GalleryHolder.php has this two function to sort the galleries and to get the latest 4 images of each gallery

       public function getGalleries() {
          return DataObject::get('GalleryPage', "ParentID = '$this->ID'", 'Date DESC');
       }
       
       function LatestGalleryImages($num=4) {
       $galleryimage = DataObject::get_one("GalleryHolder");
       return ($galleryimage) ? DataObject::get("GalleryPage", "ParentID = $galleryimage->ID", "Date DESC", "", $num) : false;
       }

    that's the GalleryImagesObject.php

    <?php
    class GalleryImagesObject extends DataObject {

       public static $db = array(
          'Title' => 'Text',
          'Description' => 'Text'
       );

       public static $has_one = array(
          'GalleryImage' => 'Image',
          'GalleryPage' => 'GalleryPage'
       );

       public function getCMSFields_forPopup() {

    return new FieldSet(
       new TextField('Title', 'Titel des Bildes'),
       new TextAreaField('Description', 'Beschreibung des Bildes'),
       new ImageField('GalleryImage', 'Bild(er) hochladen')
    );

       }
    }

    ?>

    and my GallerHolder.ss looks like this.

    <% control getGalleries %>
       <% control GalleryImagesObject %>
          $GalleryImage
       <% end_control %>
       <a href="$Link" title="Die Gallerie $Title anzeigen">$Title</a>
    <% end_control %>


    -----

    Where's the mistake(s) i made? I can see the link but not the images
    Thx for your Help

    Benni

    P.s. Website

  • UncleCheese
    Avatar
    4085 Posts

    Re: trying to get the latest images out of an ImageObject Link to this post

    How does GalleryPage relate to GalleryImageObject?

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

  • benni91
    Avatar
    Community Member
    72 Posts

    Re: trying to get the latest images out of an ImageObject Link to this post

    Sry, i think that was wrong in my first post. I'm not able to describe the relations good in english.

    Thats the GalleryPage.php I hope it will help

    <?php
    class GalleryPage extends Page {
          
       static $allowed_children = 'none';
       static $default_parrent = 'GalleryHolder';
       static $can_be_root = false;

       public static $db = array(
          'Date' => 'Date',
          'Description' => 'HTMLText',
          //'ThumbnailSize' => 'Text',
       );
       
       public static $has_many = array(
          'GalleryImages' => 'GalleryImagesObject'
       );

       function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->removeFieldFromTab('Root.Content.Main', 'Content');
          $fields->addFieldToTab('Root.Content.Main', $date = new DateField('Date', 'Datum der Aufnahmen'));
          $date->setConfig('showcalendar', true);   
          $fields->addFieldToTab('Root.Content.Main', new SimpleTinyMCEField('Description','Beschreibung der Gallerie'));
          //$fields->addFieldToTab('Root.Content.Main', new TextField('ThumbnailSize','Größe der Thumbnails (in px / muss ausgefüllt sein)'));
          $fields->addFieldToTab('Root.Content.Main', $GalleryImages = new ImageDataObjectManager($this, 'GalleryImages', 'GalleryImagesObject', 'GalleryImage', array('Title' => 'Titel des Bildes', 'Description' => 'Beschreibung des Bildes'), 'getCMSFields_forPopup'));
          $GalleryImages->copyOnImport = false;
          //$GalleryImages->setPageSize( '999' );
          $GalleryImages->setPerPageMap('50');
          $GalleryImages->setPageSize('50');
          return $fields;
       }
    }

    class GalleryPage_Controller extends Page_Controller {

       public function PrevNextPage($Mode = 'next') {
          if($Mode == 'next'){
             $Where = "ParentID = ($this->ParentID) AND Sort > ($this->Sort)";
             $Sort = "Sort ASC";
          }
          elseif($Mode == 'prev'){
             $Where = "ParentID = ($this->ParentID) AND Sort < ($this->Sort)";
          $Sort = "Sort DESC";
          }
          else{
          return false;
          }
          return DataObject::get("SiteTree", $Where, $Sort, null, 1);
       }
    }
    ?>

  • benni91
    Avatar
    Community Member
    72 Posts
  • benni91
    Avatar
    Community Member
    72 Posts

    Re: trying to get the latest images out of an ImageObject Link to this post

    Hmm is it possible to get the latest Entry out of an DataObject with the Mysql Field "Created" ? If got absolutly no knowlege about sql but i think it should be possible?!

    Perhapse this is one way?

    562 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.