/** * @param User $user * @param ContactInterface $contact */ protected function archiveEmail(User $user, ContactInterface $contact) { if ($contact->getMainEmail() !== $user->getEmail()) { if ($contact->getMainEmail()) { $hasEmail = false; /** @var Email $email */ foreach ($contact->getEmails() as $email) { if ($email->getEmail() === $contact->getMainEmail()) { $hasEmail = true; } } if (!$hasEmail) { $email = new Email(); $email->setEmail($contact->getMainEmail()); /** @var EmailType $emailType */ $emailType = $this->entityManager->getRepository(EmailType::class)->find(1); if ($emailType) { $email->setEmailType($emailType); $contact->addEmail($email); } } } $contact->setMainEmail($user->getEmail()); } }
/** * Returns the data needed for the account list-sidebar. * * @param ContactInterface $contact * * @return array */ protected function parseMainContact(ContactInterface $contact) { if ($contact) { $data = []; $data['id'] = $contact->getId(); $data['fullName'] = $contact->getFullName(); $data['phone'] = $contact->getMainPhone(); $data['email'] = $contact->getMainEmail(); return $data; } else { return null; } }
/** * Sets an order-address by data provided by contact-address. * If order-address does not exist a new one is created. * * @param Address $address * @param null|ContactInterface $contact * @param null|Account $account * @param null|OrderAddressInterface $orderAddress * * @return OrderAddressInterface */ public function getAndSetOrderAddressByContactAddress(Address $address, $contact = null, $account = null, $orderAddress = null) { if (!$orderAddress) { $orderAddress = new static::$orderAddressEntity(); } $orderAddress->setStreet($address->getStreet()); $orderAddress->setNumber($address->getNumber()); $orderAddress->setAddition($address->getAddition()); $orderAddress->setCity($address->getCity()); $orderAddress->setZip($address->getZip()); $orderAddress->setState($address->getState()); $orderAddress->setCountry($address->getCountry()->getName()); $orderAddress->setPostboxCity($address->getPostboxCity()); $orderAddress->setPostboxPostcode($address->getPostboxPostcode()); $orderAddress->setPostboxNumber($address->getPostboxNumber()); $orderAddress->setContactAddress($address); $orderAddress->setNote($address->getNote()); // add account data if ($account) { $orderAddress->setAccountName($account->getName()); $orderAddress->setUid($account->getUid()); } if ($contact) { if ($contact->getTitle()) { $orderAddress->setTitle($contact->getTitle()->getTitle()); } $orderAddress->setSalutation($contact->getSalutation()); $orderAddress->setFormOfAddress($contact->getFormOfAddress()); $orderAddress->setFirstName($contact->getFirstName()); $orderAddress->setLastName($contact->getLastName()); $orderAddress->setEmail($contact->getMainEmail()); $orderAddress->setPhone($contact->getMainPhone()); } return $orderAddress; }
/** * Gets email address of a contact * * @param ContactInterface $contact * @param bool $useFallback * * @return string|null */ public function getEmailAddressOfContact(ContactInterface $contact, $useFallback = true) { // take contacts main-email $contactMainEmail = $contact->getMainEmail(); if ($contact && $contactMainEmail) { return $contactMainEmail; } // fallback take contact's main-account main-email $account = $contact->getMainAccount(); if ($useFallback && $account) { return $this->getEmailAddressOfAccount($account); } return null; }