src/Utilities/QueryBuilderUtility.php
public static function setCriteria(QueryBuilder $queryBuilder, array $criteria = [], $alias = null)
    {
        /*
         * No criteria used in WHERE clause?
         * Nothing to do
         */
        if (empty($criteria)) {
            return $queryBuilder;
        }

        /*
         * No alias provided?
         * Let's use root alias
         */
        if (null === $alias || '' === $alias) {
            $alias = self::getRootAlias($queryBuilder);
        }

        foreach ($criteria as $column => $value) {
            $compareOperator = '=';

            if (is_array($value) && !empty($value)) {
                if (2 === count($value)) {
                    $compareOperator = $value[1];
                }

                $value = $value[0];
            }

            $predicate = sprintf('%s.%s %s :%s', $alias, $column, $compareOperator, $column);

            if (null === $value) {
                $predicate = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $column));
                unset($criteria[$column]);
            } else {
                $queryBuilder->setParameter($column, $value);
            }

            $queryBuilder = $queryBuilder->andWhere($predicate);
        }

        return $queryBuilder;
    }
public static function setCriteria(QueryBuilder $queryBuilder, array $criteria = [], $alias = null)
    {
        /*
         * No criteria used in WHERE clause?
         * Nothing to do
         */
        if (empty($criteria)) {
            return $queryBuilder;
        }

        /*
         * No alias provided?
         * Let's use root alias
         */
        if (null === $alias || '' === $alias) {
            $alias = self::getRootAlias($queryBuilder);
        }

        foreach ($criteria as $column => $value) {
            $compareOperator = '=';

            if (is_array($value) && !empty($value)) {
                if (2 === count($value)) {
                    $compareOperator = $value[1];
                }

                $value = $value[0];
            }

            $predicate = sprintf('%s.%s %s :%s', $alias, $column, $compareOperator, $column);

            if (null === $value) {
                $predicate = $queryBuilder->expr()->isNull(sprintf('%s.%s', $alias, $column));
                unset($criteria[$column]);
            } else {
                $queryBuilder->setParameter($column, $value);
            }

            $queryBuilder = $queryBuilder->andWhere($predicate);
        }

        return $queryBuilder;
    }
public static function setCriteria ( QueryBuilder $ queryBuilder , array $ criteria = [ ] , $ alias = null ) { /*
         * No criteria used in WHERE clause?
         * Nothing to do
         */ if ( empty ( $ criteria ) ) { return $ queryBuilder ; } /*
         * No alias provided?
         * Let's use root alias
         */ if ( null === $ alias || '' === $ alias ) { $ alias = self :: getRootAlias ( $ queryBuilder ) ; } foreach ( $ criteria as $ column => $ value ) { $ compareOperator = '=' ; if ( is_array ( $ value ) && ! empty ( $ value ) ) { if ( 2 === count ( $ value ) ) { $ compareOperator = $ value [ 1 ] ; } $ value = $ value [ 0 ] ; } $ predicate = sprintf ( '%s.%s %s :%s' , $ alias , $ column , $ compareOperator , $ column ) ; if ( null === $ value ) { $ predicate = $ queryBuilder -> expr ( ) -> isNull ( sprintf ( '%s.%s' , $ alias , $ column ) ) ; unset ( $ criteria [ $ column ] ) ; } else { $ queryBuilder -> setParameter ( $ column , $ value ) ; } $ queryBuilder = $ queryBuilder -> andWhere ( $ predicate ) ; } return $ queryBuilder ; }
Sets the WHERE criteria in given query builder

@param QueryBuilder $queryBuilder The query builder
@param array        $criteria     (optional) The criteria used in WHERE clause. It may simple array with pairs
key-value or an array of arrays where second element of sub-array is the
comparison operator. Example below.
@param null|string  $alias        (optional) Alias used in the query
@return QueryBuilder

Example of the $criteria argument:
[
'created_at' => [
'2012-11-17 20:00',
'<'
],
'title' => [
'%test%',
'like'
],
'position' => 5,
]
Sets the WHERE criteria in given query builder