Skip to content

Commit

Permalink
BUGFIX DataList used in SearchContext::getQuery() should be returned …
Browse files Browse the repository at this point in the history
…so limit() and sort() are applied correctly
  • Loading branch information
Sean Harvey committed Jun 15, 2012
1 parent b04c199 commit 8b83487
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions search/SearchContext.php
Expand Up @@ -115,20 +115,22 @@ protected function applyBaseTableFields() {
* @return DataList
*/
public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = 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->limit(isset($limit['limit']) ? $limit['limit'] : null, isset($limit['start']) ? $limit['start'] : null);
else $query->limit($limit);

$query->sort($sort);

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);
}

$query = $query->sort($sort);

// hack to work with $searchParems when it's an Object
$searchParamArray = array();
if (is_object($searchParams)) {
Expand Down

0 comments on commit 8b83487

Please sign in to comment.