1
0
mirror of synced 2025-02-13 02: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() public function count()
{ {
if ($this->count === null) { 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 */ /* @var $countQuery Query */
$countQuery = $this->cloneQuery($this->query); $countQuery = $this->cloneQuery($this->query);
@ -138,8 +152,6 @@ class Paginator implements \Countable, \IteratorAggregate
} }
$countQuery->setFirstResult(null)->setMaxResults(null); $countQuery->setFirstResult(null)->setMaxResults(null);
try {
$parser = new Query\Parser($countQuery); $parser = new Query\Parser($countQuery);
$parameterMappings = $parser->parse($parser)->getParameterMappings(); $parameterMappings = $parser->parse($parser)->getParameterMappings();
$parameters = $countQuery->getParameters(); $parameters = $countQuery->getParameters();
@ -149,16 +161,7 @@ class Paginator implements \Countable, \IteratorAggregate
} }
} }
$countQuery->setParameters($parameters); $countQuery->setParameters($parameters);
return $countQuery;
$data = $countQuery->getScalarResult();
$data = array_map('current', $data);
$this->count = array_sum($data);
} catch(NoResultException $e) {
$this->count = 0;
}
}
return $this->count;
} }
/** /**