public function doApprove() { $exist = Member::get()->filter(array('Email' => $this->Email))->first(); if ($exist) { return false; } $member = new Member(); $data = $this->toMap(); unset($data['ID']); unset($data['ClassName']); unset($data['UnapprovedMember']); $member->update($data); $member->write(); if ($this->MemberType === 'Organization') { $member->addToGroupByCode('organization'); $organization = new Organization(); $organization->AccountID = $member->ID; $organization->company_name = $this->OrganizationName; $organizationID = $organization->write(); $member->OrganizationID = $organizationID; $member->write(); } else { $member->addToGroupByCode('personal'); } $this->setField('Approved', true); $this->write(); return true; }
public function findOrCreateOrganization() { $organization = $this->owner->Organization(); if ($organization->ID) { return $organization; } $organization = new Organization(); $organization->write(); $organization->Members()->add($this->owner); return $organization; }