Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * @param string $name
  * @param int    $number
  *
  * @return ContactAddress
  *
  * @throws \LogicException
  */
 protected function createContactAddress($name, $number)
 {
     $countryRepo = $this->templateManager->getEntityRepository('Oro\\Bundle\\AddressBundle\\Entity\\Country');
     $regionRepo = $this->templateManager->getEntityRepository('Oro\\Bundle\\AddressBundle\\Entity\\Region');
     $entity = new ContactAddress();
     switch ($name) {
         case 'Jerry Coleman':
             $entity->setFirstName('Jerry')->setLastName('Coleman');
             break;
         case 'John Smith':
             $entity->setFirstName('John')->setLastName('Smith');
             break;
         default:
             throw new \LogicException(sprintf('Undefined contact address. Name: %s. Number: %d.', $name, $number));
     }
     switch ($number) {
         case 1:
             $entity->setCity('Rochester')->setStreet('1215 Caldwell Road')->setPostalCode('14608')->setRegion($regionRepo->getEntity('NY'))->setCountry($countryRepo->getEntity('US'));
             break;
         case 2:
             $entity->setCity('New York')->setStreet('4677 Pallet Street')->setPostalCode('10011')->setRegion($regionRepo->getEntity('NY'))->setCountry($countryRepo->getEntity('US'));
             break;
         case 3:
             $entity->setCity('New York')->setStreet('52 Jarvisville Road')->setPostalCode('11590')->setRegion($regionRepo->getEntity('NY'))->setCountry($countryRepo->getEntity('US'));
             break;
         default:
             throw new \LogicException(sprintf('Undefined contact address. Name: %s. Number: %d.', $name, $number));
     }
     return $entity;
 }