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.

Form Questions /

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

Unable to view reference properties in ManyManyComplexTableField


Go to End
Reply


1101 Views

Avatar
delhi

Community Member, 1 Post

12 July 2009 at 9:23pm

I use the following model:
Object "Person" belong to many "Team"
and a Team can have many Person

In the admin module, I created a Team Holder and a Team below the TeamHolder Page.

When I click on the "Person" tab, I would like to show a table with the Photo, name, ... AND Category (which is another DataObject).
I saw in some posts that I could create a method into the Person class as a "Custom getter" like in this tutorial:
http://doc.silverstripe.org/doku.php?id=tablelistfield

But methods in the "Person" class returns nothing (I've got empty columns in the ComplexTable) (both for the Picture and for the text). Can anyone help me on that ?

class Team extends Page {

static $db = array(
'Annee' => 'Text'
);
static $has_one = array(
);

static $many_many = array(
'Persons' => 'Person',
'Categories' => 'Category'
);

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Annee' ) );

$MemberTablefield = new ManyManyComplexTableField(
$this,
'Persons',
'Person',
array(
'Thumbnail' => 'Image',
'Nom' => 'Nom',
'Prenom' => 'Prenom',
'DateNaissance' => 'Date de naissance',
'Email' => 'Email',
'Category' => 'Categorie'
),
'getCMSFields_forPopup'

);

$MemberTablefield->setAddTitle( 'Persons' );

$fields->addFieldToTab( 'Root.Content.Persons', $MemberTablefield );

$CategoryTablefield = new ManyManyComplexTableField(
$this,
'Categories',
'Category',
array(
'Poid' => 'Poid'
),
'getCMSFields_forPopup'
);
$CategoryTablefield->setAddTitle( 'Categories' );

$fields->addFieldToTab( 'Root.Content.Categories', $CategoryTablefield );

return $fields;

}

And

class Person extends DataObject {

static $icon = "themes/art-vert/images/galleryicon";

static $db = array(
'Nom' => 'Text',
'Prenom' => 'Text',
'DateNaissance' => 'Date',
'Email' => 'Text',

);

static $has_one = array (
'Category' => 'Category',
'Photo' => 'Image'
);

static $belongs_many_many = array(
'Teams' => 'Team',
);

static $allowed_children = array('');

function getCMSFields_forPopup() {
$fields = new FieldSet();
$fields->push( new TextField('Nom'));
$fields->push( new TextField('Prenom'));
$fields->push( new DateField('DateNaissance'));
$fields->push( new TextField('Email'));

$cats = DataObject::get('Category');
if(count($cats->Count())) {
$catOptions = array();
foreach($cats as $cat) {
$catOptions[$cat->ID] = $cat->Poid;
}
}

$fields->push(new DropdownField('CategoryID','Category', $catOptions));
$fields->push(new ImageField('Photo'));
return $fields;
}

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab( 'Root.Content.Images', new ImageField ('Photo'));
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Annee' ) );
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Prenom' ) );
$fields->addFieldToTab( 'Root.Content.Main', new DateField( 'DateNaissance' ) );
$fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Email' ) );
$cats = DataObject::get('Category');
if(count($cats->Count())) {
$catOptions = array();
foreach($cats as $cat) {
$catOptions[$cat->ID] = $cat->Poid;
}
}

/* $fields->addFieldToTab('Root.Content.Main', new DropdownField('CategoryID','Category', $catOptions)); */

return $fields;

}

public function getCategory() {
return "a Text";
}

function getThumbnail() {
$Image = $this->Photo();
if ( $Image ) {
return $Image->CMSThumbnail();
} else {
return null;
}
}