Prepare the contact data
@param  array $contacts
@return array
484554
public function prepareContacts($contacts)
    {
        $retContacts = array();

        foreach ($contacts as &$contact) {
            $info = array(
                'image' => null,
                'first_name' => null,
                'last_name' => null,
                'work_title' => null,
                'administration_unit' => null,
                'email' => null,
                'phone' => null,
                'social_media' => null,
                'address' => null,
                'visiting_address' => null,
                'opening_hours' => null
            );

            switch ($contact['acf_fc_layout']) {
                case 'custom':
                    $info = apply_filters('Modularity/mod-contacts/contact-info', array(
                        'image'               => $contact['image'],
                        'first_name'          => $contact['first_name'],
                        'last_name'           => $contact['last_name'],
                        'work_title'          => $contact['work_title'],
                        'administration_unit' => $contact['administration_unit'],
                        'email'               => strtolower($contact['email']),
                        'phone'               => $contact['phone_numbers'],
                        'social_media'        => $contact['social_media'],
                        'address'             => $contact['address'],
                        'visiting_address'    => $contact['visiting_address'],
                        'opening_hours'       => $contact['opening_hours'],
                        'other'               => $contact['other']
                    ), $contact, $contact['acf_fc_layout']);
                    break;

                case 'user':
                   $info = apply_filters('Modularity/mod-contacts/contact-info', array(
                        'id'                  => $contact['user']['ID'],
                        'image'               => null,
                        'first_name'          => $contact['user']['user_firstname'],
                        'last_name'           => $contact['user']['user_lastname'],
                        'work_title'          => null,
                        'administration_unit' => null,
                        'email'               => strtolower($contact['user']['user_email']),
                        'phone'               => null,
                        'address'             => $contact['address'],
                        'visiting_address'    => null,
                        'opening_hours'       => null
                    ), $contact, $contact['acf_fc_layout']);
                    break;
            }

            //Parse thumbnail id's
            $info['thumbnail'] = false;
            if (isset($info['image']) && !empty($info['image']) && isset($info['image']['id']) && is_numeric($info['image']['id'])) {
                $info['thumbnail'] = wp_get_attachment_image_src(
                    $info['image']['id'],
                    apply_filters(
                        'Modularity/image/contact',
                        municipio_to_aspect_ratio('1:1', array(400, 400)),
                        $this->args
                    )
                );
            }

            //Parse directly inputted url:s
            if (isset($info['image']) && filter_var($info['image'], FILTER_VALIDATE_URL) !== false) {
                $info['thumbnail'] = array($info['image'], 250, 250, false);
            }

            //Create full name
            $info['full_name'] = trim($info['first_name'] . ' ' . $info['last_name']);

            //Adds chosen user meta data or removes the field completely and make it unvisible.
            if (get_field('advaced_mode', $this->ID) == "1") {

                if (get_field('profile_image', $this->ID) == "1") {
                    $info['thumbnail'][0] = get_user_meta($contact['user']['ID'], "user_profile_picture", true);
                } else {
                    unset($info['thumbnail']);
                }

                if (get_field('other_user_info', $this->ID) == "1") {
                    $info['other'] = get_user_meta($contact['user']['ID'], "user_about", true);
                } else {
                    unset($info['other']);
                }

                if (get_field('work_title', $this->ID) == "1") {
                    $info['work_title'] = get_user_meta($contact['user']['ID'], "user_work_title", true);
                } else {
                    unset($info['work_title']);
                }

                if (get_field('email', $this->ID) != "1") {
                    unset($info['email']);
                }

                if (get_field('address', $this->ID) != "1") {
                    unset($info['address']);
                }

                if (get_field('phone', $this->ID) != "1") {
                    unset($info['phone']);
                }
            }

            $retContacts[] = $info;
        }

        return $retContacts;
    }
950147
public function getLocales()
    {
        $entities = [];
        if ($this->entity->getLocales()) {
            foreach ($this->entity->getLocales() as $locale) {
                $entities[] = new ContactLocale($locale);
            }
        }

        return $entities;
    }
