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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   1358 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