Add a new phone to the given contact and persist it with the given object manager.

@param $contact
@param array $phoneData

@throws EntityNotFoundException
@throws EntityIdAlreadySetException

@return bool True if there was no error, otherwise false
160685
protected function addPhone($contact, $phoneData)
    {
        $success = true;

        $phoneType = $this->em->getRepository(
            self::$phoneTypeEntityName
        )->find($phoneData['phoneType']['id']);

        if (isset($phoneData['id'])) {
            throw new EntityIdAlreadySetException(self::$phoneEntityName, $phoneData['id']);
        } elseif (!$phoneType) {
            throw new EntityNotFoundException(self::$phoneTypeEntityName, $phoneData['phoneType']['id']);
        } else {
            $phone = new Phone();
            $phone->setPhone($phoneData['phone']);
            $phone->setPhoneType($phoneType);
            $this->em->persist($phone);
            $contact->addPhone($phone);
        }

        return $success;
    }
257549
public function deleteContactsAction($accountId, $contactId)
    {
        try {
            // Check if relation exists.
            /** @var AccountContactEntity $accountContact */
            $accountContact = $this->getDoctrine()
                ->getRepository(self::$accountContactEntityName)
                ->findByForeignIds($accountId, $contactId);

            if (!$accountContact) {
                throw new EntityNotFoundException('AccountContact', $accountId . $contactId);
            }
            $id = $accountContact->getId();

            $account = $accountContact->getAccount();

            // Remove main contact when relation with main was removed.
            if ($account->getMainContact() && strval($account->getMainContact()->getId()) === $contactId) {
                $account->setMainContact(null);
            }

            // Remove accountContact.
            $em = $this->getDoctrine()->getManager();
            $em->remove($accountContact);
            $em->flush();

            $view = $this->view($id, 200);
        } catch (EntityNotFoundException $enfe) {
            $view = $this->view($enfe->toArray(), 404);
        }

        return $this->handleView($view);
    }
1162309
public function save(ServiceInterface $service, Contact $contact = null)
    {
        if (!$this->validate()) {
            throw new NotValidException('Unable to validate contact note');
        }

        if ($contact === null) {
            throw new Exception('$contact must be instance of Contact');
        }

        $newContact = $service->saveNote($this, $contact);
        $contact->setData($newContact->toArray(), false);
        return $this->reload(
            end($newContact->notes)
        );
    }
836915
public function setMainAccount(Contact $contact, $data)
    {
        // set account relation
        if (isset($data['account']) &&
            isset($data['account']['id']) &&
            'null' != $data['account']['id']
        ) {
            $accountId = $data['account']['id'];

            $account = $this->accountRepository->findAccountById($accountId);

            if (!$account) {
                throw new EntityNotFoundException($this->accountRepository->getClassName(), $accountId);
            }

            // get position
            $position = null;
            if (isset($data['position'])) {
                $position = $this->getPosition($data['position']);
            }

            // check if relation between account and contact already exists
            $mainAccountContact = $this->getMainAccountContact($contact);
            $accountContact = $this->getAccounContact($account, $contact);

            // remove previous main accountContact
            if ($mainAccountContact && $mainAccountContact !== $accountContact) {
                // if this contact is the main-Contact - set mainContact to null
                if ($mainAccountContact->getAccount()->getMainContact() === $contact) {
                    $mainAccountContact->getAccount()->setMainContact(null);
                }
                $this->em->remove($mainAccountContact);
            }

            // if account-contact relation existed set params
            if ($accountContact) {
                $accountContact->setMain(true);
                $accountContact->setPosition($position);
            } else {
                // else create new one
                $this->createMainAccountContact($contact, $account, $position);
            }
        } else {
            // if a main account exists - remove it
            if ($accountContact = $this->getMainAccountContact($contact)) {
                // if this contact is the main-Contact - set mainContact to null
                if ($accountContact->getAccount()->getMainContact() === $contact) {
                    $accountContact->getAccount()->setMainContact(null);
                }

                $this->em->remove($accountContact);
            }
        }
    }
1238196
public function setContact($contact)
    {
        if ($contact instanceof Contact) {
            $contact = $contact->getId();
        }

        $this->contact = $contact;

        return $this;
    }
