Returns contacts by account id.

@param int $id
@param string $locale
@param bool $onlyFetchMainAccounts

@return array|null
553442
public function findContactsByAccountId($id, $locale, $onlyFetchMainAccounts = false)
    {
        $contactsEntities = $this->contactRepository->findByAccountId(
            $id,
            null,
            false,
            $onlyFetchMainAccounts
        );

        if (!empty($contactsEntities)) {
            $contacts = [];
            foreach ($contactsEntities as $contact) {
                $contacts[] = new Contact($contact, $locale);
            }

            return $contacts;
        }

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

        return false;
    }
312218
public function findByIdAndLocale($id, $locale, $updateApiEntity = true)
    {
        $order = $this->orderRepository->findByIdAndLocale($id, $locale);

        if (!$order) {
            return null;
        }

        $order = $this->orderFactory->createApiEntity($order, $locale);

        if ($updateApiEntity) {
            $this->updateApiEntity($order, $locale);
        }

        return $order;
    }
589404
public function getById($id, $locale)
    {
        $account = $this->accountRepository->findAccountById($id);
        if (!$account) {
            throw new EntityNotFoundException($this->accountRepository->getClassName(), $id);
        }

        return $this->getApiObject($account, $locale);
    }
765048
private function findContactsByIds($ids)
    {
        if (0 === count($ids)) {
            return [];
        }

        $queryBuilder = $this->entityManager->createQueryBuilder()
            ->select('CONCAT(\'c\', c.id) AS id, CONCAT(CONCAT(c.firstName, \' \'), c.lastName) AS name')
            ->from($this->contactEntityClass, 'c')
            ->where('c.id IN (:ids)');

        $query = $queryBuilder->getQuery();
        $query->setParameter('ids', $ids);

        return $query->getArrayResult();
    }
43569
protected function findRecordInLocale($locale, $table, $id)
    {
        $query = SQLSelect::create('"ID"');
        $query->addFrom('"'. $table . '"');
        $query->addWhere([
            '"RecordID"' => $id,
            '"Locale"' => $locale,
        ]);

        return $query->firstRow()->execute()->value() !== null;
    }
1093312
static public function fetch( $id, $locale = false )
    {
        if ( is_string( $locale ) )
            $tags = self::fetchList( array( 'id' => $id ), null, null, false, $locale );
        else
            $tags = self::fetchList( array( 'id' => $id ) );

        if ( is_array( $tags ) && !empty( $tags ) )
            return $tags[0];

        return false;
    }
856925
public function getContact($contactID, $accountID)
    {
        $result = $this->httpHelper->get("accounts/" . intval($accountID) . "/contacts/" . intval($contactID));

        $phoneNumbers = [];
        if (is_object($result->phone_numbers))
        {
            foreach ($result->phone_numbers as $type => $phoneNumberResult)
            {
                $phoneNumber = new PhoneNumber([
                    'number' => $phoneNumberResult->number,
                    'extension' => $phoneNumberResult->extension,
                    'type' => $type,
                ]);
                array_push($phoneNumbers, $phoneNumber);
            }
        }

        $contact = new Contact([
            'contact_id' => $result->id,
            'account_id' => intval($accountID),
            'name' => $result->name,
            'role' => $result->role,
            'email_address' => $result->email_address,
            'phone_numbers' => $phoneNumbers,
        ]);

        return $contact;
    }
791050
public function findAll($locale, $filter = null)
    {
        if ($filter) {
            $accountEntities = $this->accountRepository->findByFilter($filter);
        } else {
            $accountEntities = $this->accountRepository->findAll();
        }

        if (!empty($accountEntities)) {
            $accounts = [];
            foreach ($accountEntities as $account) {
                $accounts[] = $this->getApiObject($account, $locale);
            }

            return $accounts;
        }

        return;
    }
