Using an attribute of a has_one relation as heading in Dataobjectmanager
Hello all,
Once again I find myself using the DataObjectManager to build the necessary user-friendliness into my site and in general I am enjoying the experience. However, as usual, I seem to have run into this one small issue that I cannot seem to get my head around.
Here's hoping one of you can help me out.
The project I am currently working is fairly straightforward: a few pages explaining the goal and activities of the association that is our customer; and a couple of pages listing members and such for logged-in users.
The page that is giving me trouble is a page listing the members of the direction. The DirectionPage has a has_many relation with the dataobject DirectionMember. DirectionMember in turn has a has_one relation to the DataObject Member.
In the CMS the DirectionPage contains a DataObjectManager that shows all linked DirectionMembers, defined like this:
$manager = new DataObjectManager(
$this, // Controller
'DirectionMembers', // Source name
'DirectionMember', // Source class
array(
'Function' => 'Functie',
'EmailAddress' => 'Emailadres'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
And this is the definition of DirectionMember:
class DirectionMember extends DataObject
{
static $db = array (
'EmailAddress' => 'Text',
'Function' => 'Text'
);
static $has_one = array (
'Member' => 'Member',
'Parent' => 'DirectionPage'
);
public function getCMSFields_forPopup()
{
$Group = DataObject::get_one("Group", "Title = 'WebsiteUsers'", "", "");
$Members = $Group->Members(
$limit = '',
$offset = '',
'',
$sort = 'Member.Email',
$join = ''
);
$dropdown = new DropdownField('MemberID','Lid',$Members->toDropdownMap('ID', 'Title', 'Selecteer lid'),$this->Member);
return new FieldSet(
new TextField('EmailAddress', 'Emailadres'),
new TextField('Function', 'Functie'),
$dropdown
);
}
}
Now, the above code works flawlessly... except that I would really like to show the DirectionMember's name as well as their function and email address. However, this name is stored inside the has_one field Member.
I had hoped that I could do something like this:
$manager = new DataObjectManager(
$this, // Controller
'DirectionMembers', // Source name
'DirectionMember', // Source class
array(
'Member->Name' => 'Naam',
'Function' => 'Functie',
'EmailAddress' => 'Emailadres'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
However, no such luck. Am I missing anything obvious, or is getting this name more involved?
Looking forward to your replies,
Bart M.