Called by parse, loops through all the rules to find out if nested or not.

@param array $rules
@param Builder $querybuilder
@param string $queryCondition

@throws QBParseException

@return Builder
3275
protected function loopThroughRules(array $rules, Builder $querybuilder, $queryCondition = 'AND')
    {
        foreach ($rules as $rule) {
            /*
             * If makeQuery does not see the correct fields, it will return the QueryBuilder without modifications
             */
            $querybuilder = $this->makeQuery($querybuilder, $rule, $queryCondition);

            if ($this->isNested($rule)) {
                $querybuilder = $this->createNestedQuery($querybuilder, $rule, $queryCondition);
            }
        }

        return $querybuilder;
    }
32816
protected function executeWithPartialLoad(QueryBuilder $qb)
    {
        $query = $qb->getQuery();
        $query->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true);

        return $query->getOneOrNullResult();
    }
328533
protected function validateCondition($condition)
    {
        $condition = trim(strtolower($condition));

        if ($condition !== 'and' && $condition !== 'or') {
            throw new QBParseException("Condition can only be one of: 'and', 'or'.");
        }

        return $condition;
    }
220900
private function buildSubclauseQuery($query, $rule, $value, $condition)
    {
        /*
         * Convert the Operator (LIKE/NOT LIKE/GREATER THAN) given to us by QueryBuilder
         * into on one that we can use inside the SQL query
         */
        $_sql_op = $this->operator_sql[$rule->operator];
        $operator = $_sql_op['operator'];
        $require_array = $this->operatorRequiresArray($operator);

        $subclause = $this->joinFields[$rule->field];
        $subclause['operator'] = $operator;
        $subclause['value'] = $value;
        $subclause['require_array'] = $require_array;

        $not = array_key_exists('not_exists', $subclause) && $subclause['not_exists'];

        // Create a where exists clause to join to the other table, and find results matching the criteria
        $query = $query->whereExists(
            /**
             * @param Builder $query
             */
            function(Builder $query) use ($subclause) {

                $q = $query->selectRaw(1)
                    ->from($subclause['to_table'])
                    ->whereRaw($subclause['to_table'].'.'.$subclause['to_col']
                        .' = '
                        .$subclause['from_table'].'.'.$subclause['from_col']);

                if (array_key_exists('to_clause', $subclause)) {
                    $q->where($subclause['to_clause']);
                }

                $this->buildSubclauseInnerQuery($subclause, $q);
            },
            $condition,
            $not
        );

        return $query;
    }
77669
private function getConditionSelectQuery(): QueryBuilder
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT ngbm_rule_condition.*')
            ->from('ngbm_rule_condition');

        return $query;
    }
447444
protected function search(QueryBuilder $qb, string $search): void
    {
        $query = $this->queryDefinition;
        $node = $this->objectDefinition;

        $em = $this->getManager();
        $metadata = $em->getClassMetadata($this->entity);

        $node->getFields();
        $columns = [];
        $searchFields = FieldOptionsHelper::normalize($query->getMeta('pagination')['search_fields'] ?? ['*']);
        foreach ($node->getFields() as $field) {
            if (!FieldOptionsHelper::isEnabled($searchFields, $field->getName())) {
                continue;
            }

            $config = FieldOptionsHelper::getConfig($searchFields, $field->getName(), null);
            $searchColumn = null;
            if ($metadata->hasField($field->getName())) {
                $searchColumn = $field->getName();
            }

            if ($metadata->hasField($field->getOriginName())) {
                $searchColumn = $field->getOriginName();
            }

            if ($searchColumn) {
                switch ($metadata->getFieldMapping($searchColumn)['type']) {
                    case Type::STRING:
                    case Type::TEXT:
                        $columns[$searchColumn] = $config ?? 'partial';
                        break;
                    case Type::INTEGER:
                    case Type::BIGINT:
                    case Type::FLOAT:
                    case Type::DECIMAL:
                    case Type::SMALLINT:
                        $columns[$searchColumn] = $config ?? 'exact';
                        break;
                }
            }
        }

        foreach ($searchFields as $field => $mode) {
            if (\is_int($field)) {
                $field = $mode;
                $mode = 'exact';
            }

            if ('*' === $field) {
                continue;
            }
            $columns[$field] = $mode;
        }


        if (\count($columns) > 0) {
            $joins = [];
            $orx = new Orx();
            foreach ($columns as $column => $mode) {
                $alias = $qb->getRootAliases()[0];
                if (strpos($column, '.') !== false) {
                    [$child, $column] = explode('.', $column);
                    $parentAlias = $alias;
                    $alias = 'searchJoin'.ucfirst($child);
                    if (!\in_array($alias, $joins, true)) {
                        $qb->leftJoin("{$parentAlias}.{$child}", $alias);
                        $joins[] = $alias;
                    }
                }

                if ('partial' === $mode) {
                    //search each word separate
                    $searchArray = explode(' ', $search);

                    $partialAnd = new Andx();
                    foreach ($searchArray as $q) {
                        $q = trim($q);
                        $partialAnd->add("$alias.$column LIKE '%$q%'");
                    }
                    $orx->add($partialAnd);
                } else {
                    $q = trim($search);
                    $orx->add("$alias.$column LIKE '$q'");
                }
            }

            $qb->andWhere($orx);
        }
    }
