當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。