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


PHP QueryBuilder::getEntityManager方法代码示例

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


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

示例1: array

 /**
  * @param Repository $EntityRepository
  * @param array      $Filter array( 'ColumnName' => 'Value', ... )
  */
 function __construct(Repository $EntityRepository, $Filter = array())
 {
     $this->QueryBuilder = $EntityRepository->createQueryBuilder(self::QUERY_BUILDER_ALIAS);
     $this->ColumnNames = $this->QueryBuilder->getEntityManager()->getClassMetadata($EntityRepository->getClassName())->getFieldNames();
     $this->Request = $this->getRequest()->getParameterArray();
     $this->setFilter($Filter);
     $this->setSearch();
     $this->setOrderBy();
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:13,代码来源:DataTables.php

示例2: 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

示例3: getFixedQueryBuilder

 /**
  * This method alters the query to return a clean set of object with a working
  * set of Object
  *
  * @param \Doctrine\ORM\QueryBuilder $queryBuilder
  * @return void
  */
 private function getFixedQueryBuilder(QueryBuilder $queryBuilder)
 {
     $queryBuilderId = clone $queryBuilder;
     // step 1 : retrieve the targeted class
     $from = $queryBuilderId->getDQLPart('from');
     $class = $from[0]->getFrom();
     // step 2 : retrieve the column id
     $idName = current($queryBuilderId->getEntityManager()->getMetadataFactory()->getMetadataFor($class)->getIdentifierFieldNames());
     // step 3 : retrieve the different subjects id
     $select = sprintf('%s.%s', $queryBuilderId->getRootAlias(), $idName);
     $queryBuilderId->resetDQLPart('select');
     $queryBuilderId->add('select', 'DISTINCT ' . $select);
     $results = $queryBuilderId->getQuery()->execute(array(), Query::HYDRATE_ARRAY);
     $idx = array();
     $connection = $queryBuilder->getEntityManager()->getConnection();
     foreach ($results as $id) {
         $idx[] = $connection->quote($id[$idName]);
     }
     // step 4 : alter the query to match the targeted ids
     if (count($idx) > 0) {
         $queryBuilder->andWhere(sprintf('%s IN (%s)', $select, implode(',', $idx)));
         $queryBuilder->setMaxResults(null);
         $queryBuilder->setFirstResult(null);
     }
     return $queryBuilder;
 }
开发者ID:renegare,项目名称:AdminBundle,代码行数:33,代码来源:ProxyQuery.php

示例4: resolveEntityClass

 /**
  * Gets the full class name if the given join expression represents an entity name in form "bundle:class"
  *
  * @param string $joinExpr
  *
  * @return string
  */
 protected function resolveEntityClass($joinExpr)
 {
     $parts = explode(':', $joinExpr);
     if (count($parts) !== 2) {
         return $joinExpr;
     }
     return $this->originalQueryBuilder->getEntityManager()->getConfiguration()->getEntityNamespace($parts[0]) . '\\' . $parts[1];
 }
开发者ID:Maksold,项目名称:platform,代码行数:15,代码来源:QueryOptimizationContext.php

示例5: 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

示例6: initIdFieldName

 /**
  * Initialize the column id of the targeted class.
  *
  * @return string
  */
 protected function initIdFieldName()
 {
     /** @var $from \Doctrine\ORM\Query\Expr\From */
     $from = current($this->originalQb->getDQLPart('from'));
     $class = $from->getFrom();
     $idNames = $this->originalQb->getEntityManager()->getMetadataFactory()->getMetadataFor($class)->getIdentifierFieldNames();
     $this->idFieldName = current($idNames);
 }
开发者ID:northdakota,项目名称:platform,代码行数:13,代码来源:CountQueryBuilderOptimizer.php

示例7: createNumRowsSubQuery

 private function createNumRowsSubQuery()
 {
     $parts = $this->query->getDQLParts();
     $from = $parts['from'][0];
     $where = $parts['where'];
     $entityManager = $this->query->getEntityManager();
     $queryBuilder = $entityManager->createQueryBuilder();
     $queryBuilder->select('COUNT(DISTINCT countAlias.id)')->from($from->getFrom(), 'countAlias');
     $aliasCount = 1;
     $aliases = array($from->getAlias() => 'countAlias');
     foreach ($parts['join'] as $joinSource => $joins) {
         if (!array_key_exists($joinSource, $aliases)) {
             $aliases[$joinSource] = 'countAlias' . $aliasCount;
             ++$aliasCount;
         }
         foreach ($joins as $join) {
             if (!array_key_exists($join->getAlias(), $aliases)) {
                 $aliases[$join->getAlias()] = 'countAlias' . $aliasCount;
                 ++$aliasCount;
             }
             preg_match('#[a-zA-Z_]*\\.+#', $join->getJoin(), $matches);
             $joinCondition = preg_replace('#[a-zA-Z_]*\\.+#', $aliases[substr($matches[0], 0, -1)] . '.', $join->getJoin());
             switch ($join->getJoinType()) {
                 case \Doctrine\ORM\Query\Expr\Join::INNER_JOIN:
                     $queryBuilder->innerJoin($joinCondition, $aliases[$join->getAlias()]);
                     break;
                 case \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN:
                     $queryBuilder->leftJoin($joinCondition, $aliases[$join->getAlias()]);
                     break;
                 default:
                     throw new \Exception('Unknow join type');
                     break;
             }
         }
     }
     if ($where) {
         $whereCondition = $where->__toString();
         preg_match_all('#([a-zA-Z_]*)\\.+#', $whereCondition, $matches);
         foreach ($matches[1] as $alias) {
             $whereCondition = preg_replace('#' . $alias . '\\.+#', $aliases[$alias] . '.', $whereCondition);
         }
         $queryBuilder->where($whereCondition);
     }
     return $queryBuilder;
 }
开发者ID:w3build,项目名称:paginate-bundle,代码行数:45,代码来源:QueryBuilder.php

示例8: applyToCollection

 /**
  * {@inheritdoc}
  */
 public function applyToCollection(ResourceInterface $resource, QueryBuilder $queryBuilder)
 {
     $classMetaData = $queryBuilder->getEntityManager()->getClassMetadata($resource->getEntityClass());
     $identifiers = $classMetaData->getIdentifier();
     if (null !== $this->order && 1 === count($identifiers)) {
         $identifier = $identifiers[0];
         $queryBuilder->addOrderBy('o.' . $identifier, $this->order);
     }
 }
开发者ID:akomm,项目名称:DunglasApiBundle,代码行数:12,代码来源:OrderExtension.php

示例9: 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

示例10: applyToCollection

 /**
  * {@inheritdoc}
  */
 public function applyToCollection(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $operationName = null)
 {
     $classMetaData = $queryBuilder->getEntityManager()->getClassMetadata($resourceClass);
     $identifiers = $classMetaData->getIdentifier();
     if (null !== $this->order) {
         foreach ($identifiers as $identifier) {
             $queryBuilder->addOrderBy('o.' . $identifier, $this->order);
         }
     }
 }
开发者ID:api-platform,项目名称:core,代码行数:13,代码来源:OrderExtension.php

示例11: initializeDataStructure

 protected function initializeDataStructure($tableName, $primaryKey)
 {
     $dataStructure = new Structures\DataStructure($tableName, $primaryKey);
     $this->setDataStructure($dataStructure);
     $entityManager = $this->queryBuilder->getEntityManager();
     $classMetadata = $entityManager->getClassMetadata($tableName);
     Helpers::setStructureFromColumns($dataStructure, $this->determineFromColumns($classMetadata));
     foreach ($classMetadata->getAssociationNames() as $associationName) {
         $targetClass = $classMetadata->getAssociationTargetClass($associationName);
         $targetMetadata = $entityManager->getClassMetadata($targetClass);
         $associations = $classMetadata->getAssociationsByTargetClass($targetClass);
         $primaryColumns = $targetMetadata->getIdentifierColumnNames();
         foreach ($associations as $association) {
             $dataStructure->getOrCreateTableStructure($targetClass, reset($primaryColumns));
             $associationsType = $association['type'];
             if ($associationsType === $classMetadata::ONE_TO_ONE) {
                 if ($association['sourceEntity'] === $tableName) {
                     $referencedColumn = reset($association['targetToSourceKeyColumns']);
                 }
                 if (!isset($referencedColumn)) {
                     throw new InvalidStateException(sprintf('Can not find referenced column name for field %s.', $associationName));
                 }
                 $dataStructure->addOneToOne($associationName, $targetClass, $referencedColumn);
             } elseif ($associationsType === $classMetadata::MANY_TO_ONE) {
                 if ($association['sourceEntity'] === $tableName) {
                     $referencedColumn = reset($association['targetToSourceKeyColumns']);
                 }
                 if (!isset($referencedColumn)) {
                     throw new InvalidStateException(sprintf('Can not find referenced column name for field %s.', $associationName));
                 }
                 $dataStructure->addManyToOne($associationName, $targetClass, $referencedColumn);
             } elseif ($associationsType === $classMetadata::ONE_TO_MANY) {
                 foreach ($targetMetadata->getAssociationMappings() as $joinedAssociation) {
                     if ($joinedAssociation['inversedBy'] === $associationName) {
                         $referencedColumn = reset($joinedAssociation['targetToSourceKeyColumns']);
                     }
                 }
                 if (!isset($referencedColumn)) {
                     throw new InvalidStateException(sprintf('Can not find referenced column name for field %s. Is `inversedBy` set in property annotation?', $associationName));
                 }
                 $dataStructure->addOneToMany($associationName, $targetClass, $referencedColumn);
             } elseif ($associationsType === $classMetadata::MANY_TO_MANY) {
                 if (!isset($association['joinTable'])) {
                     throw new InvalidStateException(sprintf('Can not find joinColumn settings for field %s. Is `joinColumn` set in property annotation?', $associationName));
                 }
                 $joinTable = $association['joinTable'];
                 if (isset($joinTable['joinColumns']) && $joinTable['joinColumns']) {
                     $joinColumn = reset($joinTable['joinColumns']);
                     $inverseJoinColumn = reset($joinTable['inverseJoinColumns']);
                     $dataStructure->addManyToMany($associationName, $targetClass, $inverseJoinColumn['name'], $joinTable['name'], $joinColumn['name']);
                 }
             }
         }
     }
 }
开发者ID:mesour,项目名称:sources,代码行数:55,代码来源:DoctrineSource.php

示例12: normalize

 /**
  * @inheritdoc
  */
 public function normalize(Query $query, QueryBuilder $queryBuilder, $hydratorClass = null)
 {
     /*
      * Add custom hydrator
      */
     $emConfig = $queryBuilder->getEntityManager()->getConfiguration();
     $hydrator = new \ReflectionClass($hydratorClass);
     $hydratorName = $hydrator->getShortName();
     $emConfig->addCustomHydrationMode($hydratorName, $hydratorClass);
     return $query->getResult($hydratorName);
 }
开发者ID:mops1k,项目名称:KitpagesDataGridBundle,代码行数:14,代码来源:StandardNormalizer.php

示例13: 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

示例14: joinRelations

 /**
  * Left joins relations to eager load.
  *
  * @param ResourceInterface $resource
  * @param QueryBuilder      $queryBuilder
  */
 private function joinRelations(ResourceInterface $resource, QueryBuilder $queryBuilder)
 {
     $classMetaData = $queryBuilder->getEntityManager()->getClassMetadata($resource->getEntityClass());
     foreach ($classMetaData->getAssociationNames() as $i => $association) {
         $mapping = $classMetaData->associationMappings[$association];
         if (ClassMetadataInfo::FETCH_EAGER === $mapping['fetch']) {
             $queryBuilder->leftJoin('o.' . $association, 'a' . $i);
             $queryBuilder->addSelect('a' . $i);
         }
     }
 }
开发者ID:PaskR,项目名称:DunglasApiBundle,代码行数:17,代码来源:EagerLoadingExtension.php

示例15: applyAcl

 /**
  * Apply ACL restriction to query builder.
  *
  * @param QueryBuilder $queryBuilder
  * @param string $tableAlias
  */
 public function applyAcl(QueryBuilder $queryBuilder, $tableAlias)
 {
     $taggableEntities = $this->getTaggableEntities($queryBuilder->getEntityManager());
     $allowedEntities = $this->getAllowedEntities($taggableEntities);
     if (count($allowedEntities) != count($taggableEntities)) {
         if ($allowedEntities) {
             $queryBuilder->andWhere($tableAlias . '.entityName IN(:allowedEntities)')->setParameter('allowedEntities', $allowedEntities);
         } else {
             // Do not show any result if all entities are prohibited
             $queryBuilder->andWhere('1 = 0');
         }
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:19,代码来源:SecurityProvider.php


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