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


PHP DoctrineHelper::applyJoins方法代码示例

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


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

示例1: testApplyJoins

 public function testApplyJoins()
 {
     $joins = ['emails' => null, 'phones', 'contacts' => [], 'accounts' => ['join' => 'accounts_field'], 'users' => ['join' => 'accounts.users_field', 'condition' => 'users.active = true', 'conditionType' => 'WITH'], 'products' => ['condition' => 'products.active = true']];
     $qb = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
     $qb->expects($this->once())->method('distinct')->with(true);
     $qb->expects($this->once())->method('getRootAliases')->willReturn(['root_alias']);
     $qb->expects($this->at(2))->method('leftJoin')->with('root_alias.emails', 'emails');
     $qb->expects($this->at(3))->method('leftJoin')->with('root_alias.phones', 'phones');
     $qb->expects($this->at(4))->method('leftJoin')->with('root_alias.contacts', 'contacts');
     $qb->expects($this->at(5))->method('leftJoin')->with('root_alias.accounts_field', 'accounts');
     $qb->expects($this->at(6))->method('leftJoin')->with('accounts.users_field', 'users', 'WITH', 'users.active = true');
     $qb->expects($this->at(7))->method('leftJoin')->with('root_alias.products', 'products', 'WITH', 'products.active = true');
     $this->doctrineHelper->applyJoins($qb, $joins);
 }
开发者ID:hugeval,项目名称:platform,代码行数:14,代码来源:DoctrineHelperTest.php

示例2: getMultiAssociationOwnersQueryBuilder

 /**
  * Returns a query builder that could be used for fetching the list of entities
  * associated with $associationOwnerClass entities found by $filters and $joins
  *
  * @param string      $associationTargetClass The FQCN of the entity that is the owning side of the association
  * @param mixed|null  $filters                Criteria is used to filter entities which are association owners
  *                                            e.g. ['age' => 20, ...] or \Doctrine\Common\Collections\Criteria
  * @param array|null  $joins                  Additional associations required to filter owning side entities
  * @param array       $associationOwners      The list of fields responsible to store associations between
  *                                            the given target and association owners
  *                                            Array format: [owner_entity_class => field_name]
  * @param int         $limit                  The maximum number of items per page
  * @param int         $page                   The page number
  * @param string|null $orderBy                The ordering expression for the result
  *
  * @return SqlQueryBuilder
  */
 public function getMultiAssociationOwnersQueryBuilder($associationTargetClass, $filters, $joins, $associationOwners, $limit = null, $page = null, $orderBy = null)
 {
     $em = $this->doctrineHelper->getEntityManager($associationTargetClass);
     $criteria = $this->doctrineHelper->normalizeCriteria($filters);
     $selectStmt = null;
     $subQueries = [];
     $targetIdFieldName = $this->doctrineHelper->getSingleEntityIdentifierFieldName($associationTargetClass);
     foreach ($associationOwners as $ownerClass => $fieldName) {
         // dispatch oro_api.request.get_list.before event
         $event = new GetListBefore($this->cloneCriteria($criteria), $associationTargetClass);
         $this->eventDispatcher->dispatch(GetListBefore::NAME, $event);
         $subCriteria = $event->getCriteria();
         $nameExpr = $this->entityNameResolver->getNameDQL($ownerClass, 'e');
         $subQb = $em->getRepository($ownerClass)->createQueryBuilder('e')->select(sprintf('target.%s AS id, e.id AS entityId, \'%s\' AS entityClass, ' . ($nameExpr ?: '\'\'') . ' AS entityTitle', $targetIdFieldName, str_replace('\'', '\'\'', $ownerClass)))->innerJoin('e.' . $fieldName, 'target');
         $this->doctrineHelper->applyJoins($subQb, $joins);
         // fix of doctrine error with Same Field, Multiple Values, Criteria and QueryBuilder
         // http://www.doctrine-project.org/jira/browse/DDC-2798
         // TODO revert changes when doctrine version >= 2.5 in scope of BAP-5577
         QueryBuilderHelper::addCriteria($subQb, $subCriteria);
         // $subQb->addCriteria($criteria);
         $subQuery = $subQb->getQuery();
         $subQueries[] = QueryUtils::getExecutableSql($subQuery);
         if (empty($selectStmt)) {
             $mapping = QueryUtils::parseQuery($subQuery)->getResultSetMapping();
             $selectStmt = sprintf('entity.%s AS id, entity.%s AS entity, entity.%s AS title', QueryUtils::getColumnNameByAlias($mapping, 'entityId'), QueryUtils::getColumnNameByAlias($mapping, 'entityClass'), QueryUtils::getColumnNameByAlias($mapping, 'entityTitle'));
         }
     }
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('id', 'id', Type::INTEGER)->addScalarResult('entity', 'entity')->addScalarResult('title', 'title');
     $qb = new SqlQueryBuilder($em, $rsm);
     $qb->select($selectStmt)->from('(' . implode(' UNION ALL ', $subQueries) . ')', 'entity');
     if (null !== $limit) {
         $qb->setMaxResults($limit);
         if (null !== $page) {
             $qb->setFirstResult($this->doctrineHelper->getPageOffset($page, $limit));
         }
     }
     if ($orderBy) {
         $qb->orderBy($orderBy);
     }
     return $qb;
 }
