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()
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user