src/ORM/Search/SearchContext.php
public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null)
    {
        /** DataList $query */
        $query = null;
        if ($existingQuery) {
            if (!($existingQuery instanceof DataList)) {
                throw new InvalidArgumentException("existingQuery must be DataList");
            }
            if ($existingQuery->dataClass() != $this->modelClass) {
                throw new InvalidArgumentException("existingQuery's dataClass is " . $existingQuery->dataClass()
                    . ", $this->modelClass expected.");
            }
            $query = $existingQuery;
        } else {
            $query = DataList::create($this->modelClass);
        }

        if (is_array($limit)) {
            $query = $query->limit(
                isset($limit['limit']) ? $limit['limit'] : null,
                isset($limit['start']) ? $limit['start'] : null
            );
        } else {
            $query = $query->limit($limit);
        }

        /** @var DataList $query */
        $query = $query->sort($sort);
        $this->setSearchParams($searchParams);

        foreach ($this->searchParams as $key => $value) {
            $key = str_replace('__', '.', $key);
            if ($filter = $this->getFilter($key)) {
                $filter->setModel($this->modelClass);
                $filter->setValue($value);
                if (!$filter->isEmpty()) {
                    $query = $query->alterDataQuery(array($filter, 'apply'));
                }
            }
        }

        if ($this->connective != "AND") {
            throw new Exception("SearchContext connective '$this->connective' not supported after ORM-rewrite.");
        }

        return $query;
    }
public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null)
    {
        /** DataList $query */
        $query = null;
        if ($existingQuery) {
            if (!($existingQuery instanceof DataList)) {
                throw new InvalidArgumentException("existingQuery must be DataList");
            }
            if ($existingQuery->dataClass() != $this->modelClass) {
                throw new InvalidArgumentException("existingQuery's dataClass is " . $existingQuery->dataClass()
                    . ", $this->modelClass expected.");
            }
            $query = $existingQuery;
        } else {
            $query = DataList::create($this->modelClass);
        }

        if (is_array($limit)) {
            $query = $query->limit(
                isset($limit['limit']) ? $limit['limit'] : null,
                isset($limit['start']) ? $limit['start'] : null
            );
        } else {
            $query = $query->limit($limit);
        }

        /** @var DataList $query */
        $query = $query->sort($sort);
        $this->setSearchParams($searchParams);

        foreach ($this->searchParams as $key => $value) {
            $key = str_replace('__', '.', $key);
            if ($filter = $this->getFilter($key)) {
                $filter->setModel($this->modelClass);
                $filter->setValue($value);
                if (!$filter->isEmpty()) {
                    $query = $query->alterDataQuery(array($filter, 'apply'));
                }
            }
        }

        if ($this->connective != "AND") {
            throw new Exception("SearchContext connective '$this->connective' not supported after ORM-rewrite.");
        }

        return $query;
    }
public function getQuery ( $ searchParams , $ sort = false , $ limit = false , $ existingQuery = null ) { /** DataList $query */ $ query = null ; if ( $ existingQuery ) { if ( ! ( $ existingQuery instanceof DataList ) ) { throw new InvalidArgumentException ( "existingQuery must be DataList" ) ; } if ( $ existingQuery -> dataClass ( ) != $ this -> modelClass ) { throw new InvalidArgumentException ( "existingQuery's dataClass is " . $ existingQuery -> dataClass ( ) . ", $this->modelClass expected." ) ; } $ query = $ existingQuery ; } else { $ query = DataList :: create ( $ this -> modelClass ) ; } if ( is_array ( $ limit ) ) { $ query = $ query -> limit ( isset ( $ limit [ 'limit' ] ) ? $ limit [ 'limit' ] : null , isset ( $ limit [ 'start' ] ) ? $ limit [ 'start' ] : null ) ; } else { $ query = $ query -> limit ( $ limit ) ; } /** @var DataList $query */ $ query = $ query -> sort ( $ sort ) ; $ this -> setSearchParams ( $ searchParams ) ; foreach ( $ this -> searchParams as $ key => $ value ) { $ key = str_replace ( '__' , '.' , $ key ) ; if ( $ filter = $ this -> getFilter ( $ key ) ) { $ filter -> setModel ( $ this -> modelClass ) ; $ filter -> setValue ( $ value ) ; if ( ! $ filter -> isEmpty ( ) ) { $ query = $ query -> alterDataQuery ( array ( $ filter , 'apply' ) ) ; } } } if ( $ this -> connective != "AND" ) { throw new Exception ( "SearchContext connective '$this->connective' not supported after ORM-rewrite." ) ; } return $ query ; }
Returns a SQL object representing the search context for the given
list of query parameters.

@param array $searchParams Map of search criteria, mostly taken from $_REQUEST.
If a filter is applied to a relationship in dot notation,
the parameter name should have the dots replaced with double underscores,
for example "Comments__Name" instead of the filter name "Comments.Name".
@param array|bool|string $sort Database column to sort on.
Falls back to {@link DataObject::$default_sort} if not provided.
@param array|bool|string $limit
@param DataList $existingQuery
@return DataList
@throws Exception
Returns a SQL object representing the search context for the given list of query parameters .