Skip to content

Commit

Permalink
#1188 - making `Doctrine\ORM\Tools\Pagination\Paginator#getCountQuery…
Browse files Browse the repository at this point in the history
…()` private, as it is an implementation detail
  • Loading branch information
Ocramius committed Nov 27, 2014
1 parent a80117a commit 69064ac
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions lib/Doctrine/ORM/Tools/Pagination/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,44 +127,6 @@ public function count()

return $this->count;
}
/**
* Returns Query prepared to count.
*
* @return Query
*/
public function getCountQuery()
{
/* @var $countQuery Query */
$countQuery = $this->cloneQuery($this->query);

if ( ! $countQuery->hasHint(CountWalker::HINT_DISTINCT)) {
$countQuery->setHint(CountWalker::HINT_DISTINCT, true);
}

if ($this->useOutputWalker($countQuery)) {
$platform = $countQuery->getEntityManager()->getConnection()->getDatabasePlatform(); // law of demeter win

$rsm = new ResultSetMapping();
$rsm->addScalarResult($platform->getSQLResultCasing('dctrn_count'), 'count');

$countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
$countQuery->setResultSetMapping($rsm);
} else {
$this->appendTreeWalker($countQuery, 'Doctrine\ORM\Tools\Pagination\CountWalker');
}

$countQuery->setFirstResult(null)->setMaxResults(null);
$parser = new Query\Parser($countQuery);
$parameterMappings = $parser->parse()->getParameterMappings();
$parameters = $countQuery->getParameters();
foreach ($parameters as $k => $param){
if( ! array_key_exists($param->getName(), $parameterMappings)) {
$parameters->remove($k);
}
}
$countQuery->setParameters($parameters);
return $countQuery;
}

/**
* {@inheritdoc}
Expand Down Expand Up @@ -267,4 +229,44 @@ private function appendTreeWalker(Query $query, $walkerClass)
$hints[] = $walkerClass;
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $hints);
}

/**
* Returns Query prepared to count.
*
* @return Query
*/
private function getCountQuery()
{
/* @var $countQuery Query */
$countQuery = $this->cloneQuery($this->query);

if ( ! $countQuery->hasHint(CountWalker::HINT_DISTINCT)) {
$countQuery->setHint(CountWalker::HINT_DISTINCT, true);
}

if ($this->useOutputWalker($countQuery)) {
$platform = $countQuery->getEntityManager()->getConnection()->getDatabasePlatform(); // law of demeter win

$rsm = new ResultSetMapping();
$rsm->addScalarResult($platform->getSQLResultCasing('dctrn_count'), 'count');

$countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\CountOutputWalker');
$countQuery->setResultSetMapping($rsm);
} else {
$this->appendTreeWalker($countQuery, 'Doctrine\ORM\Tools\Pagination\CountWalker');
}

$countQuery->setFirstResult(null)->setMaxResults(null);

$parser = new Query\Parser($countQuery);
$parameterMappings = $parser->parse()->getParameterMappings();
$parameters = $countQuery->getParameters();
foreach ($parameters as $k => $param){
if( ! array_key_exists($param->getName(), $parameterMappings)) {
$parameters->remove($k);
}
}
$countQuery->setParameters($parameters);
return $countQuery;
}
}

0 comments on commit 69064ac

Please sign in to comment.