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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Image Thumbnails DataObjectManager


Reply

2 Posts   906 Views

Avatar
web2works

19 February 2011 at 12:45am Community Member, 50 Posts

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

Avatar
UncleCheese

19 February 2011 at 4:07am 4085 Posts

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"