Push a contact to a preconfigured Contact Client.

@param Contact $contact
@param array   $event

@return bool

@throws Exception
978115
public function pushLead($contact, $event = [])
    {
        $this->reset();
        $this->getEvent($event);

        if (empty($this->event['config']['contactclient'])) {
            return false;
        }

        /** @var Contact $contactModel */
        $clientModel = $this->getContactClientModel();
        $client      = $clientModel->getEntity($this->event['config']['contactclient']);

        $this->sendContact($client, $contact, false);

        // Returning false will typically cause a retry.
        // If an error occurred and we do not wish to retry we should return true.
        return $this->valid ? $this->valid : !$this->retry;
    }
883698
public function changeEmail($listId, Contact $contact, $oldEmail)
    {
        // get old contact properties
        $response = $this->mailjet->get(Resources::$Contactdata, ['id' => $oldEmail]);
        if (!$response->success()) {
            $this->throwError("ContactsListManager:changeEmail() failed", $response);
        }

        // copy contact properties
        $oldContactData = $response->getData();
        if (isset($oldContactData[0])) {
            $contact->setProperties($oldContactData[0]['Data']);
        }

        // add new contact
        $contact->setAction(Contact::ACTION_ADDFORCE);
        $response = $this->_exec($listId, $contact);
        if (!$response->success()) {
            $this->throwError("ContactsListManager:changeEmail() failed", $response);
        }

        // remove old
        $oldContact = new Contact($oldEmail);
        $oldContact->setAction(Contact::ACTION_REMOVE);
        $response = $this->_exec($listId, $oldContact);
        if (!$response->success()) {
            $this->throwError("ContactsListManager:changeEmail() failed", $response);
        }

        return $response->getData();
    }
1155237
public function update($listId, Contact $contact, $action=Contact::ACTION_ADDNOFORCE)
    {
        $contact->setAction($action);
        $response = $this->_exec($listId, $contact);
        if (!$response->success()) {
            $this->throwError("ContactsListManager:update() failed", $response);
        }

        return $response->getData();
    }
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);
            }
        }
    }
1111208
public function validContact(string $contact): bool
    {
        return filter_var($contact, FILTER_VALIDATE_EMAIL) !== false ||
               filter_var($contact, FILTER_VALIDATE_URL) !== false;
    }
485419
public function update(Contact $contact): Contact
    {
        $id = $contact->getId();

        $contact->setId(null);

        $response = $this->client->put($this->prepareUrlForKey('update-contact', ['id' => $id]), [], $contact->jsonSerialize());
        $responseData = $response->getDecodedBody();

        return new Contact($responseData);
    }
722630
public function onContactSourceDelete(ContactSourceEvent $event)
    {
        $entity = $event->getContactSource();
        $log    = [
            'bundle'    => 'contactsource',
            'object'    => 'contactsource',
            'objectId'  => $entity->deletedId,
            'action'    => 'delete',
            'details'   => ['name' => $entity->getName()],
            'ipAddress' => $this->ipHelper->getIpAddressFromRequest(),
        ];
        $this->auditLogModel->writeToLog($log);
    }
279290
public function getContact($email, $websiteId, $contactFromTable = false)
    {
        if (! $this->isEnabled($websiteId)) {
            return false;
        }

        if ($contactFromTable) {
            $contact = $contactFromTable;
        } else {
            $contact = $this->contactFactory->create()
                ->loadByCustomerEmail($email, $websiteId);
        }

        $client = $this->getWebsiteApiClient($websiteId);
        $response = $client->getContactByEmail($email);
        if (! isset($response->id)) {
            $response = $client->postContacts($email);
        }

        if (isset($response->message)) {
            $contact->setEmailImported(1);
            if ($response->message == \Dotdigitalgroup\Email\Model\Apiconnector\Client::API_ERROR_CONTACT_SUPPRESSED) {
                $contact->setSuppressed(1);
            }
            $this->saveContact($contact);
            return false;
        }
        //save contact id
        if (isset($response->id)) {
            $contact->setContactId($response->id);
            $this->saveContact($contact);
        } else {
            //curl operation timeout
            return false;
        }

        return $response;
    }
