当前位置: 首页>>代码示例>>PHP>>正文


PHP QueryBuilder::getRootEntities方法代码示例

本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::getRootEntities方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::getRootEntities方法的具体用法?PHP QueryBuilder::getRootEntities怎么用?PHP QueryBuilder::getRootEntities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder::getRootEntities方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addJoins

 /**
  * Add completeness joins to query builder
  *
  * @param string $completenessAlias the join alias
  * @param string $locale            the locale
  * @param sting  $scope             the scope
  *
  * @return CompletenessJoin
  */
 public function addJoins($completenessAlias, $locale, $scope)
 {
     $rootAlias = $this->qb->getRootAlias();
     $localeAlias = $completenessAlias . 'Locale';
     $channelAlias = $completenessAlias . 'Channel';
     $rootEntity = current($this->qb->getRootEntities());
     $completenessMapping = $this->qb->getEntityManager()->getClassMetadata($rootEntity)->getAssociationMapping('completenesses');
     $completenessClass = $completenessMapping['targetEntity'];
     $this->qb->leftJoin('PimCatalogBundle:Locale', $localeAlias, 'WITH', $localeAlias . '.code = :cLocaleCode')->leftJoin('PimCatalogBundle:Channel', $channelAlias, 'WITH', $channelAlias . '.code = :cScopeCode')->leftJoin($completenessClass, $completenessAlias, 'WITH', $completenessAlias . '.locale = ' . $localeAlias . '.id AND ' . $completenessAlias . '.channel = ' . $channelAlias . '.id AND ' . $completenessAlias . '.product = ' . $rootAlias . '.id')->setParameter('cLocaleCode', $locale)->setParameter('cScopeCode', $scope);
     return $this;
 }
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:20,代码来源:CompletenessJoin.php

示例2: resetBuilder

 protected function resetBuilder()
 {
     $rootEntities = $this->qb->getRootEntities();
     $this->qb = $this->qb->getEntityManager()->getRepository($rootEntities[0])->createQueryBuilder('x');
     $this->joinAliases = [];
     $this->parametersMap = [];
     $this->orderBy = [];
 }
开发者ID:bitecodes,项目名称:doctrine-filter,代码行数:8,代码来源:FilterBuilder.php

