From 18bfd6605de3d2d888d07baff8fdceba86bc8aeb Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 16 Feb 2014 18:19:04 +0100 Subject: [PATCH] Searching: more robust entity counting --- src/Models/SearchServices/AbstractSearchService.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Models/SearchServices/AbstractSearchService.php b/src/Models/SearchServices/AbstractSearchService.php index b8456494..64f91ffd 100644 --- a/src/Models/SearchServices/AbstractSearchService.php +++ b/src/Models/SearchServices/AbstractSearchService.php @@ -21,7 +21,7 @@ abstract class AbstractSearchService $sqlQuery->offset('?')->put(($page - 1) * $perPage); } - static function getEntitiesRows($searchQuery, $perPage = null, $page = 1) + public static function getEntitiesRows($searchQuery, $perPage = null, $page = 1) { $modelClassName = self::getModelClassName(); $table = $modelClassName::getTableName(); @@ -35,21 +35,23 @@ abstract class AbstractSearchService return $rows; } - static function getEntities($searchQuery, $perPage = null, $page = 1) + public static function getEntities($searchQuery, $perPage = null, $page = 1) { $modelClassName = self::getModelClassName(); $rows = static::getEntitiesRows($searchQuery, $perPage, $page); return $modelClassName::convertRows($rows); } - static function getEntityCount($searchQuery) + public static function getEntityCount($searchQuery) { $modelClassName = self::getModelClassName(); $table = $modelClassName::getTableName(); $sqlQuery = new SqlQuery(); $sqlQuery->select('count(1)')->as('count'); + $sqlQuery->from()->raw('(')->select('1'); static::decorate($sqlQuery, $searchQuery); + $sqlQuery->raw(')'); return Database::fetchOne($sqlQuery)['count']; }