Allowed to get count query from paginator.
This commit is contained in:
parent
705c33bc35
commit
ae198d5e45
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user