src/Repository/Filter/PaginationQuery.php
public function createQuery($params, $queryBuilder)
    {
        if ($params instanceof Parameters) {
            $value = $params->toArray();
        } else {
            $value = $params;
        }

        /*
         * if user is recruiter or admin
         * filter query based on permissions.view
         */
        $auth = $this->authService;
        $user = $auth->getUser();
        $ignored = [null,'guest',UserInterface::ROLE_USER];
        if (!in_array($user->getRole(), $ignored)) {
            $queryBuilder->field('permissions.view')->equals($user->getId());
        }

        if (isset($params['q']) && $params['q'] && $params['q'] != 'en/organizations/profile') {
            $queryBuilder->text($params['q'])->language('none');
        }

        if (!isset($value['sort'])) {
            $value['sort'] = '-date';
        }

        $queryBuilder->sort($this->filterSort($value['sort']));

        if (isset($params['type']) && $params['type'] === 'profile') {
            //@TODO: we should use aggregate query here
            $queryBuilder->field('profileSetting')
                ->in([Organization::PROFILE_ALWAYS_ENABLE,Organization::PROFILE_ACTIVE_JOBS])
            ;

            $filters = $this->getOrganizationProfileFilters($queryBuilder);
            if (count($filters) > 0) {
                $queryBuilder->field('id')->notIn($filters);
            }
        }

        return $queryBuilder;
    }
public function createQuery($params, $queryBuilder)
    {
        if ($params instanceof Parameters) {
            $value = $params->toArray();
        } else {
            $value = $params;
        }

        /*
         * if user is recruiter or admin
         * filter query based on permissions.view
         */
        $auth = $this->authService;
        $user = $auth->getUser();
        $ignored = [null,'guest',UserInterface::ROLE_USER];
        if (!in_array($user->getRole(), $ignored)) {
            $queryBuilder->field('permissions.view')->equals($user->getId());
        }

        if (isset($params['q']) && $params['q'] && $params['q'] != 'en/organizations/profile') {
            $queryBuilder->text($params['q'])->language('none');
        }

        if (!isset($value['sort'])) {
            $value['sort'] = '-date';
        }

        $queryBuilder->sort($this->filterSort($value['sort']));

        if (isset($params['type']) && $params['type'] === 'profile') {
            //@TODO: we should use aggregate query here
            $queryBuilder->field('profileSetting')
                ->in([Organization::PROFILE_ALWAYS_ENABLE,Organization::PROFILE_ACTIVE_JOBS])
            ;

            $filters = $this->getOrganizationProfileFilters($queryBuilder);
            if (count($filters) > 0) {
                $queryBuilder->field('id')->notIn($filters);
            }
        }

        return $queryBuilder;
    }
Creates a query for filtering organizations

@see \Core\Repository\Filter\AbstractPaginationQuery::createQuery()
@param $params
@param \Doctrine\ODM\MongoDB\Query\Builder $queryBuilder
@return mixed