7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Thumbnail for many_many relationship in the list of fields on the back end
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 551 Views |
-
Thumbnail for many_many relationship in the list of fields on the back end

26 September 2010 at 9:48am
Hi UncleCheeze!
There's something I've been trying to do, it doesn't sound too complicated, and it would be a really nice feature for my client :
I'm programming a web site for an art gallery. The have «paintings» related to «exhibitions». This is a many-many relationship. Paintings have an image linked to them (has_one), as well as a Title, the creator's name, the year of creation, etc.
In the CMS, when it's time to link paintings to exhibitions, it works well, but it's hard to find out which painting is which because there are many « untitled » paintings. It would be awesome to have a thumbnail that shows the image related to a painting in a column.
Tell me if it's not clear!
thanks,
JP
-
Re: Thumbnail for many_many relationship in the list of fields on the back end

26 September 2010 at 10:09am Last edited: 26 September 2010 10:10am
Can u show your php code i think i can help
-
Re: Thumbnail for many_many relationship in the list of fields on the back end

26 September 2010 at 10:20am
I'm not sure the code will help... The feature I request could be used on any ManyMany relationship that have an image linked to the other side of the relation.
But, in any cases, I'll send an excerpt of the code:
class ExpoPage extends Page {
public static $db = array(
);public static $has_one = array(
);public static $has_many = array(
);
static $many_many = array(
'ExhibitingWorks' => 'ArtistWork'
);function getCMSFields () {
$fields = parent::getCMSFields();$x = new ManyManyDataObjectManager(
$this,
'ExhibitingWorks',
'ArtistWork',
array (
'Title' => "Titre de l'oeuvre",
"CONCAT(FirstName,' ', LastName)"=>'Artiste',
"Year" => 'Année'
),
null,
null, 'Title', "LEFT JOIN ArtistPage ON (ArtistWork.CreatorID=ArtistPage.ID)"
);
$x->setPermissions (Array()); //WE DON'T WANT THEM TO EDIT PAINTINGS, WE WANT THEM TO USE THE CHECKBOX TO CHOOSE WHICH PAINTINGS ARE EXHIBITED AND WHICH AREN'T
$x->setPageSize (8999);
$x->setTitle ("Liste des oeuvres");
$fields->addFieldToTab("Root.Content.ListeDesOeuvres", $x);return $fields;
}
}class ArtistWork extends DataObject {
public static $db = array (
'Title' => 'Text',
'Medium' => 'Text',
'Year' => 'Int',
'Height' => 'Float', /* All dimensions are in CM, converted to inches when english */
'Width' => 'Float', /* All dimensions are in CM, converted to inches when english */
'Depth' => 'Float' /* All dimensions are in CM, converted to inches when english */
);public static $has_one = array(
'Creator' => 'ArtistPage', //from a has_many relationship on ArtistPage
'Image' => 'Image'
);
static $belongs_many_many = array (
'ExpoPages' => 'ExpoPage'
);
function getCMSFields_forPopup () {
$fields = new FieldSet();
$fields->push (new TextField ('Title', 'Titre'));
$fields->push (new TextField ('Medium', 'Médium'));
$fields->push (new TextField ('Year', 'Année (ex: 2010)'));
$fields->push (new TextField ('Height', 'Hauteur (en CM sans le CM, ex: 230)'));
$fields->push (new TextField ('Width', 'Largeur'));
$fields->push (new TextField ('Depth', 'Profondeur'));$uploader = new ImageUploadField ('Image', "Image de l'oeuvre");
$uploader->uploadFolder = "oeuvres";
$fields->push ($uploader);
return $fields;
}
} -
Re: Thumbnail for many_many relationship in the list of fields on the back end

26 September 2010 at 10:24am
try this
$x = new ManyManyDataObjectManager(
$this,
'ExhibitingWorks',
'ArtistWork',
array (
'Title' => "Titre de l'oeuvre",
"CONCAT(FirstName,' ', LastName)"=>'Artiste',
"Year" => 'Année' ,
"Image" => 'Image translation'
), -
Re: Thumbnail for many_many relationship in the list of fields on the back end

26 September 2010 at 10:29am
Hmmm...
I tried it and it gives the SQL Error : « Unknown column 'Image' in 'field list' »
I tried with ImageID instead of Image, and it shows the ID of each images, in the column titled « Image translation », like this code's behavior has been expected!
Thanks anyway!
-
Re: Thumbnail for many_many relationship in the list of fields on the back end

26 September 2010 at 2:28pm
Just use a custom getter..
public function getDOMThumbnail() {
if($i = $this->YourImageField()) {
return $i->CroppedImage(50,50);
}
}And in your headings array, you just need
'DOMThumbnail' => 'Thumbnail'
---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com
| 551 Views | ||
|
Page:
1
|
Go to Top |


