本文整理汇总了PHP中Doctrine\ORM\EntityRepository::countBy方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityRepository::countBy方法的具体用法?PHP EntityRepository::countBy怎么用?PHP EntityRepository::countBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\EntityRepository
的用法示例。
在下文中一共展示了EntityRepository::countBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: countBy
/**
* countBy
*
* @param array $criteria
* @access public
* @return void
*/
public function countBy(array $criteria)
{
if (!$this->getInterfaceCriteriaParser()) {
if (method_exists(get_parent_class($this), 'conutBy')) {
return parent::countBy($criteria);
}
throw new \Exception('EntityRepository does not support method "countBy". Please overwrite this method.');
}
$query = $this->createInterfaceQuery($criteria, array(), null, null);
$nativeQuery = $query->getNativeQuery();
// Check Composite Key or not
if ($this->getClassMetadata()->isIdentifierComposite) {
// Select COUNT
if (!$nativeQuery->getHint(\Doctrine\ORM\Tools\Pagination\CountOutputWalker::HINT_DISTINCT)) {
$nativeQuery->setHint(\Doctrine\ORM\Tools\Pagination\CountOutputWalker::HINT_DISTINCT, true);
}
$platform = $nativeQuery->getEntityManager()->getConnection()->getDatabasePlatform();
// law of demeter win
$rsm = new ResultSetMapping();
$rsm->addScalarResult($platform->getSQLResultCasing('dctrn_count'), 'count');
$nativeQuery->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\\ORM\\Tools\\Pagination\\CountOutputWalker');
$nativeQuery->setResultSetMapping($rsm);
} else {
// Set Distinct
if (!$nativeQuery->getHint(\Doctrine\ORM\Tools\Pagination\CountWalker::HINT_DISTINCT)) {
$nativeQuery->setHint(\Doctrine\ORM\Tools\Pagination\CountWalker::HINT_DISTINCT, true);
}
// Select COUNT
$nativeQuery->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_TREE_WALKERS, array('Doctrine\\ORM\\Tools\\Pagination\\CountWalker'));
}
$nativeQuery->setFirstResult(null)->setMaxResults(null);
// Convert to CountQuery
return $nativeQuery->getSingleScalarResult();
}