5121 Posts in 1527 Topics by 1119 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 896 Views |
-
Copying Data from DataObject to Member

28 August 2009 at 10:21am
I have UserApplication for that I want to move the Data to a Member Group once the User is approved, however I'm having trouble writing to the Member Class, I think its because I have Extra KEys and I need to match them up
Here is the DataObject Containing the Unapproved Member
class UserApplication extends DataObject {
static $db = array(
'FirstName' => 'Text',
'Surname' => 'Text',
'Email' => 'Text',
'CompanyName' => 'Text',
'CompanyType' => "Text",
'CompanyURL' => 'Text',
'HomePhone' => 'Text',
'Address' => 'Text',
'AddressLine2' => 'Text',
'City' => 'Text',
'Country' => 'Text',
'TaxIDNumber' => 'Text',
'Distributor' => 'Text',
'SalesRep' => 'Text',
'Notes' => 'Text',
'ApprovedMember' => 'Boolean',
'Password' => 'Text'
);
static $has_one = array(
'RegistrationPage' => 'RegistrationPage',
);
public function getCMSFields_forPopup()
{
$companyTypeList = array(
'Retail' => 'Retail',
'Online' => 'Online',
'Distributor' => 'Distributor',
'Press' => 'Press'
);
return new FieldSet (
new CheckBoxField('ApprovedMember', 'Approved Member'),
new TextField('FirstName', 'First Name'),
new TextField('Surname','Last Name'),
new EmailField('Email'),
new TextField('CompanyName','Company Name'),
new DropdownField('CompanyType','Company Type',$companyTypeList),
new TextField('CompanyURL','Company Website'),
new TextField('HomePhone','Company Phone'),
new TextField('Address','Address'),
new TextField('AddressLine2','Address Line 2'),
new TextField('City','City'),
new TextField('Country','Country'),
new TextField('TaxIDNumber','TaxIDNumber'),
new TextField('Distributor','Distributor'),
new TextField('SalesRep','Sales Rep'),
new TextareaField('Notes','Description'),
new ConfirmedPasswordField('Password')
);
}And here is the CMS function writing to the Member Class
class ApplicationDataObjectManager extends DataObjectManager
{
public $popupClass = "ApplicationDataObjectManager_Popup";
public $itemClass = "ApplicationDataObjectManager_Item";}
class ApplicationDataObjectManager_Popup extends DataObjectManager_Popup
{
function __construct($controller, $name, $fields, $validator, $readonly, $dataObject) {
parent::__construct($controller, $name, $fields, $validator, $readonly, $dataObject);
$this->Actions()->push(
new FormAction('ApproveUser','Approve User')
);
}function ApproveUser($data, $form, $request) {
// do stuff
$member = new Member();
$form->saveInto($member);
$groupID = 2;
switch ($member->CompanyType) {
case ("Retail"): $groupID = 3;
break;
case ("Distributor"): $groupID = 4;
break;
case ("Press"): $groupID = 5;
break;
case ("Online"): $groupID = 6;
break;
}
/*$member->write();*/
if($group = DataObject::get_one('Group', "ID = 2")) {
$member->Groups()->add($group);
return print_r($member);
//Director::redirectBack();
}
else{
return print_r($member->ID);
}}
}
class ApplicationDataObjectManager_Item extends DataObjectManager_Item
{}
-
Re: Copying Data from DataObject to Member

29 August 2009 at 2:16am
I see that you're extending the DataObjectManager module by Uncle Cheese. If you haven't done so already then you should ask your question inte DataObjectManager forum. Uncle Cheese is quick on the replies so I bet you'll get help there.
Also it would be really good to know what actually happens when you try to write to the member class.
| 896 Views | ||
|
Page:
1
|
Go to Top |


