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


PHP QueryBuilder::join方法代码示例

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


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

示例1: applyJoins

 private function applyJoins(QueryBuilderFilter $filter, QueryBuilder $queryBuilder)
 {
     /** @var Join[] $previousJoins */
     $previousJoins = array();
     foreach ($filter->getJoins() as $join) {
         $joinEntity = $join->getEntityClassName();
         $joinAlias = $join->getAlias();
         if (!array_key_exists($joinEntity, $previousJoins)) {
             $previousJoins[$joinEntity] = $join;
             switch (get_class($join)) {
                 case LeftJoinWith::class:
                     /** @var LeftJoinWith $join */
                     $queryBuilder->leftJoin($joinEntity, $joinAlias, \Doctrine\ORM\Query\Expr\Join::WITH, $join->getWithCondition());
                     break;
                 case LeftJoin::class:
                     $queryBuilder->leftJoin($joinEntity, $joinAlias);
                     break;
                 case JoinWith::class:
                     /** @var JoinWith $join */
                     $queryBuilder->join($joinEntity, $joinAlias, \Doctrine\ORM\Query\Expr\Join::WITH, $join->getWithCondition());
                     break;
                 case Join::class:
                     $queryBuilder->join($joinEntity, $joinAlias);
                     break;
                 default:
                     throw new Exception('Invalid JOIN type: ' . get_class($join));
             }
         } else {
             if ($previousJoins[$joinEntity]->getAlias() !== $joinAlias) {
                 throw new InconsistentJoinsException($joinEntity, $previousJoins[$joinEntity]->getAlias(), $joinAlias);
             }
         }
     }
 }
开发者ID:netucz,项目名称:slovicka,代码行数:34,代码来源:QueryBuilderFilterApplier.php

示例2: applyCustomQuery

 /**
  * Applies a custom query to the QueryBuilder
  * 
  * @param QueryBuilder $qb The query builder
  * @param ManagerFilter $filter The query filter
  */
 protected function applyCustomQuery(QueryBuilder $qb, ManagerFilter $filter)
 {
     // Apply special handling for non-direct fields in relations, where the frontend has no idea about.
     foreach ($filter->getSorters() as $sorter) {
         switch ($sorter->getSortField()) {
             case "q.part_name":
                 $qb->join("q.part", "p");
                 $sorter->setSortField("p.name");
                 break;
             case "q.user_id":
                 $qb->leftJoin("q.user", "u");
                 $sorter->setSortField("u.username");
                 break;
             case "q.direction":
                 $sorter->setSortField("q.dateTime");
                 break;
             case "q.storageLocation_name":
                 $qb->join("q.part", "p")->join("p.storageLocation", "st");
                 $sorter->setSortField("st.name");
                 break;
             default:
                 break;
         }
     }
 }
开发者ID:JohnEffland,项目名称:PartKeepr,代码行数:31,代码来源:StockManager.php

示例3: join

 /**
  * @param array $joins
  * @return AbstractQuery
  */
 public function join(array $joins)
 {
     $this->assertCanBeModified();
     foreach ($joins as $attribute => $prefix) {
         $this->queryBuilder->join($attribute, $prefix);
     }
     return $this;
 }
开发者ID:mystlabs,项目名称:mistydoctrine,代码行数:12,代码来源:AbstractQuery.php

