Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Copying Data from DataObject to Member

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1014 Views
  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Copying Data from DataObject to Member Link to this post

    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
    {

    }

  • MarcusDalgren
    Avatar
    Community Member
    288 Posts

    Re: Copying Data from DataObject to Member Link to this post

    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.

    1014 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.