1
0
mirror of synced 2025-02-09 00:39:25 +03:00

Allowed to get count query from paginator.

This commit is contained in:
Merixstudio 2014-11-24 15:27:15 +01:00 committed by Marco Pivetta
parent 705c33bc35
commit ae198d5e45

View File

@ -118,6 +118,20 @@ class Paginator implements \Countable, \IteratorAggregate
public function count()
{
if ($this->count === null) {
$countQuery = $this->getCountQuery();
try {
$data = $countQuery->getScalarResult();
$data = array_map('current', $data);
$this->count = array_sum($data);
} catch(NoResultException $e) {
$this->count = 0;
}
}
return $this->count;
}
public function getCountQuery(){
/* @var $countQuery Query */
$countQuery = $this->cloneQuery($this->query);
@ -138,8 +152,6 @@ class Paginator implements \Countable, \IteratorAggregate
}
$countQuery->setFirstResult(null)->setMaxResults(null);
try {
$parser = new Query\Parser($countQuery);
$parameterMappings = $parser->parse($parser)->getParameterMappings();
$parameters = $countQuery->getParameters();
@ -149,16 +161,7 @@ class Paginator implements \Countable, \IteratorAggregate
}
}
$countQuery->setParameters($parameters);
$data = $countQuery->getScalarResult();
$data = array_map('current', $data);
$this->count = array_sum($data);
} catch(NoResultException $e) {
$this->count = 0;
}
}
return $this->count;
return $countQuery;
}
/**