/** * There can be only one primary entity * * @param Contact $entity */ public function updatePrimaryEntities(Contact $entity) { // update addresses $addresses = $entity->getAddresses(); $primaryAddress = $this->getPrimaryEntity($addresses); if ($primaryAddress) { $entity->setPrimaryAddress($primaryAddress); } elseif ($addresses->count() > 0) { $entity->setPrimaryAddress($addresses->first()); } // update emails $emails = $entity->getEmails(); $primaryEmail = $this->getPrimaryEntity($emails); if ($primaryEmail) { $entity->setPrimaryEmail($primaryEmail); } elseif ($emails->count() > 0) { $entity->setPrimaryEmail($emails->first()); } // update phones $phones = $entity->getPhones(); $primaryPhone = $this->getPrimaryEntity($phones); if ($primaryPhone) { $entity->setPrimaryPhone($primaryPhone); } elseif ($phones->count() > 0) { $entity->setPrimaryPhone($phones->first()); } }
public function testGetOpportunityEmail() { $salesFunnel = new SalesFunnel(); $email = new ContactEmail(); $email->setEmail('*****@*****.**'); $contact = new Contact(); $contact->addEmail($email); $contact->setPrimaryEmail($email); $opportunity = new Opportunity(); $opportunity->setContact($contact); $salesFunnel->setOpportunity($opportunity); $this->assertEquals('*****@*****.**', $salesFunnel->getEmail()); }
public function testGetEmail() { $contact = new Contact(); $this->assertNull($contact->getEmail()); $email = new ContactEmail('*****@*****.**'); $contact->addEmail($email); $this->assertNull($contact->getEmail()); $contact->setPrimaryEmail($email); $this->assertEquals('*****@*****.**', $contact->getEmail()); }
/** * @param Contact $entity * @return Contact */ protected function afterProcessEntity($entity) { // there can be only one primary entity $addresses = $entity->getAddresses(); $primaryAddress = $this->getPrimaryEntity($addresses); if ($primaryAddress) { /** @var ContactAddress $primaryAddress */ $entity->setPrimaryAddress($primaryAddress); } elseif ($addresses->count() > 0) { $entity->setPrimaryAddress($addresses->first()); } $emails = $entity->getEmails(); $primaryEmail = $this->getPrimaryEntity($emails); if ($primaryEmail) { /** @var ContactEmail $primaryEmail */ $entity->setPrimaryEmail($primaryEmail); } elseif ($emails->count() > 0) { $entity->setPrimaryEmail($emails->first()); } $phones = $entity->getPhones(); $primaryPhone = $this->getPrimaryEntity($phones); if ($primaryPhone) { /** @var ContactPhone $primaryPhone */ $entity->setPrimaryPhone($primaryPhone); } elseif ($phones->count() > 0) { $entity->setPrimaryPhone($phones->first()); } return $entity; }
public function testGetPrimaryEmail() { $contact = new Contact(); $this->assertNull($contact->getPrimaryEmail()); $email = new ContactEmail('*****@*****.**'); $contact->addEmail($email); $this->assertNull($contact->getPrimaryEmail()); $contact->setPrimaryEmail($email); $this->assertSame($email, $contact->getPrimaryEmail()); $email2 = new ContactEmail('*****@*****.**'); $contact->addEmail($email2); $contact->setPrimaryEmail($email2); $this->assertSame($email2, $contact->getPrimaryEmail()); $this->assertFalse($email->isPrimary()); }