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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

shwing thumbnail summary_fields of model admin


Go to End


3 Posts   1215 Views

Avatar
Possibles

Community Member, 16 Posts

2 December 2011 at 5:47am

Edited: 03/12/2011 6:14am

Hello

I'm trying to get some thumbnails to show in the summary_fields of model admin.
I can get the ID of the photo but not the proper image.

I have seen example with as one Relationship. but not with has many :

Here is where I'm at :

Work.php

class Work extends DataObject
{
	static $db = array(
		'Title' => 'Varchar(255)',
        'Year' => 'Int',
		'MaterialsFr' => 'Text',
		'MaterialsEn' => 'Text',
		'Editions' => 'Text',
		'Description' => 'HTMLText',
		'URLSegment' => 'Varchar(255)',
		'MetaTitle' => 'Varchar(255)'
	);

	//Set our defaults
	static $defaults = array(	
		'Title' => 'New Work',
		'URLSegment' => 'new-Work'
	);
	
	static $has_many = array(
		'Photos' => 'Photo'
	);
	
	//Relate to the Artist pages
	static $belongs_many_many = array(
		'Artists' => 'ArtistPage'
	);
	
	//Fields to show in ModelAdmin table
	static $summary_fields = array(
		'Title' => 'Title',
		'Artists' => 'Artist',
		'Photos'=> 'Photo'
	);	

	//Add an SQL index for the URLSegment
	static $indexes = array(
		"URLSegment" => true
	);	

	//Fields to search in ModelAdmin
	static $searchable_fields = array (
		'Title',
		'URLSegment',
		'Description',
		'Artists.ID' => array(
			'title' => 'Artist'
		)
	);

	public function getCMSFields()
	{
		$f = parent::getCMSFields();
		$manager = new FileDataObjectManager(
			$this, // Controller
			'Photos', // Source name
			'Photo', // Source class
			'Attachment', // File name on DataObject
			array(
		'Title' => 'Title',
        'Year' => 'Year',
		'MaterialsFr' => 'Materials Français',
		'MaterialsEn' => 'Materials English',
		'Editions' => 'Editions',
		'Description' => 'Description',
		'URLSegment' => 'URL Segment',
		'MetaTitle' => 'Meta Title'
			), // Headings 
			'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
			// Filter clause
			// Sort clause
			// Join clause
		);
		$f->addFieldToTab("Root.Photos", $manager);
		//Artists
		$Artists = DataObject::get('ArtistPage');
		$f->addFieldToTab("Root.Artists", new CheckboxsetField('Artists', 'Artists', $Artists));
        return $f;
...

Photo.php

<?php

class Photo extends DataObject {

   static $db = array(
		'Description' => 'Text'
   );
   
   static $has_one = array(
      'Attachment' => 'Image',
      'Product' => 'Product',
      'Work' => 'Work'
   );
   public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextareaField('Description'),
			new FileIFrameField('Attachment')
		);
	}
}

?>

Thanks

Avatar
Possibles

Community Member, 16 Posts

3 December 2011 at 6:21am

Edited: 03/12/2011 6:24am

Hello

I'm trying to build a :

function getThumbnail()
{
 $image= this where I don't know what to put to get my image
return $image->CroppedImage(50,50); 
}

and add this

	static $summary_fields = array(
	'Thumbnail' => 'The Image'
	);

Could anyone enlight me please, I cant get the ID of photo but not the photo itself in my getThumbnai() function

Thanks

Avatar
Chris_Bryer

Community Member, 35 Posts

8 December 2011 at 9:35am

Edited: 08/12/2011 10:24am

you're close..
in photo.php you defined:

static $has_one = array(
     'Attachment' => 'Image',
     'Product' => 'Product',
     'Work' => 'Work'
); 

so your function should be

function getThumbnail()
{
    if($this->Attachment()->exists()) return $this->Attachment()->CroppedImage(50,50)->forTemplate();
}

-Chris