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;
}
}