Programming Language PHP

Namespace Oro\Component\DoctrineUtils\ORM

Class QueryUtil

Method/Function resetResultSetMapping

Total Examples 1

1 code examples of PHP Oro\Component\DoctrineUtils\ORM\QueryUtil::resetResultSetMapping extracted from open source projects

Was this example useful?
0
                                                    private function executeOrmCountQueryUsingCountWalker(Query $query): int
    {
        $countQuery = QueryUtil::cloneQuery($query);
        if (null !== $this->shouldUseDistinct) {
            $countQuery->setHint(CountWalker::HINT_DISTINCT, $this->shouldUseDistinct);
        } elseif (!$countQuery->hasHint(CountWalker::HINT_DISTINCT)) {
            $countQuery->setHint(CountWalker::HINT_DISTINCT, $countQuery->contains('DISTINCT'));
        }
        QueryUtil::addTreeWalker($countQuery, CountWalker::class);
        $this->unbindUnusedQueryParams($countQuery, QueryUtil::parseQuery($countQuery));
        $countQuery->setFirstResult(null)->setMaxResults(null);
        // the result-set mapping is not relevant and should be rebuilt because the query is be changed
        QueryUtil::resetResultSetMapping($countQuery);

        try {
            return array_sum(array_map('current', $countQuery->getScalarResult()));
        } catch (NoResultException $e) {
            return 0;
        }
    }