943927
public static function prepare($params = [])
    {
        $positions = array_combine(array_keys($params), array_fill(0, count($params), 0));
        $data = [];

        do {
            $data[] = self::getByIndexes($params, $positions);
        } while (self::updateIndexesToNextIteration($params, $positions));

        return $data;
    }
440331
public function addContacts($contacts, $id = null)
    {
        if (!is_array($contacts)) {
            throw new  InvalidArgumentException('No array with contacts provided.');
        }
        if (is_null($id)) {
            throw new InvalidArgumentException('No group id provided.');
        }

        $ResourceName = $this->resourceName . ($id ? '/' . $id . '/contacts' : null);
        $contacts = json_encode($contacts);
        list($responseStatus, , $responseBody) = $this->HttpClient->performHttpRequest(
            Common\HttpClient::REQUEST_PUT,
            $ResourceName,
            false,
            $contacts
        );
        if ($responseStatus !== Common\HttpClient::HTTP_NO_CONTENT) {
            return json_decode($responseBody);
        }
    }
250966
protected function form(Contact $contact)
    {
        $countries = collect(countries())->map(function ($country, $code) {
            return [
                'id' => $code,
                'text' => $country['name'],
                'emoji' => $country['emoji'],
            ];
        })->values();
        $languages = collect(languages())->pluck('name', 'iso_639_1');
        $sources = app('rinvex.contacts.contact')->distinct()->get(['source'])->pluck('source', 'source')->toArray();
        $methods = app('rinvex.contacts.contact')->distinct()->get(['method'])->pluck('method', 'method')->toArray();
        $genders = ['male' => trans('cortex/contacts::common.male'), 'female' => trans('cortex/contacts::common.female')];

        return view('cortex/contacts::managerarea.pages.contact', compact('contact', 'genders', 'countries', 'languages', 'sources', 'methods'));
    }
646986
protected function prepareRoles(array $roles)
    {
        $now = now();

        return array_map(function ($role) use ($now) {
            return array_merge($role, [
                'slug'         => $role['slug'] ?? $this->slugify($role['name']),
                'is_locked'    => $role['is_locked'] ?? true,
                'created_at'   => $now,
                'updated_at'   => $now,
                'activated_at' => array_get($role, 'activated_at', $now),
            ]);
        }, $roles);
    }
1052634
protected function extractContacts(Contact $contact)
    {
        $result = [];

        foreach ($this->languages as $language) {
            $result[$language] = $this->contactLocalization($contact, $language);
        }

        return $result;
    }
787342
public function getMainAccountContact($contact)
    {
        foreach ($contact->getAccountContacts() as $accountContact) {
            /** @var AccountContact $accountContact */
            if ($accountContact->getMain()) {
                return $accountContact;
            }
        }

        return false;
    }
305941
public function processPhones($contact, $phones)
    {
        $get = function($phone) {
            return $phone->getId();
        };

        $delete = function($phone) use ($contact) {
            return $contact->removePhone($phone);
        };

        $update = function($phone, $matchedEntry) {
            return $this->updatePhone($phone, $matchedEntry);
        };

        $add = function($phone) use ($contact) {
            return $this->addPhone($contact, $phone);
        };

        $entities = $contact->getPhones();

        $result = $this->processSubEntities(
            $entities,
            $phones,
            $get,
            $add,
            $update,
            $delete
        );

        $this->resetIndexOfSubentites($entities);

        // check main
        $this->setMainPhone($contact);

        return $result;
    }
1238196
public function setContact($contact)
    {
        if ($contact instanceof Contact) {
            $contact = $contact->getId();
        }

        $this->contact = $contact;

        return $this;
    }
577073
public static function createContactsFromObjects(array $objects = null)
    {
        if ($objects === null) {
            return null;
        }

        $contacts = [];

        foreach ($objects as $object) {
            $contact = new static();
            $contact->updateFromObject($object);

            $contacts[] = $contact;
        }

        return $contacts;
    }
973232
private function prepareFields(array $fields)
    {
        $include = null;
        foreach ($fields as $key => $type) {
            $type = (bool) $type;
            if (null === $include) {
                $include = $type;
            }
            if ($type !== $include) {
                PersisterException::badRequest('Field projection mismatch. You cannot both exclude and include fields.');
            }
            $fields[$key] = $type;
        }
        return [$fields, $include];
    }