1335273
public function getContactEvents($contactId, $search = '', $start = 0, $limit = 0, $orderBy = '', $orderByDir = 'ASC')
    {
        $parameters = array(
            'search'        => $search,
            'start'         => $start,
            'limit'         => $limit,
            'orderBy'       => $orderBy,
            'orderByDir'    => $orderByDir,
        );

        $parameters = array_filter($parameters);

        return $this->makeRequest($this->endpoint.'/contact/'.$contactId, $parameters);
    }
28578
private function processAdditionalSubscriptions($contact, $client, $website)
    {
        $additionalFromConfig = $this->helper->getAddressBookIdsToShow($website);

        if (!$this->helper->getCanShowAdditionalSubscriptions($website) ||
            empty($additionalFromConfig)) {
            return true;
        }

        $success = true;
        $additionalSubscriptions = $this->getRequest()->getParam('additional_subscriptions', []);

        foreach ($additionalFromConfig as $bookId) {
            if (in_array($bookId, $additionalSubscriptions)) {
                $bookResponse = $client->postAddressBookContacts(
                    $bookId,
                    $contact
                );
                if (isset($bookResponse->message)) {
                    $success = false;
                }
            }
        }
        foreach ($additionalFromConfig as $bookId) {
            if (!in_array($bookId, $additionalSubscriptions)) {
                $client->deleteAddressBookContact(
                    $bookId,
                    $contact->id
                );
            }
        }
        return $success;
    }
159265
protected function dispatchEvent($action, &$entity, $isNew = false, Event $event = null)
    {
        if (!$entity instanceof ContactClient) {
            throw new MethodNotAllowedHttpException(['ContactClient']);
        }

        switch ($action) {
            case 'pre_save':
                $name = ContactClientEvents::PRE_SAVE;
                break;
            case 'post_save':
                $name = ContactClientEvents::POST_SAVE;
                break;
            case 'pre_delete':
                $name = ContactClientEvents::PRE_DELETE;
                break;
            case 'post_delete':
                $name = ContactClientEvents::POST_DELETE;
                break;
            default:
                return null;
        }

        if ($this->dispatcher->hasListeners($name)) {
            if (empty($event)) {
                $event = new ContactClientEvent($entity, $isNew);
                $event->setEntityManager($this->em);
            }

            $this->dispatcher->dispatch($name, $event);

            return $event;
        } else {
            return null;
        }
    }
286330
public function newSession(
        ContactClient $contactClient = null,
        Contact $contact = null,
        $payload = [],
        $campaign = null,
        $event = []
    ) {
        $this->context     = [];
        $this->renderCache = [];
        $this->setContactClient($contactClient);
        $this->addContextPayload($payload);
        $this->addContextContact($contact);
        $this->addContextCampaign($campaign);
        $this->addContextEvent($event);

        return $this;
    }
1321595
public function sendToContact($id, $contactId, $parameters = array())
    {
        return $this->makeRequest($this->endpoint.'/'.$id.'/contact/'.$contactId.'/send', $parameters, 'POST');
    }
788972
public function create(Contact $contact): Contact
    {
        $response = $this->client->post($this->prepareUrlForKey('add-contact'), [], $contact->jsonSerialize());
        $responseData = $response->getDecodedBody();

        return new Contact($responseData);
    }
638502
public function addContact(\Sulu\Bundle\ContactBundle\Entity\ContactInterface $contacts)
    {
        $this->contacts[] = $contacts;

        return $this;
    }
21371
public function on($event, $callback)
        {
            if (!is_callable($callback)) {
                throw new Exception('Socketio::on() type callback must be callable.');
            }

            if (!isset($this->callbacks[$event])) {
                $this->callbacks[$event] = array();
            }

            // @TODO Handle case where callback is a string
            if (in_array($callback, $this->callbacks[$event])) {
                $this->stdout('debug', 'Skip existing callback');
                return;
            }

            $this->callbacks[$event][] = $callback;
        }
903384
public function onContactClientDelete(ContactClientEvent $event)
    {
        $entity = $event->getContactClient();
        $log    = [
            'bundle'    => 'contactclient',
            'object'    => 'contactclient',
            'objectId'  => $entity->deletedId,
            'action'    => 'delete',
            'details'   => ['name' => $entity->getName()],
            'ipAddress' => $this->ipHelper->getIpAddressFromRequest(),
        ];
        $this->auditLogModel->writeToLog($log);
    }