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


PHP QueryBuilder::getDQLParts方法代码示例

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


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

示例1: collectMeta

 /**
  * collectMetadata for all Entities
  */
 private function collectMeta()
 {
     $parts = $this->queryBuilder->getDQLParts();
     $entity = reset($parts['from']);
     $this->setEntityName($entity->getFrom());
     $this->setAlias($entity->getAlias());
     $mdf = $this->queryBuilder->getEntityManager()->getMetadataFactory();
     $this->meta[$this->alias] = $mdf->getMetadataFor($this->entityName);
     if (isset($parts['join'][$this->alias])) {
         /** @var Join $join */
         foreach ($parts['join'][$this->alias] as $join) {
             $j = explode('.', $join->getJoin(), 2);
             if (count($j) != 2) {
                 throw new \InvalidArgumentException('Join in wrong format: ' . $join->getJoin());
             }
             if (!isset($this->meta[$j[0]])) {
                 throw new \InvalidArgumentException('Unknown alias in join or wrong order: ' . $join->getJoin());
             }
             if (!isset($this->meta[$j[0]]->associationMappings[$j[1]])) {
                 throw new \InvalidArgumentException('Unknown Mapping in join: ' . $join->getJoin());
             }
             $jEntity = $this->meta[$j[0]]->associationMappings[$j[1]]['targetEntity'];
             $this->meta[$join->getAlias()] = $mdf->getMetadataFor($jEntity);
         }
     }
 }
开发者ID:Silwereth,项目名称:core,代码行数:29,代码来源:Config.php

示例2: getCountQueryBuilder

 /**
  * Get optimized query builder for count calculation.
  *
  * @param QueryBuilder $originalQb
  * @return QueryBuilder
  */
 public function getCountQueryBuilder(QueryBuilder $originalQb)
 {
     $this->setOriginalQueryBuilder($originalQb);
     $parts = $this->originalQb->getDQLParts();
     $qb = clone $this->originalQb;
     $qb->setFirstResult(null)->setMaxResults(null)->resetDQLPart('orderBy')->resetDQLPart('groupBy')->resetDQLPart('select')->resetDQLPart('join')->resetDQLPart('where')->resetDQLPart('having');
     $fieldsToSelect = array();
     if ($parts['groupBy']) {
         $groupBy = (array) $parts['groupBy'];
         $groupByFields = $this->getSelectFieldFromGroupBy($groupBy);
         $usedGroupByAliases = [];
         foreach ($groupByFields as $key => $groupByField) {
             $alias = '_groupByPart' . $key;
             $usedGroupByAliases[] = $alias;
             $fieldsToSelect[] = $groupByField . ' as ' . $alias;
         }
         $qb->groupBy(implode(', ', $usedGroupByAliases));
     } elseif (!$parts['where'] && $parts['having']) {
         // If there is no where and group by, but having is present - convert having to where.
         $parts['where'] = $parts['having'];
         $parts['having'] = null;
         $qb->resetDQLPart('having');
     }
     if ($parts['having']) {
         $qb->having($this->qbTools->replaceAliasesWithFields($parts['having']));
     }
     $hasJoins = false;
     if ($parts['join']) {
         $hasJoins = $this->addJoins($qb, $parts);
     }
     if (!$parts['groupBy']) {
         $qb->distinct($hasJoins);
         $fieldsToSelect[] = $this->getFieldFQN($this->idFieldName);
     }
     if ($parts['where']) {
         $qb->where($this->qbTools->replaceAliasesWithFields($parts['where']));
     }
     $qb->select(array_unique($fieldsToSelect));
     $this->qbTools->fixUnusedParameters($qb);
     return $qb;
 }
开发者ID:xamin123,项目名称:platform,代码行数:47,代码来源:CountQueryBuilderOptimizer.php

