Programming Language PHP

Namespace Oro\Component\DoctrineUtils\ORM

Class QueryUtil

Method/Function addTreeWalker

Total Examples 5

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

Was this example useful?
0
                                                    /**
     * Protects a query by ACL.
     *
     * @param Query|QueryBuilder $query      The query to be protected
     * @param string             $permission The permission to apply
     * @param array              $options    Additional options for access rules.
     *                                       The following options are implemented out-of-the-box:
     *                                       * "checkRootEntity" determined whether the root entity should be
     *                                         protected; default value is TRUE
     *                                       * "checkRelations" determined whether entities associated with
     *                                         the root entity should be protected; default value is TRUE
     *                                       To find all possible options see classes that implement
     *                                       Oro\Bundle\SecurityBundle\AccessRule\AccessRuleInterface
     */
    public function apply($query, string $permission = 'VIEW', array $options = []): Query
    {
        $context = $this->contextFactory->createContext($permission);
        foreach ($options as $optionName => $value) {
            $context->setOption($optionName, $value);
        }

        if ($query instanceof QueryBuilder) {
            $query = $query->getQuery();
        }

        QueryUtil::addTreeWalker($query, AccessRuleWalker::class);
        $query->setHint(AccessRuleWalker::CONTEXT, $context);

        return $query;
    }
                                            
Was this example useful?
0
                                                    /**
     * @inheritdoc
     */
    public function initializeIdentityQuery(Query $query)
    {
        $identifierHydrationMode = 'IdentifierHydrator';
        $query
            ->getEntityManager()
            ->getConfiguration()
            ->addCustomHydrationMode($identifierHydrationMode, IdentifierHydrator::class);

        $query->setHydrationMode($identifierHydrationMode);

        QueryUtil::addTreeWalker($query, ReduceOrderByWalker::class);
        QueryUtil::addTreeWalker($query, SelectIdentifierWalker::class);
    }
                                            
Was this example useful?
0
                                                    /**
     * @inheritdoc
     */
    public function initializeDataQuery(Query $query)
    {
        QueryUtil::addTreeWalker($query, LimitIdentifierWalker::class);

        // limit and offset implemented with ids
        $query->setFirstResult(null);
        $query->setMaxResults(null);
    }
                                            
Was this example useful?
0
                                                    /**
     * @inheritdoc
     */
    public function initializeIdentityQuery(Query $query)
    {
        $identifierHydrationMode = 'IdentifierHydrator';
        $query
            ->getEntityManager()
            ->getConfiguration()
            ->addCustomHydrationMode($identifierHydrationMode, IdentifierHydrator::class);

        $query->setHydrationMode($identifierHydrationMode);

        QueryUtil::addTreeWalker($query, SelectIdentifierWalker::class);
    }
                                            
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;
        }
    }