1040199
public function count(array $constraints = [], QueryBuilder $qb = null)
    {
        $qb = !is_null($qb) ? $qb : $this->createQueryBuilder('e');
        if (count($constraints)) $qb = $this->_by($qb, $constraints);
        return $this->arrange($this->_count($qb), Repository::RESULT_SHAPE_SCALAR);
    }
925392
protected function _query(QueryBuilder $qb, array $columns)
    {
        return $this->inquire($qb, $columns, $this->getClassMetadata(), 'e', $this->getEntityManager());
    }
1006499
protected function buildWhereOr(QueryBuilder $qb, $parentColumnName, array $options)
    {
        $orX = $qb->expr()->orX();
        foreach ($options as $columnName => $option) {
            if (empty($options[$columnName])) {
                continue;
            } elseif (Arr::isIndexed($options)) {
                $key = $parentColumnName . '_' . $columnName;
                $orX->add("$parentColumnName = :$key");
                $qb->setParameter($key, $option);
            } else {
                $orX->add("$columnName = :$columnName");
                $qb->setParameter($columnName, $option);
            }
        }

        return $orX;
    }
1246865
protected function addSearch(QueryBuilder $queryBuilder)
    {
        if ($this->search !== true) {
            return;
        }

        $request = $this->request->getCurrentRequest();

        $columns = $request->get('columns', array());

        $searchFields = array_intersect_key(array_values($this->fields), $columns);

        $globalSearch = $request->get('search');

        $orExpr = $queryBuilder->expr()->orX();

        $filteringType = $this->getFilteringType();

        foreach ($searchFields as $i => $searchField) {

            $searchField = $this->getSearchField($searchField);

            // Global filtering
            if ((!empty($globalSearch) || $globalSearch['value'] == '0') && $columns[$i]['searchable'] === "true") {

                $qbParam = "sSearch_global_" . $i;

                if ($this->isStringDQLQuery($searchField)) {

                    $orExpr->add(
                            $queryBuilder->expr()->eq($searchField, ':' . $qbParam)
                    );
                    $queryBuilder->setParameter($qbParam, $globalSearch['value']);

                } else {

                    $orExpr->add($queryBuilder->expr()->like($searchField, ":" . $qbParam));
                    $queryBuilder->setParameter($qbParam, "%" . $globalSearch['value'] . "%");

                }
            }

            // Individual filtering
            $searchName = "sSearch_" . $i;

            if($columns[$i]['searchable'] === "true" && $columns[$i]['search']['value'] != "") {

                $queryBuilder->andWhere($queryBuilder->expr()->like($searchField, ":" . $searchName));

                if (array_key_exists($i, $filteringType)) {
                    switch ($filteringType[$i]) {
                        case 's':
                            $queryBuilder->setParameter($searchName, $columns[$i]['search']['value']);
                            break;
                        case 'f':
                            $queryBuilder->setParameter($searchName, sprintf("%%%s%%", $columns[$i]['search']['value']));
                            break;
                        case 'b':
                            $queryBuilder->setParameter($searchName, sprintf("%%%s", $columns[$i]['search']['value']));
                            break;
                        case 'e':
                            $queryBuilder->setParameter($searchName, sprintf("%s%%", $columns[$i]['search']['value']));
                            break;
                    }
                } else {
                    $queryBuilder->setParameter($searchName, sprintf("%%%s%%", $columns[$i]['search']['value']));
                }
            }
        }

        if ((!empty($globalSearch) || $globalSearch == '0') && $orExpr->count() > 0) {
            $queryBuilder->andWhere($orExpr);
        }
    }
