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; }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $user = $manager->getRepository('OroUserBundle:User')->findOneByUsername(self::$owner); $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); foreach ($this->contactsData as $contactData) { $contact = new Contact(); $contact->setOwner($user); $contact->setOrganization($organization); $contact->setFirstName($contactData['firstName']); $contact->setLastName($contactData['lastName']); $manager->persist($contact); } $manager->flush(); }
/** * {@inheritdoc} */ public function load(ObjectManager $manager) { $user = $manager->getRepository('OroUserBundle:User')->findOneByUsername('admin'); $organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); foreach ($this->contactsData as $contactData) { $contact = new Contact(); $contact->setOwner($user); $contact->setOrganization($organization); $contact->setFirstName($contactData['firstName']); $contact->setLastName($contactData['lastName']); $email = new ContactEmail(); $email->setEmail($contactData['email']); $email->setPrimary(true); $contact->addEmail($email); $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(); }
/** * {@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(); }
/** * 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; }
/** * @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); }