608417
function GetContacts($tags = null, $params = array()) {
		if (!is_null($tags)) {
			return $this->return_all_results($this->MakeAPICall("GET", "contacts/tags/" . rawurlencode($tags), 0, $params));
		}
		else {
			return $this->return_all_results($this->MakeAPICall("GET", "contacts", 0, $params));
		}
	}
460018
public function updateContact(Contact $contact)
    {
        return $this->httpHelper->patch("accounts/" . $contact->getAccountID() . "/contacts/" . $contact->getContactID(), [
            'name' => $contact->getName(),
            'role' => $contact->getRole(),
            'email_address' => $contact->getEmailAddress(),
            'phone_numbers' => $contact->getPhoneNumbersFormatted(),
        ]);
    }
1085504
public function getContacts()
    {
        $nodes = $this->get('//epp:epp/epp:response/epp:resData/domain:infData/domain:contact');

        foreach ($nodes as $node) {
            yield $node->getAttribute('type') => $node->nodeValue;
        }
    }
621334
public static function createProcessedContactFromStdClassArray(array $contactArray): ClassValidationArray
    {
        $contacts = new ClassValidationArray();
        foreach ($contactArray as $c) {
            $contacts[] = self::createProcessedContactFromStdClass($c);
        }
        return $contacts;
    }