251309
static public function fetchListCount( $params, $mainTranslation = false, $locale = false )
    {
        $customConds = self::fetchCustomCondsSQL( $params, $mainTranslation, $locale );

        if ( is_array( $params ) )
        {
            $newParams = array();
            foreach ( $params as $key => $value )
            {
                if ( $key != 'keyword' )
                    $newParams[$key] = $value;
                else
                    $newParams['eztags_keyword.keyword'] = $value;
            }

            $params = $newParams;
        }

        $tagsList = parent::fetchObjectList( self::definition(), array(), $params,
                                                         array(), null, false, false,
                                                         array( array( 'operation' => 'COUNT( * )',
                                                                       'name'      => 'row_count' ) ),
                                                         array( 'eztags_keyword' ), $customConds );

        return $tagsList[0]['row_count'];
    }
330548
public function roleFetchSubjectRoles(SubjectInterface $subject, $permissions = true)
    {
        $query = "
            SELECT
                role_id
            FROM
                auth_subject_role
            WHERE
                subject_id = :subject_id
        ";
        $roles = [];
        $cur = $this->db->prepare($query);
        $cur->bindValue(":subject_id", $subject->id(), PDO::PARAM_INT);
        try {
            $cur->execute();
            $res = $cur->fetchAll(PDO::FETCH_OBJ);
            if (!$res) {
                return [];
            } else {
                $role_ids = array_map(
                    function ($row) {
                        return $row->role_id;
                    },
                    $res
                );
                $roles = $this->roleFetchById($role_ids);
            }
        } catch (PDOException $db_err) {
            if ($this->logger) {
                $this->logger->error("Failed to fetch roles for subject", ['exception' => $db_err]);
            }
        }
        return $roles;
    }
1168948
public function findAllByLocale($locale)
    {
        try {
            $qb = $this->getStatusQuery($locale);

            return $qb->getQuery()->getResult();
        } catch (NoResultException $exc) {
            return null;
        }
    }
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);
    }
675829
public function retrieveTranslationByIdAndLocale($deliveryStatusId, $locale)
    {
        /** @var DeliveryStatusEntity $deliveryStatus */
        $deliveryStatus = $this->deliveryStatusRepository->find($deliveryStatusId);

        if (!$deliveryStatus || $deliveryStatus->getTranslations()->count() < 1) {
            return null;
        }

        $deliveryStatusTranslation = $deliveryStatus->getTranslations()->first();

        /** @var DeliveryStatusTranslation $translation */
        foreach ($deliveryStatus->getTranslations() as $translation) {
            if ($translation->getLocale() === $locale) {
                $deliveryStatusTranslation = $translation;
                break;
            }
        }

        return $deliveryStatusTranslation;
    }
1039584
public function findOrdersByStatusAndAccount($locale, $status, AccountInterface $account)
    {
        try {
            $qb = $this->getOrderQuery($locale)
                ->leftJoin('o.creator', 'creator')
                ->leftJoin('creator.contact', 'contact')
                ->leftJoin('contact.accountContacts', 'accountContact', 'WITH', 'accountContact.main = true')
                ->leftJoin('accountContact.account', 'account')
                ->andWhere('status.id = :statusId')
                ->andWhere('account = :account')
                ->setParameter('account', $account)
                ->setParameter('statusId', $status);

            return $qb->getQuery()->getResult();
        } catch (NoResultException $exc) {
            return null;
        }
    }
879187
public function findByIdAndLocale($id, $locale)
    {
        $shipping = $this->getShippingRepository()->findByIdAndLocale($id, $locale);

        if ($shipping) {
            $apiShippings = $this->shippingFactory->createApiEntity($shipping, $locale);

            // set currently shipped items (sum of all shippings for that item)
            $shippingCounts = $this->getSumOfShippedItemsByOrderId($shipping->getOrder()->getId());
            foreach ($apiShippings->getItems() as $apiItem) {
                $itemId = $apiItem->getEntity()->getItem()->getId();
                $sum = 0;
                if (array_key_exists($itemId, $shippingCounts)) {
                    $sum = $shippingCounts[$itemId];
                }
                $apiItem->setShippedItems($sum);
            }
            return $apiShippings;
        } else {
            return null;
        }
    }
883584
public function getChildren( $offset = 0, $limit = null, $mainTranslation = false )
    {
        return self::fetchByParentID( $this->attribute( 'id' ), $offset, $limit, $mainTranslation );
    }