Beispiel #1
0
 public function create($data)
 {
     $person = new Person($data->first_name, $data->last_name);
     if (isset($data->middle_name)) {
         $person->setMiddleName($data->middle_name);
     }
     if (isset($data->display_name)) {
         $person->setDisplayName($data->display_name);
     }
     $account = new Account($person);
     switch ($data->status) {
         case 'active':
             $account->setStatus(AccountInterface::STATUS_ACTIVE);
             break;
         case 'inactive':
             $account->setStatus(AccountInterface::STATUS_INACTIVE);
             break;
         default:
             throw new RuntimeException('Invalid account status provided.');
     }
     $this->entityManager->persist($person);
     $this->entityManager->persist($account);
     $this->entityManager->flush($account);
     return new AccountEntity($account);
 }
Beispiel #2
0
 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;
 }