1290388
public function addCallButton($title, $phone)
    {
        $this->add(new Button(Button::TYPE_CALL, $title, $phone));

        return $this;
    }
155801
public function processCategories($contact, $categoryIds)
    {
        $contact->getCategories()->clear();

        if (!$categoryIds) {
            return true;
        }

        foreach ($categoryIds as $categoryId) {
            $category = $this->em->getRepository(self::$categoryEntityName)->find($categoryId);

            if (!$category) {
                throw new EntityNotFoundException(self::$categoryEntityName, $categoryId);
            }

            $contact->addCategory($category);
        }

        return true;
    }
334107
protected function addContactRelation(array $data, $dataKey, $addCallback)
    {
        $contact = null;
        if (array_key_exists($dataKey, $data) && is_array($data[$dataKey]) && array_key_exists('id', $data[$dataKey])) {
            /** @var Contact $contact */
            $contactId = $data[$dataKey]['id'];
            $contact = $this->em->getRepository(static::$contactEntityName)->find($contactId);
            if (!$contact) {
                // TODO: custom exception dependencyNotFound
                throw new \Exception(sprintf("Entity '%s' with id %s not found", static::$contactEntityName, $contactId));
            }
            $addCallback($contact);
        }
        return $contact;
    }
1241729
protected function populate($entity, array $entityData)
    {
        foreach ($entityData as $key => $value) {
            if ($this->propertyAccessor->isWritable($entity, $key)) {
                $this->propertyAccessor->setValue($entity, $key, $value);
            }
        }

        return $entity;
    }
555310
public function setContactId($contactId)
    {
        if ($contactId instanceof Lead) {
            $this->setContact($contactId);
        } elseif (\is_int($contactId)) {
            $this->contactId = $contactId;
        } else {
            throw new \InvalidArgumentException(
                '$contact must be an integer or instance of "\\Mautic\\LeadBundle\\Entity\\Lead"'
            );
        }

        return $this;
    }
1085615
public function mergeContactIntoAddressData(array &$addressData, ContactInterface $contact)
    {
        $addressData['firstName'] = $contact->getFirstName();
        $addressData['lastName'] = $contact->getLastName();
        $addressData['fullName'] = $contact->getFullName();
        $addressData['salutation'] = $contact->getSalutation();
        $addressData['formOfAddress'] = $contact->getFormOfAddress();
        if ($contact->getTitle() !== null) {
            $addressData['title'] = $contact->getTitle()->getTitle();
        }
    }
176820
public function addAssocContacts($contacts)
    {
        if (!is_array($contacts)) {
            return false;
        }
        foreach ($contacts as $name => $contact) {
            if (is_object($contact) && $contact  instanceof SoapVar) {
                $contact = $contact->enc_value;
            }
            if (!($contact  instanceof contact)) {
                return false;
            }
            if ($name != $contact->name) {
                return false;
            }
            $this->contacts[] = $contact;
        }

        return true;
    }
60402
private function resetContact($contact)
    {
        if ($contact->getCustomerId() && $contact->getEmailImported()) {
            $contact->setEmailImported(\Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_NOT_IMPORTED);
            $this->contactResource->save($contact);
        } elseif (! $contact->getCustomerId() && $contact->getIsSubscriber() && $contact->getSubscriberImported()) {
            $contact->setSubscriberImported(\Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_NOT_IMPORTED);
            $this->contactResource->save($contact);
        }
    }
788972
public function create(Contact $contact): Contact
    {
        $response = $this->client->post($this->prepareUrlForKey('add-contact'), [], $contact->jsonSerialize());
        $responseData = $response->getDecodedBody();

        return new Contact($responseData);
    }
713426
public function replaceContact($contactId, array $data = [])
	{
		return $this->sendRequest(
			$this->createRequest('PUT', sprintf('contacts/%d', $contactId), [], $data)
		);
	}
220637
public function update($id, ContactMetadata $contactMetadata)
    {
        $response = $this->mailjet->put(Resources::$Contactmetadata, ['id' => $id,'body' => $contactMetadata->format()]);
        if (!$response->success()) {
            $this->throwError("ContactMetadataManager:update() failed", $response);
        }

        return $response->getData();
    }
940544
public function setContact(Lead $contact)
    {
        $this->contact   = $contact;
        $this->contactId = $contact->getId();

        return $this;
    }