示例4: attachCriteriaToQueryBuilder

 /**
  * @param QueryBuilder $qb
  * @param array $criteria
  * @param array $orderBy
  * @param int $limit
  * @param int $offset
  *
  * @return QueryBuilder
  */
 protected function attachCriteriaToQueryBuilder(QueryBuilder $qb, $criteria, $orderBy, $limit, $offset)
 {
     if (array_key_exists('cohort', $criteria)) {
         $criteria['cohorts'][] = $criteria['cohort'];
         unset($criteria['cohort']);
     }
     if (array_key_exists('cohorts', $criteria)) {
         $ids = is_array($criteria['cohorts']) ? $criteria['cohorts'] : [$criteria['cohorts']];
         $qb->join('l.cohort', 'l_cohort');
         $qb->andWhere($qb->expr()->in('l_cohort.id', ':cohorts'));
         $qb->setParameter(':cohorts', $ids);
     }
     if (array_key_exists('parent', $criteria)) {
         $criteria['parents'][] = $criteria['parent'];
         unset($criteria['parent']);
     }
     if (array_key_exists('parents', $criteria)) {
         $ids = is_array($criteria['parents']) ? $criteria['parents'] : [$criteria['parents']];
         if (in_array(null, $ids)) {
             $ids = array_diff($ids, [null]);
             $qb->andWhere('l.parent IS NULL');
         }
         if (count($ids)) {
             $qb->join('l.parent', 'l_parent');
             $qb->andWhere($qb->expr()->in('l_parent.id', ':parents'));
             $qb->setParameter(':parents', $ids);
         }
     }
     //cleanup all the possible relationship filters
     unset($criteria['cohorts']);
     unset($criteria['parents']);
     if (count($criteria)) {
         foreach ($criteria as $key => $value) {
             $values = is_array($value) ? $value : [$value];
             $qb->andWhere($qb->expr()->in("l.{$key}", ":{$key}"));
             $qb->setParameter(":{$key}", $values);
         }
     }
     if (empty($orderBy)) {
         $orderBy = ['id' => 'ASC'];
     }
     if (is_array($orderBy)) {
         foreach ($orderBy as $sort => $order) {
             $qb->addOrderBy('l.' . $sort, $order);
         }
     }
     if ($offset) {
         $qb->setFirstResult($offset);
     }
     if ($limit) {
         $qb->setMaxResults($limit);
     }
     return $qb;
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:63,代码来源:LearnerGroupRepository.php

示例5: join

 /**
  * Will do JOIN only if there is no such join already.
  *
  * @param QueryBuilder $queryBuilder
  * @param string $join
  * @param string $alias
  *
  * @return QueryBuilder
  */
 protected function join(QueryBuilder $queryBuilder, $join, $alias)
 {
     list($entity) = explode('.', $join);
     $joinParts = $queryBuilder->getDQLPart('join');
     if (!array_key_exists($entity, $joinParts)) {
         return $queryBuilder->join($join, $alias);
     }
     $joinParts = $joinParts[$entity];
     $existingJoin = array_filter($joinParts, function (Join $joinObj) use($alias, $join) {
         return $joinObj->getAlias() == $alias && $joinObj->getJoin() == $join;
     });
     if ([] != $existingJoin) {
         return $queryBuilder;
     }
     return $queryBuilder->join($join, $alias);
 }
开发者ID:ustrugany,项目名称:searcher,代码行数:25,代码来源:AbstractQueryBuilderFilterImposer.php

示例6: implement

 public function implement(QueryBuilder $queryBuilder)
 {
     foreach ($this->getValue() as $key => $alias) {
         $key = Utils::parseKey($key);
         $queryBuilder->join($key, $alias);
     }
 }
开发者ID:jacoz,项目名称:doctrine-query-builder-from-request,代码行数:7,代码来源:JoinsParam.php

示例7: apply

 /**
  * {@inheritdoc}
  *
  * Orders collection by properties. The order of the ordered properties is the same as the order specified in the
  * query.
  * For each property passed, if the resource does not have such property or if the order value is different from
  * `asc` or `desc` (case insensitive), the property is ignored.
  */
 public function apply(ResourceInterface $resource, QueryBuilder $queryBuilder)
 {
     $request = $this->requestStack->getCurrentRequest();
     if (null === $request) {
         return;
     }
     $properties = $this->extractProperties($request);
     foreach ($properties as $property => $order) {
         if (!$this->isPropertyEnabled($property) || !$this->isPropertyMapped($property, $resource)) {
             continue;
         }
         if (empty($order) && isset($this->properties[$property])) {
             $order = $this->properties[$property];
         }
         $order = strtoupper($order);
         if (!in_array($order, ['ASC', 'DESC'])) {
             continue;
         }
         $alias = 'o';
         $field = $property;
         if ($this->isPropertyNested($property)) {
             $propertyParts = $this->splitPropertyParts($property);
             $parentAlias = $alias;
             foreach ($propertyParts['associations'] as $association) {
                 $alias = QueryNameGenerator::generateJoinAlias($association);
                 $queryBuilder->join(sprintf('%s.%s', $parentAlias, $association), $alias);
                 $parentAlias = $alias;
             }
             $field = $propertyParts['field'];
         }
         $queryBuilder->addOrderBy(sprintf('%s.%s', $alias, $field), $order);
     }
 }
开发者ID:akomm,项目名称:DunglasApiBundle,代码行数:41,代码来源:OrderFilter.php

示例8: attachCriteriaToQueryBuilder

 /**
  * @param QueryBuilder $qb
  * @param array $criteria
  * @param array $orderBy
  * @param int $limit
  * @param int $offset
  *
  * @return QueryBuilder
  */
 protected function attachCriteriaToQueryBuilder(QueryBuilder $qb, $criteria, $orderBy, $limit, $offset)
 {
     if (array_key_exists('alerts', $criteria)) {
         $ids = is_array($criteria['alerts']) ? $criteria['alerts'] : [$criteria['alerts']];
         $qb->join('x.alerts', 'al');
         $qb->andWhere($qb->expr()->in('al.id', ':alerts'));
         $qb->setParameter(':alerts', $ids);
     }
     //cleanup all the possible relationship filters
     unset($criteria['alerts']);
     if (count($criteria)) {
         foreach ($criteria as $key => $value) {
             $values = is_array($value) ? $value : [$value];
             $qb->andWhere($qb->expr()->in("x.{$key}", ":{$key}"));
             $qb->setParameter(":{$key}", $values);
         }
     }
     if (empty($orderBy)) {
         $orderBy = ['id' => 'ASC'];
     }
     if (is_array($orderBy)) {
         foreach ($orderBy as $sort => $order) {
             $qb->addOrderBy('x.' . $sort, $order);
         }
     }
     if ($offset) {
         $qb->setFirstResult($offset);
     }
     if ($limit) {
         $qb->setMaxResults($limit);
     }
     return $qb;
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:42,代码来源:AlertChangeTypeRepository.php

示例9: apply

 /**
  * {@inheritdoc}
  */
 public function apply(ResourceInterface $resource, QueryBuilder $queryBuilder)
 {
     $request = $this->requestStack->getCurrentRequest();
     if (null === $request) {
         return;
     }
     foreach ($this->extractProperties($request) as $property => $values) {
         // Expect $values to be an array having the period as keys and the date value as values
         if (!$this->isPropertyEnabled($property) || !$this->isPropertyMapped($property, $resource) || !$this->isDateField($property, $resource) || !is_array($values)) {
             continue;
         }
         $alias = 'o';
         $field = $property;
         if ($this->isPropertyNested($property)) {
             $propertyParts = $this->splitPropertyParts($property);
             $parentAlias = $alias;
             foreach ($propertyParts['associations'] as $association) {
                 $alias = QueryNameGenerator::generateJoinAlias($association);
                 $queryBuilder->join(sprintf('%s.%s', $parentAlias, $association), $alias);
                 $parentAlias = $alias;
             }
             $field = $propertyParts['field'];
         }
         $nullManagement = isset($this->properties[$property]) ? $this->properties[$property] : null;
         if (self::EXCLUDE_NULL === $nullManagement) {
             $queryBuilder->andWhere($queryBuilder->expr()->isNotNull(sprintf('%s.%s', $alias, $field)));
         }
         if (isset($values[self::PARAMETER_BEFORE])) {
             $this->addWhere($queryBuilder, $alias, $field, self::PARAMETER_BEFORE, $values[self::PARAMETER_BEFORE], $nullManagement);
         }
         if (isset($values[self::PARAMETER_AFTER])) {
             $this->addWhere($queryBuilder, $alias, $field, self::PARAMETER_AFTER, $values[self::PARAMETER_AFTER], $nullManagement);
         }
     }
 }
开发者ID:PaskR,项目名称:DunglasApiBundle,代码行数:38,代码来源:DateFilter.php

示例10: attachCriteriaToQueryBuilder

 /**
  * @param QueryBuilder $qb
  * @param array $criteria
  * @param array $orderBy
  * @param int $limit
  * @param int $offset
  *
  * @return QueryBuilder
  */
 protected function attachCriteriaToQueryBuilder(QueryBuilder $qb, $criteria, $orderBy, $limit, $offset)
 {
     if (array_key_exists('courses', $criteria)) {
         $ids = is_array($criteria['courses']) ? $criteria['courses'] : [$criteria['courses']];
         $qb->join('o.courses', 'course');
         $qb->andWhere($qb->expr()->in('course.id', ':courses'));
         $qb->setParameter(':courses', $ids);
     }
     if (array_key_exists('programYears', $criteria)) {
         $ids = is_array($criteria['programYears']) ? $criteria['programYears'] : [$criteria['programYears']];
         $qb->join('o.programYears', 'programYear');
         $qb->andWhere($qb->expr()->in('programYear.id', ':programYears'));
         $qb->setParameter(':programYears', $ids);
     }
     if (array_key_exists('sessions', $criteria)) {
         $ids = is_array($criteria['sessions']) ? $criteria['sessions'] : [$criteria['sessions']];
         $qb->join('o.sessions', 'session');
         $qb->andWhere($qb->expr()->in('session.id', ':sessions'));
         $qb->setParameter(':sessions', $ids);
     }
     unset($criteria['courses']);
     unset($criteria['programYears']);
     unset($criteria['sessions']);
     if (count($criteria)) {
         foreach ($criteria as $key => $value) {
             $values = is_array($value) ? $value : [$value];
             $qb->andWhere($qb->expr()->in("o.{$key}", ":{$key}"));
             $qb->setParameter(":{$key}", $values);
         }
     }
     if (empty($orderBy)) {
         $orderBy = ['id' => 'ASC'];
     }
     if (is_array($orderBy)) {
         foreach ($orderBy as $sort => $order) {
             $qb->addOrderBy('o.' . $sort, $order);
         }
     }
     if ($offset) {
         $qb->setFirstResult($offset);
     }
     if ($limit) {
         $qb->setMaxResults($limit);
     }
     return $qb;
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:55,代码来源:ObjectiveRepository.php

示例11: filterExistingJoins

 /**
  * @param QueryBuilder $queryBuilder
  * @param array        $joinParts
  * @param string       $alias
  * @param string       $join
  * @param string       $joinType
  *
  * @return QueryBuilder
  */
 protected function filterExistingJoins(QueryBuilder $queryBuilder, $joinParts, $alias, $join, $joinType)
 {
     $existingJoin = array_filter($joinParts, function (Join $joinObj) use($alias, $join, $joinType) {
         return $joinObj->getJoinType() == $joinType && $joinObj->getAlias() == $alias && $joinObj->getJoin() == $join;
     });
     if ([] != $existingJoin) {
         return $queryBuilder;
     }
     return $queryBuilder->join($join, $alias);
 }
开发者ID:krzysztof-gzocha,项目名称:searcher,代码行数:19,代码来源:AbstractORMCriteriaBuilder.php

示例12: order

 protected function order()
 {
     $column = $this->getParamAdapter()->getColumn();
     $order = $this->getParamAdapter()->getOrder();
     if (!$column) {
         return;
     }
     $header = $this->getTable()->getHeader($column);
     $tableAlias = $header ? $header->getTableAlias() : 'q';
     if (false === strpos($tableAlias, '.')) {
         $tableAlias = $tableAlias . '.' . $column;
     }
     if ($header->getOrderJoin()) {
         $joinAlias = 'j' . str_replace('.', '_', $tableAlias);
         $this->query->join($tableAlias, $joinAlias);
         $this->query->orderBy($joinAlias . '.' . $header->getOrderJoin(), $order);
     } else {
         $this->query->orderBy($tableAlias, $order);
     }
 }
开发者ID:joacub,项目名称:zftable,代码行数:20,代码来源:DoctrineQueryBuilder.php

示例13: setQueryParam

 /**
  * @param string $field
  * @param mixed $value
  * @return array
  */
 protected function setQueryParam($field)
 {
     $index = 0;
     $rootAlias = $this->qb->getRootAliases()[$index];
     if (false !== strpos($field, '.')) {
         list($assoc, $subField) = explode('.', $field);
     } else {
         $assoc = $field;
     }
     $meta = $this->getClassMetadata($index);
     if ($meta->hasAssociation($assoc)) {
         $targetClass = $meta->getAssociationTargetClass($assoc);
         if ($meta->isCollectionValuedAssociation($assoc)) {
             $alias = "{$rootAlias}_{$assoc}";
             if (!in_array($alias, $this->qb->getAllAliases())) {
                 $this->qb->leftJoin("{$rootAlias}.{$assoc}", $alias);
             }
             $assoc = $alias;
         } else {
             $alias = "{$rootAlias}_{$assoc}";
             if (!in_array($alias, $this->qb->getAllAliases())) {
                 $this->qb->join("{$rootAlias}.{$assoc}", $alias);
             }
             $assoc = $alias;
         }
         $em = $this->qb->getEntityManager();
         $targetMeta = $em->getClassMetadata($targetClass);
         if (isset($subField) && !$targetMeta->hasField($subField) && $targetMeta->isInheritanceTypeJoined()) {
             foreach ($targetMeta->discriminatorMap as $alias => $class) {
                 $joinedMeta = $em->getClassMetadata($class);
                 if ($joinedMeta->hasField($subField)) {
                     if (!in_array($alias, $this->qb->getAllAliases())) {
                         $this->qb->leftJoin($joinedMeta->getName(), $alias, 'WITH', "{$alias}.id = {$assoc}.id");
                     }
                     $assoc = $alias;
                 }
             }
         }
         $alias = isset($subField) ? "{$assoc}.{$subField}" : $assoc;
     } else {
         $alias = "{$rootAlias}.{$field}";
     }
     $values = array_slice(func_get_args(), 1);
     if ($values) {
         $result = [$alias];
         foreach ($values as $value) {
             $paramName = $this->getParamName($field);
             $this->qb->setParameter($paramName, $value);
             $result[] = ":{$paramName}";
         }
         return $result;
     }
     return $alias;
 }
开发者ID:coolms,项目名称:doctrine-orm,代码行数:59,代码来源:Filter.php

示例14: applyJoins

 /**
  * Reapply joins from a set of joins got from getDQLPart('join')
  *
  * @param array $joinsSet
  */
 protected function applyJoins($joinsSet)
 {
     foreach ($joinsSet as $joins) {
         foreach ($joins as $join) {
             if ($join->getJoinType() === Join::LEFT_JOIN) {
                 $this->qb->leftJoin($join->getJoin(), $join->getAlias(), $join->getConditionType(), $join->getCondition(), $join->getIndexBy());
             } else {
                 $this->qb->join($join->getJoin(), $join->getAlias(), $join->getConditionType(), $join->getCondition(), $join->getIndexBy());
             }
         }
     }
 }
开发者ID:a2xchip,项目名称:pim-community-dev,代码行数:17,代码来源:BaseSorter.php

示例15: visitComparison

 /**
  * {@inheritdoc}
  *
  * @throws InvalidArgumentException When a comparison expression is not supported.
  */
 public function visitComparison(Expr\Comparison $comparison)
 {
     $property = $comparison->getProperty();
     $path = explode('.', $property->getPath());
     $expr = $this->builder->expr();
     $aliases = $this->builder->getAllAliases();
     $prefix = reset($aliases);
     foreach (array_slice($path, 0, -1) as $alias) {
         if (!in_array($alias, $aliases)) {
             $this->builder->join(sprintf('%s.%s', $prefix, $alias), $alias);
         }
         $prefix = $alias;
     }
     $field = sprintf('%s.%s', $prefix, end($path));
     $value = $comparison->getValue();
     switch (true) {
         case $comparison instanceof Expr\IdenticalTo:
         case $comparison instanceof Expr\EqualTo:
             return $expr->eq($field, $expr->literal($value));
         case $comparison instanceof Expr\NotIdenticalTo:
         case $comparison instanceof Expr\NotEqualTo:
             return $expr->neq($field, $expr->literal($value));
         case $comparison instanceof Expr\LessThan:
             return $expr->lt($field, $expr->literal($value));
         case $comparison instanceof Expr\LessThanOrEqualTo:
             return $expr->lte($field, $expr->literal($value));
         case $comparison instanceof Expr\GreaterThan:
             return $expr->gt($field, $expr->literal($value));
         case $comparison instanceof Expr\GreaterThanOrEqualTo:
             return $expr->gte($field, $expr->literal($value));
         case $comparison instanceof Expr\In:
             return $expr->in($field, $expr->literal($value));
         case $comparison instanceof Expr\NotIn:
             return $expr->notIn($field, $expr->literal($value));
         case $comparison instanceof Expr\Contains:
             return $expr->like(sprintf('LOWER(%s)', $field), $expr->literal('%' . strtolower($value) . '%'));
     }
     throw new InvalidArgumentException(sprintf('Unsupported comparison operator "%s".', get_class($comparison)));
 }
开发者ID:php-common,项目名称:DoctrineORMSpecificationBridge,代码行数:44,代码来源:QueryBuilderVisitor.php


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