示例3: getResult

 public function getResult($itemsPerPage, $page, Result $result)
 {
     $parts = $this->query->getDQLParts();
     $from = $parts['from'][0];
     $itemsOnPage = clone $this->query;
     $itemsOnPage->select('DISTINCT(' . $from->getAlias() . '.id)')->addSelect('(' . $this->getNumRowsSubQuery() . ') as num_rows')->from($from->getFrom(), 'master')->setMaxResults($itemsPerPage)->setFirstResult($itemsPerPage * ($page - 1));
     $itemsOnPage = $itemsOnPage->getQuery()->getScalarResult();
     $totalResults = 0;
     $ids = array();
     if ($itemsOnPage) {
         $totalResults = $itemsOnPage[0]['num_rows'];
         foreach ($itemsOnPage as $itemOnPage) {
             $ids[] = $itemOnPage[1];
         }
     }
     $totalPages = ceil($totalResults / $itemsPerPage);
     $this->query->resetDQLPart('where');
     $this->query->where($from->getAlias() . ' IN (:ids)')->setParameters(array('ids' => $ids));
     $results = $this->query->getQuery()->getResult();
     return $this->populateResult($result, $totalResults, $totalPages, $page, $results);
 }
开发者ID:w3build,项目名称:paginate-bundle,代码行数:21,代码来源:QueryBuilder.php

示例4: draftizeQueryBuilder

 public function draftizeQueryBuilder(\Doctrine\ORM\QueryBuilder $qb)
 {
     $parts = $qb->getDQLParts();
     $froms = $parts['from'];
     foreach ($froms as $fromExpr) {
         $entityClass = $fromExpr->getFrom();
         $entityAlias = $fromExpr->getAlias();
         if (method_exists('\\' . $entityClass, 'getDraft') && !$this->allowDraft) {
             $qb->andWhere($entityAlias . '.draft=:draftAllowed')->setParameter('draftAllowed', false);
         }
     }
     return $qb;
 }
开发者ID:kokmok,项目名称:SKCMS-Core,代码行数:13,代码来源:SKEntityRepository.php

示例5: findJoinByAlias

 /**
  * @param \Doctrine\ORM\QueryBuilder $qb        Query builder
  * @param string                     $rootAlias Root alias
  * @param string                     $joinAlias Join alias
  *
  * @return \Doctrine\ORM\Query\Expr\Join
  */
 public static function findJoinByAlias(QueryBuilder $qb, $rootAlias, $joinAlias)
 {
     $dqlParts = $qb->getDQLParts();
     if (!isset($dqlParts['join'][$rootAlias])) {
         return null;
     }
     /** @var \Doctrine\ORM\Query\Expr\Join $join */
     foreach ($dqlParts['join'][$rootAlias] as $join) {
         if ($joinAlias === $join->getAlias()) {
             return $join;
         }
     }
     return null;
 }
开发者ID:darvinstudio,项目名称:darvin-utils,代码行数:21,代码来源:QueryBuilderUtil.php

示例6: buildPathToAliasMap

 /**
  * @author Andreas Glaser
  */
 protected function buildPathToAliasMap()
 {
     $rootAlias = ArrayHelper::getFirstValue($this->qb->getRootAliases());
     $this->aliasMap[$rootAlias] = $rootAlias;
     if (array_key_exists($rootAlias, $this->qb->getDQLParts()['join'])) {
         /** @var Expr\Join $part */
         foreach ($this->qb->getDQLParts()['join'][$rootAlias] as $part) {
             $alias = $part->getAlias();
             $join = $part->getJoin();
             $path = $alias;
             $pieces = explode('.', $join);
             if ($parentAlias = ArrayHelper::getKeyByValue($this->aliasMap, $pieces[0])) {
                 $path = $parentAlias . '.' . $alias;
             }
             $this->aliasMap[$path] = $alias;
         }
     }
 }
开发者ID:andreas-glaser,项目名称:doctrine-rql,代码行数:21,代码来源:ORMVisitor.php


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