Esempio n. 1
0
 /**
  * Checks whether the activity list has at least one accessible activity type
  *
  * @param string $entityClass
  *
  * @return bool
  */
 protected function hasApplicableActivityAssociations($entityClass)
 {
     $supportedActivities = $this->activityListProvider->getSupportedActivities();
     foreach ($supportedActivities as $supportedActivity) {
         if ($this->activityListProvider->isApplicableTarget($entityClass, $supportedActivity)) {
             return true;
         }
     }
     return false;
 }
 /**
  * @param EntityManager $em
  * @param array $data
  * @param string $entityIdField
  *
  * @return QueryBuilder
  */
 protected function createActivityQueryBuilder(EntityManager $em, array $data, $entityIdField)
 {
     $joinField = sprintf('%s.%s', $this->activityListAlias, ExtendHelper::buildAssociationName($data['entityClassName'], ActivityListEntityConfigDumperExtension::ASSOCIATION_KIND));
     $activityQb = $em->getRepository('OroActivityListBundle:ActivityList')->createQueryBuilder($this->activityListAlias)->select('1')->setMaxResults(1);
     $availableActivityAssociations = $this->activityManager->getActivityAssociations($data['entityClassName']);
     $availableClasses = array_map(function ($assoc) {
         return $assoc['className'];
     }, $availableActivityAssociations);
     $chosenActivities = $data['activityType']['value'];
     if (count($chosenActivities) === 1 && empty($chosenActivities[0])) {
         $chosenActivities = $this->activityListChainProvider->getSupportedActivities();
     }
     $chosenClasses = array_map(function ($className) {
         return $this->entityRoutingHelper->decodeClassName($className);
     }, $chosenActivities);
     $unavailableChoices = array_diff($chosenClasses, $availableClasses);
     if ($unavailableChoices) {
         $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;
 }
 /**
  * @param QueryBuilder $qb
  * @param array        $filterData
  * @param string       $rangeField
  * @param string       $activityListAlias
  */
 public function addFiltersToQuery(QueryBuilder $qb, $filterData, $rangeField = 'updatedAt', $activityListAlias = 'activity')
 {
     $dataSourceAdapter = new OrmFilterDatasourceAdapter($qb);
     if (isset($filterData['dateRange'])) {
         $this->dateTimeRangeFilter->init($rangeField, ['data_name' => sprintf('%s.%s', $activityListAlias, $rangeField)]);
         $datetimeForm = $this->dateTimeRangeFilter->getForm();
         if (!$datetimeForm->isSubmitted()) {
             $datetimeForm->submit($filterData['dateRange']);
         }
         $this->dateTimeRangeFilter->apply($dataSourceAdapter, $datetimeForm->getData());
     }
     if (isset($filterData['activityType'])) {
         $routingHelper = $this->routingHelper;
         $filterData['activityType']['value'] = array_map(function ($activityClass) use($routingHelper) {
             return $routingHelper->resolveEntityClass($activityClass);
         }, $filterData['activityType']['value']);
         $this->choiceFilter->init('relatedActivityClass', ['data_name' => sprintf('%s.relatedActivityClass', $activityListAlias), 'options' => ['field_options' => ['multiple' => true, 'choices' => array_flip($this->chainProvider->getSupportedActivities())]]]);
         $typeForm = $this->choiceFilter->getForm();
         if (!$typeForm->isSubmitted()) {
             $typeForm->submit($filterData['activityType']);
         }
         $this->choiceFilter->apply($dataSourceAdapter, $typeForm->getData());
     }
 }
 public function testGetSupportedActivities()
 {
     $this->assertEquals([TestActivityProvider::ACTIVITY_CLASS_NAME], $this->provider->getSupportedActivities());
 }