예제 #1
0
 /**
  * @param EntityManager $em
  * @param array $data
  * @param string $entityIdField
  *
  * @return QueryBuilder
  */
 protected function createActivityQueryBuilder(EntityManager $em, array $data, $entityIdField)
 {
     $entityClass = $data['entityClassName'];
     $joinField = sprintf('%s.%s', $this->activityListAlias, ExtendHelper::buildAssociationName($entityClass, ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND));
     $activityListRepository = $em->getRepository('OroActivityListBundle:ActivityList');
     $activityQb = $activityListRepository->createQueryBuilder($this->activityListAlias)->select('1')->setMaxResults(1);
     if (!$this->activityAssociationHelper->hasActivityAssociations($entityClass) && !$activityListRepository->getRecordsCountForTargetClass($entityClass)) {
         $activityQb->andWhere('1 = 0');
         return $activityQb;
     }
     $activityQb->join($joinField, $this->activityAlias)->andWhere(sprintf('%s.id = %s.%s', $this->activityAlias, $this->getEntityAlias(), $entityIdField));
     $entityField = $this->getField();
     $dateRangeField = strpos($entityField, '$') === 0 ? substr($entityField, 1) : null;
     if ($dateRangeField) {
         $data['dateRange'] = $data['filter']['data'];
         unset($data['filter']);
     }
     $this->activityListFilterHelper->addFiltersToQuery($activityQb, $data, $dateRangeField, $this->activityListAlias);
     if (isset($data['filter'])) {
         $activityDs = new OrmFilterDatasourceAdapter($activityQb);
         $expr = $activityDs->expr()->exists($this->createRelatedActivityDql($activityDs, $data));
         $this->applyFilterToClause($activityDs, $expr);
     }
     return $activityQb;
 }
 public function testHasActivityAssociations()
 {
     $entityClass = 'Test\\Entity';
     $activity1Class = 'Test\\Activity1';
     $activity2Class = 'Test\\Activity2';
     $config = new Config(new EntityConfigId('activity', $entityClass));
     $config->set('activities', [$activity1Class, $activity2Class]);
     $associationName = ExtendHelper::buildAssociationName($entityClass, ActivityScope::ASSOCIATION_KIND);
     $association1Config = new Config(new FieldConfigId('extend', $activity1Class, $associationName));
     $association1Config->set('is_extend', true);
     $association1Config->set('state', ExtendScope::STATE_NEW);
     $association2Config = new Config(new FieldConfigId('extend', $activity2Class, $associationName));
     $association2Config->set('is_extend', true);
     $association2Config->set('state', ExtendScope::STATE_ACTIVE);
     $this->configManager->expects($this->exactly(3))->method('hasConfig')->with()->willReturnMap([[$entityClass, null, true], [$activity1Class, $associationName, true], [$activity2Class, $associationName, true]]);
     $this->configManager->expects($this->once())->method('getEntityConfig')->with('activity', $entityClass)->willReturn($config);
     $this->configManager->expects($this->exactly(2))->method('getFieldConfig')->willReturnMap([['extend', $activity1Class, $associationName, $association1Config], ['extend', $activity2Class, $associationName, $association2Config]]);
     $this->assertTrue($this->activityAssociationHelper->hasActivityAssociations($entityClass));
 }
 /**
  * {@inheritdoc}
  */
 public function isApplicableTarget($entityClass, $accessible = true)
 {
     return $this->activityAssociationHelper->isActivityAssociationEnabled($entityClass, self::ACTIVITY_CLASS, $accessible);
 }