public function createFromArray(AccountInterface $account, array $data) { $isPrimary = $account->getEmailAddresses()->count() === 0; $validationCode = $this->generateValidationCode(); $emailAddress = new EmailEntity($account, $data['emailAddress']); $emailAddress->setIsPrimary($isPrimary); $emailAddress->setValidationCode($validationCode); $this->entityManager->persist($emailAddress); $this->entityManager->flush($emailAddress); }
public function inviteAccount($data) { // Lookup the e-mail address: $repository = $this->entityManager->getRepository(Email::class); $accountEmail = $repository->findOneBy(['address' => $data['email']]); if ($accountEmail !== null) { return $accountEmail->getAccount(); } $person = new Person($data['first_name'], $data['last_name']); $person->setMiddleName($data['middle_name']); $emailAddress = new EmailAddress($person, EmailAddress::TYPE_WORK, $data['email']); $account = new AccountEntity($person); $account->setStatus(AccountEntity::STATUS_INVITED); $accountEmail = new Email($account, $data['email']); $accountEmail->setValidationCode(Rand::getString(32, range('a', 'z'))); $account->getEmailAddresses()->add($accountEmail); $this->entityManager->persist($person); $this->entityManager->persist($emailAddress); $this->entityManager->persist($account); $this->entityManager->flush(); return $account; }