Пример #1
0
 /**
  * Returns a query builder that could be used for fetching the list of entities
  * associated with the given activity
  *
  * @param string      $activityClassName The FQCN of the activity entity
  * @param mixed       $filters           Criteria is used to filter activity entities
  *                                       e.g. ['age' => 20, ...] or \Doctrine\Common\Collections\Criteria
  * @param array|null  $joins             Additional associations required to filter activity entities
  * @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
  *
  * @return SqlQueryBuilder|null SqlQueryBuilder object or NULL if the given entity type has no activity associations
  */
 public function getActivityTargetsQueryBuilder($activityClassName, $filters, $joins = null, $limit = null, $page = null, $orderBy = null)
 {
     $targets = $this->getActivityTargets($activityClassName);
     if (empty($targets)) {
         return null;
     }
     return $this->associationManager->getMultiAssociationsQueryBuilder($activityClassName, $filters, $joins, $targets, $limit, $page, $orderBy);
 }
Пример #2
0
 public function testGetMultiAssociationsQueryBuilder()
 {
     $ownerClass = 'Oro\\Bundle\\EntityExtendBundle\\Tests\\Unit\\Fixtures\\Associations\\TestOwner1';
     $targetClass1 = 'Oro\\Bundle\\EntityExtendBundle\\Tests\\Unit\\Fixtures\\Associations\\TestTarget1';
     $targetClass2 = 'Oro\\Bundle\\EntityExtendBundle\\Tests\\Unit\\Fixtures\\Associations\\TestTarget2';
     $filters = ['name' => 'test', 'phones.phone' => '123-456'];
     $joins = ['phones'];
     $associationTargets = [$targetClass1 => 'targets_1', $targetClass2 => 'targets_2'];
     $this->aclHelper->expects($this->at(0))->method('apply')->willReturnCallback(function (QueryBuilder $qb) {
         return $qb->andWhere('target.age = 10')->getQuery();
     });
     $this->aclHelper->expects($this->at(1))->method('apply')->willReturnCallback(function (QueryBuilder $qb) {
         return $qb->andWhere('target.age = 100')->getQuery();
     });
     $this->entityNameResolver->expects($this->at(0))->method('getNameDQL')->with($targetClass1, 'target')->willReturn('CONCAT(target.firstName, CONCAT(\' \', target.lastName))');
     $this->entityNameResolver->expects($this->at(1))->method('getNameDQL')->with($targetClass2, 'target')->willReturn('CONCAT(target.firstName, CONCAT(\' \', target.lastName))');
     $result = $this->associationManager->getMultiAssociationsQueryBuilder($ownerClass, $filters, $joins, $associationTargets, 5, 2, 'title');
     $this->assertEquals('SELECT entity.id_1 AS id, entity.sclr_2 AS entity, entity.sclr_3 AS title ' . 'FROM (' . 'SELECT DISTINCT t0_.id AS id_0, t1_.id AS id_1, ' . '\'' . $targetClass1 . '\' AS sclr_2, ' . 't1_.firstName || \' \' || t1_.lastName || \'\' AS sclr_3 ' . 'FROM test_owner1 t0_ ' . 'INNER JOIN test_owner1_to_target1 t2_ ON t0_.id = t2_.owner_id ' . 'INNER JOIN test_target1 t1_ ON t1_.id = t2_.target_id ' . 'LEFT JOIN test_phone t3_ ON t0_.id = t3_.owner_id ' . 'WHERE (t0_.name = \'test\' AND t3_.phone = \'123-456\') AND t1_.age = 10' . ' UNION ALL ' . 'SELECT DISTINCT t0_.id AS id_0, t1_.id AS id_1, ' . '\'' . $targetClass2 . '\' AS sclr_2, ' . 't1_.firstName || \' \' || t1_.lastName || \'\' AS sclr_3 ' . 'FROM test_owner1 t0_ ' . 'INNER JOIN test_owner1_to_target2 t2_ ON t0_.id = t2_.owner_id ' . 'INNER JOIN test_target2 t1_ ON t1_.id = t2_.target_id ' . 'LEFT JOIN test_phone t3_ ON t0_.id = t3_.owner_id ' . 'WHERE (t0_.name = \'test\' AND t3_.phone = \'123-456\') AND t1_.age = 100' . ') entity ORDER BY title ASC LIMIT 5 OFFSET 5', $result->getSQL());
 }