Hello,
this really is a dumb question, but for some reason I cannot figure out how to get it to work.
My problem:
My domain provides several majordomo lists. Those have to be configured by mail. Now I want to write something to do it with a module: For each mailing list I want to build up a list of Members to keep track who is part of it. For adding members I want to have a dropdown list of Members to choose from. Sounds like a easy task for the DataObjectManager.
Unfortunatly I don't get it to work. Right now I have this:
class MailinglistePage extends Page {
static $db = array(
'Description'=>'Text',
'EMail'=>'Text'
);
static $has_one = array('Admin'=>'Member'
);
static $many_many = array('MailUser'=>'MailinglistenUser'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Mitglieder", new DataObjectManager(
$this,
'MailUser',
'MailinglistenUser',
array('User' => 'User'),
'getCMSFields_forPopup'
));
return $f;
}
}
I have added a new class to wrap the Member:
class MailinglistenUser extends DataObject
{
static $db = array (
);
static $has_one = array (
'User' => 'Member'
);
static $belongs_many_many = array(
'Mailingliste' => 'MailinglistePage'
);
public function getCMSFields_forPopup()
{
$members = DataObject::get("Member");
$memberList = array();
foreach($members as $member){
$memberList[$member->ID] = $member->getName();
}
return new FieldSet(
new DropdownField('User', 'User', $memberList)
);
}
}
With this, the cms looks good. Everything looks ready to add new Members to the Mailinglist. Unfortunatly it does not work. When I select a new member it is not inserted correctly and does not show up in the list. This is not surprising as the table MailinglistePage_MailUser stays empty. Only thing what happens is, that table MailinglistenUser each time gets a new entry with default UserID 0.
My question: Do I approach the problem in a sensible way?
If yes: What am I doing wrong?
If no: Any suggestions how to do it better?