Exemplo n.º 1
0
 /**
  * @param Contact $entity
  */
 public function updateScalars(Contact $entity)
 {
     // update gender
     $gender = $entity->getGender();
     if (null !== $gender) {
         $gender = strtolower($gender);
         switch ($gender) {
             case 'm':
                 $gender = 'male';
                 break;
             case 'f':
                 $gender = 'female';
                 break;
         }
         $entity->setGender($gender);
     }
 }
Exemplo n.º 2
0
 /**
  * {@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();
 }
Exemplo n.º 3
0
 /**
  * Create a Contact
  *
  * @param  array   $data
  * @return Contact
  */
 private function createContact(array $data)
 {
     $contact = new Contact();
     $contact->setFirstName($data['GivenName']);
     $contact->setLastName($data['Surname']);
     $contact->setNamePrefix($data['Title']);
     $contact->setGender($data['Gender']);
     $contact->setOrganization($this->organization);
     $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->setLabel('Primary Address');
     $address->setCity($data['City']);
     $address->setStreet($data['StreetAddress']);
     $address->setPostalCode($data['ZipCode']);
     $address->setFirstName($data['GivenName']);
     $address->setLastName($data['Surname']);
     $address->setPrimary(true);
     $address->setOwner($contact);
     $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;
 }