784327
private function makeArrayQueryIn(Builder $query, stdClass $rule, $operator, array $value, $condition)
    {
        if ($operator == 'NOT IN') {
            return $query->whereNotIn($rule->field, $value, $condition);
        }

        return $query->whereIn($rule->field, $value, $condition);
    }
203627
public function applyFilters(QueryBuilder $qb)
    {
        foreach ($this->getFilters() as $filter) {

            $type = null;
            $placeholder = $filter['valuePlaceholder'];
            if (is_array($filter['value'])) {
                $type = Connection::PARAM_STR_ARRAY;
                $filter['valuePlaceholder'] = '(' . $placeholder . ')';
            }

            $qb->andWhere($filter['column'] .' '. $filter['operator'] .' '. $filter['valuePlaceholder'])
                ->setParameter($placeholder, $filter['value'], $type);
        }

        return $qb;
    }
1049743
protected function getQueryBuilder(array $filters = [], array $sorting = [])
    {
        $queryBuilder = $this->getBaseQueryBuilder();
        if (!empty($filters)) {
            $this->addFilters($queryBuilder, $filters);
        }

        if (empty($sorting)) {
            $this->addSorting($queryBuilder, $this->getDefaultSorting());
        } else {
            $this->addSorting($queryBuilder, $sorting);
        }

        return $queryBuilder;
    }
1063337
public function getFilter(QueryBuilder $qb, $dqlAlias)
    {
        if (null !== $this->dqlAlias) {
            $dqlAlias = $this->dqlAlias;
        }

        $field = ArgumentToOperandConverter::toField($this->field);
        $value = ArgumentToOperandConverter::toValue($this->value);

        return (string) new DoctrineComparison(
            $field->transform($qb, $dqlAlias),
            $this->operator,
            $value->transform($qb, $dqlAlias)
        );
    }
646152
public function adaptQueryBuilder(QueryBuilder $queryBuilder, array $params = array())
    {
        parent::adaptQueryBuilder($queryBuilder);
        $queryBuilder
                ->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id')
                ->andWhere('n.id = :node')
                ->andWhere('b.lang = :lang')
                ->setParameter('node', $this->nodeTranslation->getNode()->getId())
                ->setParameter('lang', $this->nodeTranslation->getLang())
                ->addOrderBy('b.created', 'DESC');
    }
227261
public function getFilter(QueryBuilder $qb, $dqlAlias)
    {
        $children = [];
        foreach ($this->children as $spec) {
            if ($spec instanceof Filter) {
                $children[] = $spec->getFilter($qb, $dqlAlias);
            }
        }

        return call_user_func_array(array($qb->expr(), $this->expression), $children);
    }
460249
public function setupQb(QueryBuilder $qb, $filters)
    {
        $this->qb = $qb;
        $this->c = 0;
        $this->bind = array();

        $filters = $this->_unify($filters);

        $this->_setupOrderyBy($qb, $filters['orderby']);

        $this->_setFilters($qb, $filters['filters']);

        $filters['offset'] and $qb->setFirstResult($filters['offset']);

        $filters['limit'] and $qb->setMaxResults($filters['limit']);

        return $qb;
    }