Merge pull request #33 from PapaBearNZ/search-engine-patch-1.1

FIX Total Items count on Search
This commit is contained in:
Daniel Hensby 2015-06-14 20:47:12 +01:00
commit 606879243a

View File

@ -1886,12 +1886,14 @@ class PostgreSQLDatabase extends SS_Database {
$fullQuery = "SELECT * FROM (" . implode(" UNION ", $tables) . ") AS q1 $orderBy LIMIT $limit OFFSET $offset";
// Get the total items in this search
$totalItemsQuery = "SELECT COUNT(*) AS totalitems FROM (" . implode(" UNION ", $tables) . ") AS q1";
$totalCount = DB::query($totalItemsQuery);
// Get records
$records = DB::query($fullQuery);
$totalCount=0;
foreach($records as $record){
$objects[] = new $record['ClassName']($record);
$totalCount++;
}
if(isset($objects)) $results = new ArrayList($objects);
@ -1900,7 +1902,7 @@ class PostgreSQLDatabase extends SS_Database {
$list->setLimitItems(false);
$list->setPageStart($start);
$list->setPageLength($pageLength);
$list->setTotalItems($totalCount);
$list->setTotalItems($totalCount->value());
return $list;
}