/** * @dataProvider processValidDataProvider * * @param bool $isDataChanged */ public function testProcessValidData($isDataChanged) { $appendedAccount = new Account(); $appendedAccount->setId(1); $removedAccount = new Account(); $removedAccount->setId(2); $this->entity->addAccount($removedAccount); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm->expects($this->once())->method('getData')->will($this->returnValue(array($appendedAccount))); $this->form->expects($this->at(3))->method('get')->with('appendAccounts')->will($this->returnValue($appendForm)); $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedAccount))); $this->form->expects($this->at(4))->method('get')->with('removeAccounts')->will($this->returnValue($removeForm)); if ($isDataChanged) { $this->manager->expects($this->once())->method('persist')->with($this->entity); } else { $this->manager->expects($this->exactly(2))->method('persist')->with($this->entity); } $this->manager->expects($this->once())->method('flush'); $this->configureUnitOfWork($isDataChanged); $this->assertTrue($this->handler->process($this->entity)); $actualAccounts = $this->entity->getAccounts()->toArray(); $this->assertCount(1, $actualAccounts); $this->assertEquals($appendedAccount, current($actualAccounts)); }
/** * @Route("/info/{id}", name="orocrm_contact_info", requirements={"id"="\d+"}) * * @Template * @AclAncestor("orocrm_contact_view") */ public function infoAction(Contact $contact) { if (!$this->getRequest()->get('_wid')) { return $this->redirect($this->get('router')->generate('orocrm_contact_view', ['id' => $contact->getId()])); } return array('entity' => $contact); }
/** * @dataProvider addressTypesUpdateDataProvider * * @param string $priority * @param ArrayCollection $remoteTypes * @param ArrayCollection $localTypes * @param ArrayCollection $contactTypes * @param array $expectedTypeNames */ public function testAddressTypesUpdate($priority, ArrayCollection $remoteTypes, ArrayCollection $localTypes, ArrayCollection $contactTypes, array $expectedTypeNames) { $channel = new Channel(); $channel->getSynchronizationSettingsReference()->offsetSet('syncPriority', $priority); $testCountry = new Country('US'); $contact = new Contact(); $contactAddress = new ContactAddress(); $contactAddress->setId(self::TEST_CONTACT_ADDRESS_ID); $contactAddress->setTypes($contactTypes); $contactAddress->setCountry($testCountry); $contact->addAddress($contactAddress); $phone = new ContactPhone(); $phone->setPhone('123-123-123'); $phone->setOwner($contact); $contact->addPhone($phone); $localCustomer = new Customer(); $localAddress = new Address(); $localAddress->setContactAddress($contactAddress); $localAddress->setTypes($localTypes); $localAddress->setCountry($testCountry); $localAddress->setPhone('123-123-123'); $localAddress->setContactPhone($phone); $localCustomer->addAddress($localAddress); $remoteCustomer = new Customer(); $remoteAddress = new Address(); $remoteAddress->setContactAddress($contactAddress); $remoteAddress->setTypes($remoteTypes); $remoteAddress->setCountry($testCountry); $remoteAddress->setContactPhone($phone); $remoteCustomer->addAddress($remoteAddress); $helper = $this->getHelper($channel); $helper->merge($remoteCustomer, $localCustomer, $contact); $this->assertCount(1, $contact->getAddresses()); $this->assertEquals($expectedTypeNames, $contactAddress->getTypeNames()); }
public function testProcessValidData() { $appendedContact = new Contact(); $appendedContact->setId(1); $removedContact = new Contact(); $removedContact->setId(2); $this->entity->addContact($removedContact); $this->request->setMethod('POST'); $this->form->expects($this->once())->method('setData')->with($this->entity); $this->form->expects($this->once())->method('submit')->with($this->request); $this->form->expects($this->once())->method('isValid')->will($this->returnValue(true)); $this->form->expects($this->once())->method('has')->with('contacts')->will($this->returnValue(true)); $contactsForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $appendForm->expects($this->once())->method('getData')->will($this->returnValue(array($appendedContact))); $contactsForm->expects($this->at(0))->method('get')->with('added')->will($this->returnValue($appendForm)); $removeForm = $this->getMockBuilder('Symfony\\Component\\Form\\Form')->disableOriginalConstructor()->getMock(); $removeForm->expects($this->once())->method('getData')->will($this->returnValue(array($removedContact))); $contactsForm->expects($this->at(1))->method('get')->with('removed')->will($this->returnValue($removeForm)); $this->form->expects($this->exactly(1))->method('get')->with('contacts')->will($this->returnValue($contactsForm)); $this->manager->expects($this->once())->method('persist')->with($this->entity); $this->manager->expects($this->once())->method('flush'); $this->assertTrue($this->handler->process($this->entity)); $actualContacts = $this->entity->getContacts()->toArray(); $this->assertCount(1, $actualContacts); $this->assertEquals($appendedContact, current($actualContacts)); }
/** * 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()); } }
/** * @return array */ public function fieldsDataProvider() { $email = new ContactEmail('mail@example'); $email->setPrimary(true); $contact = new Contact(); $contact->addEmail($email); return [[null, json_encode([]), $contact, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL, []], [[], json_encode([]), $contact, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL, []], [['email' => 'email'], json_encode([]), $contact, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL, ['mail@example']], [['email' => 'email'], json_encode(['columns' => [['name' => 'primaryEmail']]]), $contact, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL, []], [['email' => 'email'], json_encode(['columns' => [['name' => 'primaryEmail']]]), $contact, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL, []], [['email' => 'email'], json_encode(['columns' => [['name' => 'email']]]), $contact, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_PHONE, []], [['email' => 'email'], json_encode(['columns' => [['name' => 'email'], ['name' => 'phone']]]), $contact, ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL, ['mail@example']]]; }
/** * Gets a list of all phone numbers available for the given Contact object * * @param Contact $object * * @return array of [phone number, phone owner] */ public function getPhoneNumbers($object) { $result = []; foreach ($object->getPhones() as $phone) { $result[] = [$phone->getPhone(), $object]; } return $result; }
/** * @param Contact $contact * @param EntityManager $entityManager */ protected function setCreatedProperties(Contact $contact, EntityManager $entityManager) { if (!$contact->getCreatedAt()) { $contact->setCreatedAt(new \DateTime('now', new \DateTimeZone('UTC'))); } if (!$contact->getCreatedBy()) { $contact->setCreatedBy($this->getUser($entityManager)); } }
protected function createContact() { $contact = new Contact(); $contact->setFirstName('John'); $contact->setLastName('Doe'); $contact->setOrganization($this->organization); $this->em->persist($contact); $this->em->flush(); $this->setReference('default_contact', $contact); return $this; }
public function testRemoveContact() { $account = new Account(); $account->setId(1); $contact = new Contact(); $contact->setId(2); $account->addContact($contact); $this->assertCount(1, $account->getContacts()->toArray()); $account->removeContact($contact); $this->assertEmpty($account->getContacts()->toArray()); }
/** * @param Contact $contact * @param B2bCustomer $customer * @param User $user * * @return Opportunity */ protected function createOpportunity($contact, $customer, $user) { $opportunity = new Opportunity(); $dataChannel = $this->getReference('default_channel'); $opportunity->setName($contact->getFirstName() . ' ' . $contact->getLastName()); $opportunity->setContact($contact); $opportunity->setOwner($user); $opportunity->setOrganization($this->organization); $opportunity->setCustomer($customer); $opportunity->setDataChannel($dataChannel); return $opportunity; }
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 testPrePersistWithAlreadySetCreatedAtAndCreatedBy() { $entity = new Contact(); $createdAt = new \DateTime(); $createdBy = new User(); $entity->setCreatedAt($createdAt)->setCreatedBy($createdBy); $this->mockSecurityContext(); $em = $this->getEntityManagerMock(); $args = new LifecycleEventArgs($entity, $em); $this->contactListener->prePersist($args); $this->assertSame($createdAt, $entity->getCreatedAt()); $this->assertSame($createdBy, $entity->getCreatedBy()); }
/** * @param string $key * @param Contact $entity */ public function fillEntityData($key, $entity) { $userRepo = $this->templateManager->getEntityRepository('Oro\\Bundle\\UserBundle\\Entity\\User'); $accountRepo = $this->templateManager->getEntityRepository('OroCRM\\Bundle\\AccountBundle\\Entity\\Account'); $contactAddressRepo = $this->templateManager->getEntityRepository('OroCRM\\Bundle\\ContactBundle\\Entity\\ContactAddress'); switch ($key) { case 'Jerry Coleman': $primaryAddress = $contactAddressRepo->getEntity('Jerry Coleman'); $entity->setId(1)->setNamePrefix('Mr.')->setFirstName('Jerry')->setLastName('Coleman')->setNameSuffix('Jr.')->setBirthday(new \DateTime('1973-03-07'))->setGender('male')->setDescription('Sample Contact')->setJobTitle('Manager')->setFax('713-450-0721')->setSkype('crm-jerrycoleman')->setTwitter('crm-jerrycoleman')->setFacebook('crm-jerrycoleman')->setGooglePlus('https://plus.google.com/454646545646546')->setLinkedIn('http://www.linkedin.com/in/crm-jerrycoleman')->setSource($this->createContactSource('website'))->setMethod($this->createContactMethod('phone'))->setOwner($userRepo->getEntity('John Doo'))->setAssignedTo($userRepo->getEntity('John Doo'))->addEmail($this->createContactEmail('*****@*****.**', true))->addEmail($this->createContactEmail('*****@*****.**'))->addEmail($this->createContactEmail('*****@*****.**'))->addPhone($this->createContactPhone('585-255-1127', true))->addPhone($this->createContactPhone('914-412-0298'))->addPhone($this->createContactPhone('310-430-7876'))->addGroup($this->createContactGroup('Sales Group'))->addGroup($this->createContactGroup('Marketing Group'))->addAccount($accountRepo->getEntity('Coleman'))->addAccount($accountRepo->getEntity('Smith'))->addAddress($primaryAddress)->addAddress($this->createContactAddress('Jerry Coleman', 2))->addAddress($this->createContactAddress('Jerry Coleman', 3))->setPrimaryAddress($primaryAddress); return; case 'John Smith': $primaryAddress = $this->createContactAddress('John Smith', 1); $entity->setId(2)->setNamePrefix('Mr.')->setFirstName('John')->setLastName('Smith')->setNameSuffix('Jr.')->setBirthday(new \DateTime('1973-03-07'))->setGender('male')->setDescription('Sample Contact')->setJobTitle('Manager')->setFax('713-450-0721')->setSkype('crm-johnsmith')->setTwitter('crm-johnsmith')->setFacebook('crm-johnsmith')->setGooglePlus('https://plus.google.com/343535434535435')->setLinkedIn('http://www.linkedin.com/in/crm-johnsmith')->setSource($this->createContactSource('website'))->setMethod($this->createContactMethod('phone'))->setOwner($userRepo->getEntity('John Doo'))->setAssignedTo($userRepo->getEntity('John Doo'))->addEmail($this->createContactEmail('*****@*****.**', true))->addEmail($this->createContactEmail('*****@*****.**'))->addEmail($this->createContactEmail('*****@*****.**'))->addPhone($this->createContactPhone('585-255-1127', true))->addPhone($this->createContactPhone('914-412-0298'))->addPhone($this->createContactPhone('310-430-7876'))->addGroup($this->createContactGroup('Sales Group'))->addGroup($this->createContactGroup('Marketing Group'))->addAccount($accountRepo->getEntity('Smith'))->addAccount($accountRepo->getEntity('Coleman'))->addAddress($primaryAddress)->addAddress($this->createContactAddress('John Smith', 2))->addAddress($this->createContactAddress('John Smith', 3))->setPrimaryAddress($primaryAddress); return; } parent::fillEntityData($key, $entity); }
/** * @param Contact $contact * @param ContactAddress $address * @return array * @throws BadRequestHttpException */ protected function update(Contact $contact, ContactAddress $address) { $responseData = array('saved' => false, 'contact' => $contact); if ($this->getRequest()->getMethod() == 'GET' && !$address->getId()) { $address->setFirstName($contact->getFirstName()); $address->setLastName($contact->getLastName()); if (!$contact->getAddresses()->count()) { $address->setPrimary(true); } } if ($address->getOwner() && $address->getOwner()->getId() != $contact->getId()) { throw new BadRequestHttpException('Address must belong to contact'); } elseif (!$address->getOwner()) { $contact->addAddress($address); } // Update contact's modification date when an address is changed $contact->setUpdatedAt(new \DateTime('now', new \DateTimeZone('UTC'))); if ($this->get('orocrm_contact.form.handler.contact_address')->process($address)) { $this->getDoctrine()->getManager()->flush(); $responseData['entity'] = $address; $responseData['saved'] = true; } $responseData['form'] = $this->get('orocrm_contact.contact_address.form')->createView(); return $responseData; }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $adminUser = $manager->getRepository('OroUserBundle:User')->findOneByUsername('admin'); $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); foreach ($this->contactsData as $contactData) { $contact = new Contact(); $contact->setOwner($adminUser); $contact->setOrganization($organization); $contact->setFirstName($contactData['firstName']); $contact->setLastName($contactData['lastName']); $contact->setEmail($contactData['email']); $manager->persist($contact); $this->setReference($contactData['reference'], $contact); } $manager->flush(); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { /** @var Customer $customer */ $customer = $this->getReference('customer'); $email = new ContactEmail(); $email->setPrimary(true); $email->setEmail($customer->getEmail()); $contact = new Contact(); $contact->setFirstName($customer->getFirstName()); $contact->setLastName($customer->getLastName()); $contact->setGender($customer->getGender()); $contact->addEmail($email); /** @var UserManager $userManager */ $userManager = $this->container->get('oro_user.manager'); $admin = $userManager->loadUserByUsername('admin'); $this->setReference('admin_user', $admin); $contact->setOwner($admin); $contact->setOrganization($manager->getRepository('OroOrganizationBundle:Organization')->getFirst()); $customer->setContact($contact); $this->setReference('contact', $contact); $manager->persist($contact); $manager->flush(); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { /** @var UserManager $userManager */ $userManager = $this->container->get('oro_user.manager'); $role = $manager->getRepository('OroUserBundle:Role')->findOneByRole('ROLE_ADMINISTRATOR'); $group = $manager->getRepository('OroUserBundle:Group')->findOneByName('Administrators'); $unit = $manager->getRepository('OroOrganizationBundle:BusinessUnit')->findOneByName('Main'); $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); $user = new User(); $user->setUsername('somename'); $user->addGroup($group); $user->addRole($role); $user->addBusinessUnit($unit); $user->setFirstname('Test FirstName'); $user->setLastname('Test LastName'); $user->setEmail('*****@*****.**'); $user->setOwner($unit); $user->addGroup($group); $user->setPlainPassword('test password'); $user->setSalt(md5(mt_rand(1, 222))); $user->setOrganization($organization); $userManager->updateUser($user); $this->setReference('not_associated_entities_owner', $user); $account = new Account(); $account->setName('Some Test Name'); $account->setOwner($user); $account->setOrganization($organization); $manager->persist($account); $this->setReference('not_associated_account', $account); $contact = new Contact(); $contact->setFirstName('Test First Name'); $contact->setLastName('Test Last Name'); $contact->setOwner($user); $contact->setOrganization($organization); $manager->persist($contact); $this->setReference('not_associated_contact', $contact); $manager->flush(); }
/** * Filtered phone by phone number from contact and return entity or null * * @param Contact $contact * @param ContactPhone $contactPhone * * @return ContactPhone|null */ protected function getContactPhoneFromContact(Contact $contact, ContactPhone $contactPhone) { foreach ($contact->getPhones() as $phone) { if ($phone->getPhone() === $contactPhone->getPhone()) { $hash = spl_object_hash($phone); if (array_key_exists($hash, $this->processedEntities)) { // skip if contact phone used for previously imported phone continue; } $this->processedEntities[$hash] = $phone; return $phone; } } return null; }
/** * @param Contact $defaultContact * * @return Account */ public function setDefaultContact($defaultContact) { if ($this->defaultContact === $defaultContact) { return $this; } /** * As resolving of $this->defaultContact->getDefaultInAccounts() lazy collection will * overwrite $this->defaultContact to value from db, make sure the collection is resolved */ if ($this->defaultContact) { $this->defaultContact->getDefaultInAccounts()->toArray(); } $originalContact = $this->defaultContact; $this->defaultContact = $defaultContact; if ($defaultContact) { $defaultContact->addDefaultInAccount($this); } if ($originalContact) { $originalContact->removeDefaultInAccount($this); } if ($defaultContact && !$this->contacts->contains($defaultContact)) { $this->addContact($defaultContact); } return $this; }
/** * @param $randomTemplate * @param User $owner * @param Contact $contact * @param EmailOrigin $origin * * @return EmailUser */ protected function addEmailUser($randomTemplate, $owner, $contact, $origin) { $emailUser = $this->emailEntityBuilder->emailUser($this->templates[$randomTemplate]['Subject'], $owner->getEmail(), $contact->getPrimaryEmail()->getEmail(), new \DateTime('now'), new \DateTime('now'), new \DateTime('now')); $this->setSecurityContext($owner); $emailUser->setFolder($origin->getFolder(FolderType::SENT)); $emailUser->setOwner($owner); $emailUser->setOrganization($owner->getOrganization()); $emailBody = $this->emailEntityBuilder->body("Hi,\n" . $this->templates[$randomTemplate]['Text'], false, true); $emailUser->getEmail()->setEmailBody($emailBody); $emailUser->getEmail()->setMessageId(sprintf('<id.%s@%s', uniqid(), '@bap.migration.generated>')); return $emailUser; }
/** * @param Contact $entity */ protected function processSecurityRelations(Contact $entity) { // update owner $owner = $entity->getOwner(); if ($owner) { $owner = $this->findExistingEntity($owner); } if (!$owner) { $token = $this->securityContext->getToken(); if ($token) { $owner = $token->getUser(); } } $entity->setOwner($owner); // update organization $organization = $entity->getOrganization(); if ($organization) { $organization = $this->findExistingEntity($organization); } if (!$organization) { $token = $this->securityContext->getToken(); if ($token && $token instanceof OrganizationContextTokenInterface) { $organization = $token->getOrganizationContext(); } } $entity->setOrganization($organization); }
/** * Get ContactPhone from contact by ContactPhone * * @param Contact $contact * @param ContactPhone $contactPhone * * @return mixed */ protected function getContactPhoneFromContact(Contact $contact, ContactPhone $contactPhone) { $filtered = $contact->getPhones()->filter(function (ContactPhone $phone) use($contactPhone) { return $phone && $phone->getId() === $contactPhone->getId(); }); return $filtered->first(); }
/** * @param Contact $contact * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function fixRequest($contact) { $formAlias = $this->getFormAlias(); $contactData = $this->getRequest()->request->get($formAlias); if (array_key_exists('accounts', $contactData)) { $accounts = $contactData['accounts']; $appendAccounts = array_key_exists('appendAccounts', $contactData) ? $contactData['appendAccounts'] : array(); $removeAccounts = array_key_exists('removeAccounts', $contactData) ? $contactData['removeAccounts'] : array(); if ($contact->getId()) { foreach ($contact->getAccounts() as $account) { if (!in_array($account->getId(), $accounts)) { $removeAccounts[] = $account->getId(); } } } $contactData['appendAccounts'] = array_merge($appendAccounts, $accounts); $contactData['removeAccounts'] = $removeAccounts; unset($contactData['accounts']); $this->getRequest()->request->set($formAlias, $contactData); } // @todo: just a temporary workaround until new API is implemented // - convert country name to country code (as result we accept both the code and the name) // also it will be good to accept ISO3 code in future, need to be discussed with product owners // - convert region name to region code (as result we accept the combined code, code and name) // - move region name to region_text field for unknown region if (array_key_exists('addresses', $contactData)) { foreach ($contactData['addresses'] as &$address) { if (!empty($address['country'])) { $countryCode = $this->getCountryCodeByName($address['country']); if (!empty($countryCode)) { $address['country'] = $countryCode; } } if (!empty($address['region']) && !$this->isRegionCombinedCodeByCode($address['region'])) { if (!empty($address['country'])) { $regionId = $this->getRegionCombinedCodeByCode($address['country'], $address['region']); if (!empty($regionId)) { $address['region'] = $regionId; } else { $regionId = $this->getRegionCombinedCodeByName($address['country'], $address['region']); if (!empty($regionId)) { $address['region'] = $regionId; } else { $address['region_text'] = $address['region']; unset($address['region']); } } } else { $address['region_text'] = $address['region']; unset($address['region']); } } } $this->getRequest()->request->set($formAlias, $contactData); } }
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()); }
/** * Remove contacts from account * * @param Contact $contact * @param Account[] $accounts */ protected function removeAccounts(Contact $contact, array $accounts) { foreach ($accounts as $account) { $contact->removeAccount($account); } }
/** * @param Contact $contactEntity * @param EntityManager $em */ protected function scheduleSync(Contact $contactEntity, EntityManager $em) { if ($contactEntity->getId() && !isset($this->processIds[$contactEntity->getId()])) { $magentoCustomer = $em->getRepository('OroCRMMagentoBundle:Customer')->findOneBy(['contact' => $contactEntity]); if ($this->isTwoWaySyncEnabled($magentoCustomer)) { $this->processIds[$contactEntity->getId()] = $magentoCustomer; } } }
/** * @param Contact $contact * @return array */ protected function createContactView(Contact $contact) { return ['id' => $contact->getId(), 'url' => $this->router->generate('orocrm_contact_view', array('id' => $contact->getId())), 'fullName' => $this->entityNameResolver->getName($contact), 'avatar' => null, 'permissions' => array('view' => $this->securityFacade->isGranted('VIEW', $contact))]; }
/** * Create a Contact * * @param array $data * @param int $iteration * @return Contact */ private function createContact(array $data, $iteration = 0) { $contact = new Contact(); $contact->setFirstName($data['GivenName']); $lastName = $data['Surname']; if ($iteration) { $lastName .= '_' . $iteration; } $contact->setLastName($lastName); $contact->setNamePrefix($data['Title']); $phone = new ContactPhone($data['TelephoneNumber']); $phone->setPrimary(true); $contact->addPhone($phone); $email = new ContactEmail($data['EmailAddress']); $email->setPrimary(true); $contact->addEmail($email); $date = \DateTime::createFromFormat('m/d/Y', $data['Birthday']); $contact->setBirthday($date); /** @var ContactAddress $address */ $address = new ContactAddress(); $address->setCity($data['City']); $address->setStreet($data['StreetAddress']); $address->setPostalCode($data['ZipCode']); $address->setFirstName($data['GivenName']); $address->setLastName($data['Surname']); $address->setPrimary(true); $isoCode = $data['Country']; $country = array_filter($this->countries, function (Country $a) use($isoCode) { return $a->getIso2Code() == $isoCode; }); $country = array_values($country); /** @var Country $country */ $country = $country[0]; $idRegion = $data['State']; /** @var Collection $regions */ $regions = $country->getRegions(); $region = $regions->filter(function (Region $a) use($idRegion) { return $a->getCode() == $idRegion; }); $address->setCountry($country); if (!$region->isEmpty()) { $address->setRegion($region->first()); } $contact->addAddress($address); return $contact; }
/** * @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; }