104068
public function addContextContact(Contact $contact = null)
    {
        if (!$contact) {
            return $this;
        }
        $context = [];
        $conType = [];

        // Append contact ID.
        $contactId     = (int) $contact->getId();
        $context['id'] = isset($contactId) ? $contactId : null;
        $conType['id'] = 'number';

        // Append contact owner data.
        $owner                         = $contact->getOwner();
        $context['owner']              = [];
        $context['owner']['id']        = $owner ? $owner->getId() : null;
        $conType['owner']['id']        = 'number';
        $context['owner']['username']  = $owner ? $owner->getUsername() : null;
        $context['owner']['firstName'] = $owner ? $owner->getFirstName() : null;
        $context['owner']['lastName']  = $owner ? $owner->getLastName() : null;
        $context['owner']['email']     = $owner ? $owner->getEmail() : null;

        // Append points value.
        $points            = $contact->getPoints();
        $context['points'] = isset($points) ? $points : null;
        $conType['points'] = 'number';

        // Append IP Addresses.
        $context['ipAddresses'] = [];
        $context['ip']          = null;
        foreach ($contact->getIpAddresses()->toArray() as $ip => $value) {
            $context['ipAddresses'][] = $ip;
            $context['ip']            = $ip;
        }

        // Add Identified date.
        /** @var \DateTime $dateIdentified */
        $dateIdentified            = $contact->getDateIdentified();
        $context['dateIdentified'] = $dateIdentified ? $this->dateFormatHelper->format($dateIdentified) : null;
        $conType['dateIdentified'] = 'datetime';

        // Add Modified date.
        /** @var \DateTime $dateModified */
        $dateModified            = $contact->getDateModified();
        $context['dateModified'] = $dateModified ? $this->dateFormatHelper->format($dateModified) : null;
        $conType['dateModified'] = 'datetime';

        // Add DNC data.
        $context['doNotContacts'] = [];
        $context['doNotContact']  = false;
        if ($contactId && $this->needsDncData) {
            /** @var \Mautic\LeadBundle\Model\DoNotContact $record */
            foreach ($contact->getDoNotContact() as $record) {
                $context['doNotContacts'][$record->getChannel()]           = [
                    'comments' => $record->getComments(),
                    'reason'   => $record->getReason(),
                    'exists'   => true,
                ];
                $conType['doNotContacts'][$record->getChannel()]['exists'] = 'boolean';
                $context['doNotContact']                                   = true;
            }
            $conType['doNotContact'] = 'boolean';
        }

        // Add UTM data.
        $context['utm'] = [
            'campaign'   => null,
            'content'    => null,
            'medium'     => null,
            'query'      => null,
            'referrer'   => null,
            'remoteHost' => null,
            'source'     => null,
            'term'       => null,
            'url'        => null,
            'userAgent'  => null,
        ];
        if ($contactId && $this->needsUtmData) {
            $utmTags            = $this->utmSourceHelper->getSortedUtmTags($contact);
            $context['utmTags'] = [];
            if ($utmTags) {
                foreach ($utmTags as $utmTag) {
                    $tags                 = [
                        'campaign'   => $utmTag->getUtmCampaign(),
                        'content'    => $utmTag->getUtmContent(),
                        'medium'     => $utmTag->getUtmMedium(),
                        'query'      => $utmTag->getQuery(),
                        'referrer'   => $utmTag->getReferer(),
                        'remoteHost' => $utmTag->getRemoteHost(),
                        'source'     => $utmTag->getUtmSource(),
                        'term'       => $utmTag->getUtmTerm(),
                        'url'        => $utmTag->getUrl(),
                        'userAgent'  => $utmTag->getUserAgent(),
                    ];
                    $context['utmTags'][] = $tags;
                    // Override the {{ utm.values }} to be the latest non-empty version of each found.
                    foreach ($tags as $key => $value) {
                        if (!empty($value)) {
                            $context['utm'][$key] = $value;
                        }
                    }
                }
            }
        }

        // Add Device data.
        $context['device'] = [
            'name'        => null,
            'brand'       => null,
            'model'       => null,
            'fingerprint' => null,
            'trackingId'  => null,
            'os'          => [
                'osName'      => null,
                'osShortName' => null,
                'osVersion'   => null,
                'osPlatform'  => null,
            ],
        ];
        if ($contactId && $this->needsDeviceData) {
            /** @var LeadDeviceRepository $deviceRepo */
            $deviceRepo = $this->contactModel->getDeviceRepository();
            $devices    = $deviceRepo->getEntities(
                [
                    'limit'            => 1,
                    'orderBy'          => $deviceRepo->getTableAlias().'.id',
                    'orderByDir'       => 'DESC',
                    'filter'           => [
                        'force' => [
                            [
                                'column' => 'IDENTITY('.$deviceRepo->getTableAlias().'.lead)',
                                'expr'   => 'eq',
                                'value'  => $contactId,
                            ],
                        ],
                    ],
                    'ignore_paginator' => true,
                ]
            );
            if ($devices && $device = reset($devices)) {
                $context['device'] = [
                    'name'        => $device->getDevice(),
                    'brand'       => $device->getDeviceBrand(),
                    'model'       => $device->getDeviceModel(),
                    'fingerprint' => $device->getDeviceFingerprint(),
                    'trackingId'  => $device->getTrackingId(),
                    'os'          => [
                        'osName'      => $device->getDeviceOsName(),
                        'osShortName' => $device->getDeviceOsShortName(),
                        'osVersion'   => $device->getDeviceOsVersion(),
                        'osPlatform'  => $device->getDeviceOsPlatform(),
                    ],
                ];
            }
        }

        $fieldGroups = $contact->getFields();
        if ($fieldGroups) {
            foreach ($fieldGroups as $fgKey => $fieldGroup) {
                foreach ($fieldGroup as $fkey => $field) {
                    $value = isset($field['value']) ? $field['value'] : '';
                    $type  = isset($field['type']) ? $field['type'] : '';
                    if ('' !== $value && in_array($type, ['datetime', 'date', 'time'])) {
                        // Soft support for labels/values as dates/times.
                        @$newValue = $this->dateFormatHelper->format($value);
                        if (null !== $newValue && '' !== $newValue) {
                            $value = $newValue;
                        }
                    }
                    $context[$fkey] = $value;
                    if ($type) {
                        $conType[$fkey] = $type;
                    }
                }
            }
        }

        // Support multiple contacts in the future if needed by uncommenting a bit here.
        // $contacts = !empty($this->context['contacts']) ? $this->context['contacts'] : [];

        // Set the context to this contact.
        $this->sanitizeContext($context);
        $this->context = array_merge($this->context, $context);
        $this->conType = array_merge($this->conType, $conType);

        // Support multiple contacts for future batch processing.
        // $this->context['contacts']                 = $contacts;
        // $this->context['contacts'][$context['id']] = $context;

        return $this;
    }