protected function getQueryResultCount(Select $query)
    {
        $queryString = $this->getSqlObject()->getSqlStringForSqlObject($query, $this->dbAdapter->getPlatform());

        $format = 'Select count(*) as `count` from (%s) as `query_count`';

        $countQueryString = sprintf($format, $queryString);

        $countQuery = $this->dbAdapter->query($countQueryString);

        $result = $countQuery->execute()->current();

        return (int) Arr::get($result, 'count');
    }