开发者ID:nmallare,项目名称:platform,代码行数:59,代码来源:AssociationManager.php

示例3: getMultiAssociationOwnersQueryBuilder

 /**
  * Returns a query builder that could be used for fetching the list of owner side entities
  * the specified $associationTargetClass associated with.
  * The $filters and $joins could be used to filter entities
  *
  * The resulting query would be something like this:
  * <code>
  * SELECT entity.entityId AS id, entity.entityClass AS entity, entity.entityTitle AS title FROM (
  *      SELECT [DISTINCT]
  *          target.id AS id,
  *          e.id AS entityId,
  *          {first_owner_entity_class} AS entityClass,
  *          {first_owner_title} AS entityTitle
  *      FROM {first_owner_entity_class} AS e
  *          INNER JOIN e.{target_field_name_for_first_owner} AS target
  *          {joins}
  *      WHERE {filters}
  *      UNION ALL
  *      SELECT [DISTINCT]
  *          target.id AS id,
  *          e.id AS entityId,
  *          {second_owner_entity_class} AS entityClass,
  *          {second_owner_title} AS entityTitle
  *      FROM {second_owner_entity_class} AS e
  *          INNER JOIN e.{target_field_name_for_second_owner} AS target
  *          {joins}
  *      WHERE {filters}
  *      UNION ALL
  *      ... select statements for other owners
  * ) entity
  * ORDER BY {orderBy}
  * LIMIT {limit} OFFSET {(page - 1) * limit}
  * </code>
  *
  * @param string        $associationTargetClass The FQCN of the entity that is the target side of the association
  * @param mixed|null    $filters                Criteria is used to filter entities which are association owners
  *                                              e.g. ['age' => 20, ...] or \Doctrine\Common\Collections\Criteria
  * @param array|null    $joins                  Additional associations required to filter owning side entities
  * @param array         $associationOwners      The list of fields responsible to store associations between
  *                                              the given target and association owners
  *                                              Array format: [owner_entity_class => field_name]
  * @param int|null      $limit                  The maximum number of items per page
  * @param int|null      $page                   The page number
  * @param string|null   $orderBy                The ordering expression for the result
  * @param callable|null $callback               A callback function which can be used to modify child queries
  *                                              function (QueryBuilder $qb, $ownerEntityClass)
  *
  * @return SqlQueryBuilder
  */
 public function getMultiAssociationOwnersQueryBuilder($associationTargetClass, $filters, $joins, $associationOwners, $limit = null, $page = null, $orderBy = null, $callback = null)
 {
     $em = $this->doctrineHelper->getEntityManager($associationTargetClass);
     $criteria = $this->doctrineHelper->normalizeCriteria($filters);
     $selectStmt = null;
     $subQueries = [];
     $targetIdFieldName = $this->doctrineHelper->getSingleEntityIdentifierFieldName($associationTargetClass);
     foreach ($associationOwners as $ownerClass => $fieldName) {
         $nameExpr = $this->entityNameResolver->getNameDQL($ownerClass, 'e');
         $subQb = $em->getRepository($ownerClass)->createQueryBuilder('e')->select(sprintf('target.%s AS id, e.id AS entityId, \'%s\' AS entityClass, ' . ($nameExpr ?: '\'\'') . ' AS entityTitle', $targetIdFieldName, str_replace('\'', '\'\'', $ownerClass)))->innerJoin('e.' . $fieldName, 'target');
         $this->doctrineHelper->applyJoins($subQb, $joins);
         $subQb->addCriteria($criteria);
         if (null !== $callback && is_callable($callback)) {
             call_user_func($callback, $subQb, $ownerClass);
         }
         $subQuery = $this->getAclHelper()->apply($subQb);
         $subQueries[] = QueryUtils::getExecutableSql($subQuery);
         if (empty($selectStmt)) {
             $mapping = QueryUtils::parseQuery($subQuery)->getResultSetMapping();
             $selectStmt = sprintf('entity.%s AS id, entity.%s AS entity, entity.%s AS title', QueryUtils::getColumnNameByAlias($mapping, 'entityId'), QueryUtils::getColumnNameByAlias($mapping, 'entityClass'), QueryUtils::getColumnNameByAlias($mapping, 'entityTitle'));
         }
     }
     $rsm = new ResultSetMapping();
     $rsm->addScalarResult('id', 'id', Type::INTEGER)->addScalarResult('entity', 'entity')->addScalarResult('title', 'title');
     $qb = new SqlQueryBuilder($em, $rsm);
     $qb->select($selectStmt)->from('(' . implode(' UNION ALL ', $subQueries) . ')', 'entity');
     if (null !== $limit) {
         $qb->setMaxResults($limit);
         if (null !== $page) {
             $qb->setFirstResult($this->doctrineHelper->getPageOffset($page, $limit));
         }
     }
     if ($orderBy) {
         $qb->orderBy($orderBy);
     }
     return $qb;
 }
开发者ID:hugeval,项目名称:platform,代码行数:86,代码来源:AssociationManager.php

示例4: applyJoins

 /**
  * Applies the given joins for the query builder
  *
  * @param QueryBuilder $qb
  * @param array|null   $joins
  */
 protected function applyJoins($qb, $joins)
 {
     $this->doctrineHelper->applyJoins($qb, $joins);
 }
开发者ID:northdakota,项目名称:platform,代码行数:10,代码来源:ApiEntityManager.php


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