Hi,
I am building the website of our club.
We have members, events and participants and many other dataobjects.
Each member can participate to many events. Each event have many participants.
MEMBERS has a one to many relationship with PARTICIPANTS which has a many to one relationship with EVENTS.
I manage the members, events and participants using modeladmin. Each of them has a separate entry in the left admin menu.
I succeeded to add a button to the Participants Item "page". This button allows me to send an email to confirm receipt of a payment or receipt of a subscription form a member for a particular event.
The button does only appear when I edit a participant from the participant list with all participants to all events.
I would like to have the same button appearing when I access the participant from either the events or the members. You know, you select a member, click on the tab with participants (which shows all events to which the member subscribed) and then edit one of the "participants" item on that list.
How can I do this?
If needed I will add some sources to my question this evening..
Thx for any help.
class BPF_Participants extends DataObject {
...
private static $has_one = array('BPF_Member' => 'BPF_Member', 'BPF_Event' => 'BPF_Event');
...
public function getCMSActions() {
$actions = parent::getCMSActions();
$BPF_Mail_Parms = BPF_Mails::get()->filter(array('Ma_TemplateName' => "ParticipantPaid"))->limit(1);
foreach ($BPF_Mail_Parms as $row) {
$state = $row->Ma_State;
}
if ($state == 'PROD') {
$MailAction = new FormAction ('doMailParticipantPaid', 'Confirm payment by email');
}
else {
$MailAction = new FormAction ('doMailParticipantPaid', 'Confirm payment by email (TEST)');
}
$MailAction->addExtraClass('ss-ui-action-constructive');
$actions->push($MailAction);
$state = " ";
$BPF_Mail_Parms = BPF_Mails::get()->filter(array('Ma_TemplateName' => "ParticipantOption"))->limit(1);
foreach ($BPF_Mail_Parms as $row) {
$state = $row->Ma_State;
}
if ($state == 'PROD') {
$MailAction = new FormAction ('doMailParticipantOption', 'Confirm option by email');
}
else {
$MailAction = new FormAction ('doMailParticipantOption', 'Confirm option by email (TEST)');
}
$MailAction->addExtraClass('ss-ui-action-constructive');
$actions->push($MailAction);
return $actions;
}
}
class BPF_ParticipantsDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest {
private static $allowed_actions = array (
'edit',
'view',
'ItemEditForm'
);
public function ItemEditForm() {
$form = parent::ItemEditForm();
$formActions = $form->Actions();
if ($actions = $this->record->getCMSActions())
foreach ($actions as $action)
$formActions->push($action);
return $form;
}
// ------------------------------------------------------------------------------------------
// Mailing routines
// ------------------------------------------------------------------------------------------
public function doMailParticipantPaid($data, $form) {
... do stuff here
}
class Participants_Admin extends ModelAdmin {
private static $managed_models = array('BPF_Participants'
);
private static $url_segment = 'Participants'; // Linked as /admin/BPF/
private static $menu_title = 'Participants';
public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id, $fields);
$listField = $form->Fields()->fieldByName($this->modelClass);
if ($gridField = $listField->getConfig()->getComponentByType('GridFieldDetailForm'))
$gridField->setItemRequestClass('BPF_ParticipantsDetailForm_ItemRequest');
return $form;
}
}
class BPF_Member extends Member implements PermissionProvider {
...
private static $has_many = array('EventsBooked' => 'BPF_Participants');
...
}
class BPF_Event extends DataObject {
private static $has_many = array('BPF_EventSponsor' => 'BPF_EventSponsor',
'EventPage' => 'EventPage',
'BPF_Participants' => 'BPF_Participants'
);
...
}
The following doesn't give me the desired button, when editing the participants item for a particular member.
class Member_Admin extends ModelAdmin {
private static $managed_models = array('BPF_Member'
);
private static $url_segment = 'Members'; // Linked as /admin/BPF/
private static $menu_title = 'Members';
public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id, $fields);
$listField = $form->Fields()->fieldByName($this->modelClass);
if ($gridField = $listField->getConfig()->getComponentByType('GridFieldDetailForm'))
$gridField->setItemRequestClass('BPF_ParticipantsDetailForm_ItemRequest');
return $form;
}
}