Jump to:

7938 Posts in 1541 Topics by 945 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Image Thumbnails DataObjectManager

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: 895 Views
  • web2works
    Avatar
    Community Member
    50 Posts

    Image Thumbnails DataObjectManager Link to this post

    Hi I am trying to set the Images uploaded via the 'uploadify' module to thumbnails in the admin area.

    I have tried following the example at: http://www.ssbits.com/snippets/2009/adding-a-thumbnail-to-a-dataobjectmanager-or-complex-table-field/ although I cant seem to get it to work. Can anybody see where I am going wrong.

    Homepage.php

    <?php
    class Homepage extends Page {

    static $singular_name = 'Homepage';
    static $plural_name = 'Home';

    static $has_many = array(
    'Slogans' => 'Slogans',
    'Slides' => 'Slides'
    );

    static $has_one = array (
        'Code' => 'Image'
    );
       
    static $summary_fields = array(
        'SloganImage.CMSThumbnail.Tag' => 'Slogan Image',
        'SloganBackground.CMSThumbnail.Tag' => 'Slogan Backrgound Image'
       );
       
    public function getCMSFields(){
    $fields = parent::getCMSFields();
    $fields->removeFieldFromTab("Root.Content.Main", "Heading");
    $fields->removeFieldFromTab("Root.Content.Main", "Graphic");
    $fields->addFieldToTab("Root.Content.Main", new ImageField("Code"));
    $fields->addFieldToTab("Root.Content.Slogans", new DataObjectManager(
    $this,
    'Slogans',
    'Slogans',
    array(
    'SloganText'=> 'Title',
    'SloganDesc' => 'Description',
    'SloganURI' => 'URi',
    'SloganImage' => 'Image',
    'SloganBackground' => 'Background'
    ),
    'getCMSFields_forPopup'
    ));
    $fields->addFieldToTab("Root.Content.Slides", new DataObjectManager(
    $this,
    'Slides',
    'Slides',
    array(
    'SlideTitle' => 'Title',
    'SlideURI' => 'URi',
    'SlideBody' => 'HTML',
    'SlideText1' => 'Text 1',
    'SlideText2' => 'Text 2',
    'SlideText3' => 'Text 3',
    'SlideText4' => 'Text 4'
    ),
    'getCMSFields_forPopup'
    ));
    return $fields;
    }
       
    }

    class Homepage_Controller extends Page_Controller {
       
       function BlogArticles($num=4) {
          $article = DataObject::get_one("BlogHolder");
          return ($article) ? DataObject::get("BlogEntry", "ParentID = $article->ID", "Date DESC", "", $num) : false;
       }

       function ServicePages($num=8) {
          $page = DataObject::get_one("ServicesPage");
          return ($page) ? DataObject::get("ServicePage", "ParentID = $page->ID", "Title DESC", "", $num) : false;
       }
       
       function AboutPage() {
          return DataObject::get_one("AboutPage");
       }
       
       function SortedSlogans() {
    $children = $this->Slogans();
    $children->Sort('LastEdited', 'DESC');
    return $children;
    }
    }

    Slogans.php

    <?php
    class Slogans extends DataObject {
       
       static $db = array (
          'SloganText' => 'Varchar(100)',
          'SloganURI' => 'Varchar(100)',
          'SloganDesc' => 'Text',
       );

       static $has_one = array (
          'SloganImage' => 'Image',
          'SloganBackground' => 'Image',
          'Homepage' => 'Homepage'
       );
       
    }

    Slides.php

    <?php
    class Slides extends DataObject {
       
       static $db = array (
          'SlideTitle' => 'Varchar(125)',
          'SlideURI' => 'Varchar(125)',
          'SlideText1' => 'HTMLText',
          'SlideText2' => 'HTMLText',
          'SlideText3' => 'HTMLText',
          'SlideText4' => 'HTMLText',
          'SlideBody' => 'HTMLText'
       );

       static $has_one = array (
          'SlideImage' => 'Image',
          'Homepage' => 'Homepage'
       );
       
       function getThumbnail(){
        if ($Image = $this->Image()){
        return $Image->CMSThumbnail();
        }else{
        return '(No Image)';
        }
       }
       
    }

    If anybody can help this would be brilliant.

    Thanks Ben

  • UncleCheese
    Avatar
    4085 Posts

    Re: Image Thumbnails DataObjectManager Link to this post

    It seems like you're not adding the thumbnail in the headings?

    array(
    'SlideTitle' => 'Title',
    'SlideURI' => 'URi',
    'SlideBody' => 'HTML',
    'SlideText1' => 'Text 1',
    'SlideText2' => 'Text 2',
    'SlideText3' => 'Text 3',
    'SlideText4' => 'Text 4'
    'Thumbnail' => 'Thumbnail'
    ),

    Also, as a matter of convention, models are named in the singular form. "Slides" should be "Slide"

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