Hi,
I've got a client page that creates a security group on the fly as new client pages are created. What I've done for now is added in a default member just to check that I can add members to each group. Ideally what I want is to have a tab called members with a popup that I can easily add or delete members with.
I'm getting myself lost here though, how can I add a popup that automatically retreives the corresponding fields in the member database table? What is the best way of doing this? I've posted my code below to show how far I've got:
<?php
class ClientPage extends ClientGroup {
static $has_one = array(
'Photo' => 'Image',
);
static $has_many = array(
'members' => 'member'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Client picture', new ImageField('Photo'));
$validator = new RequiredFields('Page name');
return $fields;
}
static $has_written = false;
function onBeforeWrite(){
if($this->Title != "New ClientPage" && !DataObject::get_one('Group', "Title = '$this->Title'")){
if(!self::$has_written){ // hack to ensure new security group isn't written multiple times
$group = new Group();
$group->Title = $this->Title;
$group->write();
Permission::grant($group->ID, "EDIT_SITE");
$member = new Member();
$member->FirstName = "Test name"; // for testing purpose to check member is being created
$member->write();
$group->Members()->add($member);
}
self::$has_written = true;
}
parent::onBeforeWrite();
}
}
class ClientPage_Controller extends Page_Controller{
}
?>
Thanks