/** * @param \Kdyby\Persistence\Queryable $repository * @param ResultSet $resultSet * @param \Doctrine\ORM\Tools\Pagination\Paginator $paginatedQuery * @return integer */ public function count(Queryable $repository, ResultSet $resultSet = NULL, Paginator $paginatedQuery = NULL) { if ($query = $this->doCreateCountQuery($repository)) { return (int) $this->toQuery($query)->getSingleScalarResult(); } if ($this->lastQuery && $this->lastQuery instanceof NativeQueryWrapper) { $class = get_called_class(); throw new NotSupportedException("You must implement your own count query in {$class}::doCreateCountQuery(), Paginator from Doctrine doesn't support NativeQueries."); } if ($paginatedQuery !== NULL) { return $paginatedQuery->count(); } $query = $this->getQuery($repository)->setFirstResult(NULL)->setMaxResults(NULL); $paginatedQuery = new Paginator($query, $resultSet ? $resultSet->getFetchJoinCollection() : TRUE); $paginatedQuery->setUseOutputWalkers($resultSet ? $resultSet->getUseOutputWalkers() : NULL); return $paginatedQuery->count(); }