示例3: addJoins

 /**
  * Add completeness joins to query builder
  *
  * @param string $completenessAlias the join alias
  * @param string $locale            the locale
  * @param string $scope             the scope
  *
  * @return CompletenessJoin
  */
 public function addJoins($completenessAlias, $locale, $scope)
 {
     $rootAlias = $this->qb->getRootAliases()[0];
     $localeAlias = $completenessAlias . 'Locale';
     $channelAlias = $completenessAlias . 'Channel';
     $rootEntity = $this->qb->getRootEntities()[0];
     $completenessMapping = $this->qb->getEntityManager()->getClassMetadata($rootEntity)->getAssociationMapping('completenesses');
     $completenessClass = $completenessMapping['targetEntity'];
     $joinCondition = sprintf('%s.product = %s.id', $completenessAlias, $rootAlias);
     $this->qb->leftJoin('PimCatalogBundle:Channel', $channelAlias, 'WITH', $channelAlias . '.code = :cScopeCode')->setParameter('cScopeCode', $scope);
     $joinCondition .= sprintf(' AND %s.channel = %s.id', $completenessAlias, $channelAlias);
     if (null !== $locale) {
         $this->qb->leftJoin('PimCatalogBundle:Locale', $localeAlias, 'WITH', sprintf('%s.code = :%scLocaleCode', $localeAlias, $localeAlias))->setParameter($localeAlias . 'cLocaleCode', $locale);
         $joinCondition .= sprintf(' AND %s.locale = %s.id', $completenessAlias, $localeAlias);
     }
     $this->qb->leftJoin($completenessClass, $completenessAlias, 'WITH', $joinCondition);
     return $this;
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:27,代码来源:CompletenessJoin.php

示例4: __construct

 /**
  * @param QueryBuilder      $queryBuilder
  * @param QueryBuilderTools $qbTools
  */
 public function __construct(QueryBuilder $queryBuilder, QueryBuilderTools $qbTools)
 {
     // make sure 'from' DQL part is initialized for both original and optimized query builders
     $queryBuilder->getRootEntities();
     $this->originalQueryBuilder = $queryBuilder;
     $this->qbTools = $qbTools;
     // initialize the query builder helper
     $this->qbTools->prepareFieldAliases($this->originalQueryBuilder->getDQLPart('select'));
     $this->qbTools->prepareJoinTablePaths($this->originalQueryBuilder->getDQLPart('join'));
 }
开发者ID:Maksold,项目名称:platform,代码行数:14,代码来源:QueryOptimizationContext.php

示例5: hasRootEntityWithIdentifier

 /**
  * Detects if the root entity has the given identifier.
  *
  * @param QueryBuilder    $queryBuilder
  * @param ManagerRegistry $managerRegistry
  * @param bool            $isForeign
  *
  * @return bool
  */
 private static function hasRootEntityWithIdentifier(QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry, bool $isForeign) : bool
 {
     foreach ($queryBuilder->getRootEntities() as $rootEntity) {
         $rootMetadata = $managerRegistry->getManagerForClass($rootEntity)->getClassMetadata($rootEntity);
         if ($isForeign ? $rootMetadata->isIdentifierComposite : $rootMetadata->containsForeignIdentifier) {
             return true;
         }
     }
     return false;
 }
开发者ID:api-platform,项目名称:core,代码行数:19,代码来源:QueryChecker.php

示例6: hasRootEntityWithForeignKeyIdentifier

 /**
  * Determines whether the query builder has any root entity with foreign key identifier.
  *
  * @param QueryBuilder    $queryBuilder
  * @param ManagerRegistry $managerRegistry
  *
  * @return bool
  */
 public static function hasRootEntityWithForeignKeyIdentifier(QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry)
 {
     foreach ($queryBuilder->getRootEntities() as $rootEntity) {
         $rootMetadata = $managerRegistry->getManagerForClass($rootEntity)->getClassMetadata($rootEntity);
         if ($rootMetadata->containsForeignIdentifier) {
             return true;
         }
     }
     return false;
 }
开发者ID:akomm,项目名称:DunglasApiBundle,代码行数:18,代码来源:QueryChecker.php

示例7: getAllClassesForQueryBuilder

 public function getAllClassesForQueryBuilder(QueryBuilder $queryBuilder) : array
 {
     $classes = [];
     $rootEntities = $queryBuilder->getRootEntities();
     foreach ($rootEntities as $rootEntity) {
         $classes[$rootEntity] = $rootEntity;
         $metadata = $this->getClassMetadata($rootEntity);
         $this->addAssociationsTargetClasses($metadata, $classes);
     }
     return $classes;
 }
开发者ID:WellCommerce,项目名称:DoctrineBundle,代码行数:11,代码来源:DoctrineHelper.php

示例8: ensureInitialized

 /**
  * Ensure that filtering applied and query builder wrapped in buffered iterator
  * if data source is query builder or just an entity name
  *
  * @param ContextInterface $context
  */
 protected function ensureInitialized(ContextInterface $context)
 {
     if (null !== $this->qb) {
         if ($context->hasOption(self::ID_FILTER)) {
             $optionValue = $context->getOption(self::ID_FILTER);
             $em = $this->qb->getEntityManager();
             $entityNames = $this->qb->getRootEntities();
             $classMetadata = $em->getClassMetadata(reset($entityNames));
             $identifier = $classMetadata->getSingleIdentifierFieldName();
             if (is_array($optionValue)) {
                 $this->qb->andWhere($this->qb->expr()->in('o.' . $identifier, ':id'));
                 $this->qb->setParameter('id', $optionValue);
             } else {
                 $this->qb->andWhere('o.' . $identifier . ' = :id');
             }
             $this->qb->setParameter('id', $optionValue);
         }
         $this->setSourceIterator(new BufferedQueryResultIterator($this->qb));
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:26,代码来源:EntityReaderById.php

示例9: addJoinsToQueryBuilder

 private function addJoinsToQueryBuilder($alias, QueryBuilder $qb, $className, $recursive = true)
 {
     foreach ($this->getEntityManager()->getClassMetadata($className)->getAssociationMappings() as $assoc) {
         if (in_array($assoc['targetEntity'], $qb->getRootEntities()) || $className === $assoc['targetEntity']) {
             continue;
         }
         $uniqueJoinAlias = $this->getUniqueAlias($assoc['targetEntity'], $qb);
         $qb->addSelect($uniqueJoinAlias)->leftJoin(sprintf('%s.%s', $alias, $assoc['fieldName']), $uniqueJoinAlias);
         if ($recursive) {
             $this->addJoinsToQueryBuilder($uniqueJoinAlias, $qb, $assoc['targetEntity']);
         }
     }
 }
开发者ID:adampiotrowski,项目名称:DoctrineBehaviors,代码行数:13,代码来源:JoinableRepository.php

示例10: setDefaultIdentifierFieldNames

 /**
  * Defines default identifiers from query builder in order to optimize count queries.
  *
  * @return $this
  *
  * @throws \Doctrine\Common\Persistence\Mapping\MappingException
  */
 public function setDefaultIdentifierFieldNames()
 {
     //Default identifier for table rows
     $rootEntity = $this->queryBuilder->getRootEntities()[0];
     $metadata = $this->queryBuilder->getEntityManager()->getMetadataFactory()->getMetadataFor($rootEntity);
     $identifiers = array();
     foreach ($metadata->getIdentifierFieldNames() as $identifierFieldName) {
         $identifiers[] = $this->getAlias() . '.' . $identifierFieldName;
     }
     $rootEntityIdentifier = implode(',', $identifiers);
     $this->setIdentifierFieldNames($rootEntityIdentifier ?: null);
     return $this;
 }
开发者ID:KilikFr,项目名称:TableBundle,代码行数:20,代码来源:Table.php

示例11:

 function it_adds_a_filter_on_a_field_in_the_query(QueryBuilder $qb, Expr $expr, EntityManager $em, ClassMetadata $cm, Expr\Comparison $comparison)
 {
     $qb->expr()->willReturn($expr);
     $qb->getRootAlias()->willReturn('p');
     $qb->getRootEntities()->willReturn([]);
     $qb->getEntityManager()->willReturn($em);
     $em->getClassMetadata(false)->willReturn($cm);
     $comparison->__toString()->willReturn('filterCompleteness.ratio < 100');
     $cm->getAssociationMapping('completenesses')->willReturn(['targetEntity' => 'test']);
     $expr->literal('100')->willReturn('100');
     $expr->lt(Argument::any(), '100')->willReturn($comparison);
     $this->setQueryBuilder($qb);
     $qb->leftJoin('PimCatalogBundle:Locale', Argument::any(), 'WITH', Argument::any())->willReturn($qb);
     $qb->leftJoin('PimCatalogBundle:Channel', Argument::any(), 'WITH', Argument::any())->willReturn($qb);
     $qb->leftJoin('test', Argument::any(), 'WITH', Argument::any())->willReturn($qb);
     $qb->setParameter('cLocaleCode', Argument::any())->willReturn($qb);
     $qb->setParameter('cScopeCode', Argument::any())->willReturn($qb);
     $qb->andWhere('filterCompleteness.ratio < 100')->shouldBeCalled();
     $this->addFieldFilter('completeness', '<', 100, 'en_US', 'mobile');
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:20,代码来源:CompletenessFilterSpec.php

示例12: __construct

 /**
  * Constructor.
  *
  * @param Query|QueryBuilder $query
  *        	A Doctrine ORM query or query builder.
  * @param boolean $fetchJoinCollection
  *        	Whether the query joins a collection (true by default).
  * @param boolean $cache
  *        	Use result cache (true by default).
  * @param boolean $count
  *        	Execute count query (true by default).
  */
 public function __construct($query, $fetchJoinCollection = true, $cached = true, $count = true)
 {
     if ($count) {
         $countQuery = clone $query;
         $countQuery = $countQuery->select('count(e) as c')->setFirstResult(0)->setMaxResults(1)->getQuery();
         $this->countQuery = $countQuery;
     }
     $q = $query;
     if ($cached) {
         $this->cache_prefix = '';
         if ($query instanceof QueryBuilder) {
             $q = $query->getQuery();
             $entities = $query->getRootEntities();
             if ($entities) {
                 $entity = $entities[0];
                 $this->cache_prefix = strtolower(substr(strrchr($entity, '\\'), 1) ?: $entity) . '-';
             }
         }
         $q->useQueryCache(true)->useResultCache(true, 3600, $this->cache_prefix . md5($q->getDQL()));
     }
     parent::__construct($q, $fetchJoinCollection);
 }
开发者ID:arstropica,项目名称:zf2-dashboard,代码行数:34,代码来源:Paginator.php

示例13: joinACL

 /**
  * Joins with the authorizations and filters the results to keep only those authorized.
  *
  * @param QueryBuilder              $qb
  * @param SecurityIdentityInterface $identity
  * @param string                    $action
  * @param string|null               $entityClass Class name of the entity that is the resource in the query.
  *                                               If omitted, it will be guessed from the SELECT.
  * @param string|null               $entityAlias Alias of the entity that is the resource in the query.
  *                                               If omitted, it will be guessed from the SELECT.
  *
  * @throws \RuntimeException The query builder has no "select" part
  */
 public static function joinACL(QueryBuilder $qb, SecurityIdentityInterface $identity, $action, $entityClass = null, $entityAlias = null)
 {
     if ($entityClass === null) {
         $rootEntities = $qb->getRootEntities();
         if (!isset($rootEntities[0])) {
             throw new \RuntimeException('The query builder has no "select" part');
         }
         $entityClass = $rootEntities[0];
     }
     if ($entityAlias === null) {
         $rootAliases = $qb->getRootAliases();
         if (!isset($rootAliases[0])) {
             throw new \RuntimeException('The query builder has no "select" part');
         }
         $entityAlias = $rootAliases[0];
     }
     $qb->innerJoin('MyCLabs\\ACL\\Model\\Authorization', 'authorization', 'WITH', $entityAlias . '.id = authorization.entityId');
     $qb->andWhere('authorization.entityClass = :acl_entity_class');
     $qb->andWhere('authorization.securityIdentity = :acl_identity');
     $qb->andWhere('authorization.actions.' . $action . ' = true');
     $qb->setParameter('acl_identity', $identity);
     $qb->setParameter('acl_entity_class', $entityClass);
 }
开发者ID:gbelmm,项目名称:ACL,代码行数:36,代码来源:ACLQueryHelper.php

示例14: getClassMetadataFromJoinAlias

 /**
  * Gets the class metadata from a given join alias.
  *
  * @param string          $alias
  * @param QueryBuilder    $queryBuilder
  * @param ManagerRegistry $managerRegistry
  *
  * @return ClassMetadata
  */
 public static function getClassMetadataFromJoinAlias(string $alias, QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry) : ClassMetadata
 {
     $rootEntities = $queryBuilder->getRootEntities();
     $rootAliases = $queryBuilder->getRootAliases();
     $joinParts = $queryBuilder->getDQLPart('join');
     $aliasMap = [];
     $targetAlias = $alias;
     foreach ($joinParts as $rootAlias => $joins) {
         $aliasMap[$rootAlias] = 'root';
         foreach ($joins as $join) {
             $alias = self::getJoinAlias($join);
             $relationship = self::getJoinRelationship($join);
             $pos = strpos($relationship, '.');
             $aliasMap[$alias] = ['parentAlias' => substr($relationship, 0, $pos), 'association' => substr($relationship, $pos + 1)];
         }
     }
     $associationStack = [];
     $rootAlias = null;
     while (null === $rootAlias) {
         $mapping = $aliasMap[$targetAlias];
         if ('root' === $mapping) {
             $rootAlias = $targetAlias;
         } else {
             $associationStack[] = $mapping['association'];
             $targetAlias = $mapping['parentAlias'];
         }
     }
     $rootEntity = $rootEntities[array_search($rootAlias, $rootAliases)];
     $rootMetadata = $managerRegistry->getManagerForClass($rootEntity)->getClassMetadata($rootEntity);
     $metadata = $rootMetadata;
     while (null !== ($association = array_pop($associationStack))) {
         $associationClass = $metadata->getAssociationTargetClass($association);
         $metadata = $managerRegistry->getManagerForClass($associationClass)->getClassMetadata($associationClass);
     }
     return $metadata;
 }
开发者ID:api-platform,项目名称:core,代码行数:45,代码来源:QueryJoinParser.php

示例15: buildWithSubQuery

 /**
  * Get the results from the sql after adding the
  *
  * @param \Victoire\Bundle\BusinessEntityPageBundle\Entity\BusinessEntityPagePattern $containerEntity
  * @param QueryBuilder                                                               $itemsQueryBuilder
  *
  * @throws \Exception
  *
  * @return QueryBuilder The QB to list of objects
  */
 public function buildWithSubQuery($containerEntity, QueryBuilder $itemsQueryBuilder)
 {
     //services
     $entityManager = $this->entityManager;
     //test the container entity
     if ($containerEntity === null) {
         throw new \Exception('The container entity parameter must not be null.');
     }
     //verify that the object has the query trait
     $this->checkObjectHasQueryTrait($containerEntity);
     //get the query of the container entity
     $query = $containerEntity->getQuery();
     if ($query !== '' && $query !== null) {
         $subQuery = $this->entityManager->createQueryBuilder()->select('item.id')->from($itemsQueryBuilder->getRootEntities()[0], 'item');
         $itemsQueryBuilder->andWhere('main_item.id IN (' . $subQuery->getQuery()->getDql() . ' ' . $query . ')');
     }
     $currentView = $this->currentView;
     // If the current page is a BEP, we parse all its properties and inject them as query parameters
     if ($currentView() && $currentView() instanceof BusinessEntityPage && null !== ($currentEntity = $currentView()->getBusinessEntity())) {
         // NEW
         $metadatas = $this->entityManager->getClassMetadata(get_class($currentEntity));
         foreach ($metadatas->fieldMappings as $fieldName => $field) {
             if (strpos($query, ":" . $fieldName) !== false) {
                 $itemsQueryBuilder->setParameter($fieldName, $metadatas->getFieldValue($currentEntity, $fieldName));
             }
         }
         foreach ($metadatas->associationMappings as $fieldName => $field) {
             if (strpos($query, ":" . $fieldName) !== false) {
                 $itemsQueryBuilder->setParameter($fieldName, $metadatas->getFieldValue($currentEntity, $fieldName)->getId());
             }
         }
         if (strpos($query, ":currentEntity") !== false) {
             $itemsQueryBuilder->setParameter('currentEntity', $currentEntity->getId());
         }
     }
     return $itemsQueryBuilder;
 }
开发者ID:Atc-it,项目名称:victoire,代码行数:47,代码来源:QueryHelper.php


注:本文中的Doctrine\ORM\QueryBuilder::getRootEntities方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。