Exemple #1
0
 /**
  * Create, configure and build datagrid
  *
  * @param DatagridConfiguration $config
  * @param ParameterBag          $parameters
  *
  * @return DatagridInterface
  */
 public function build(DatagridConfiguration $config, ParameterBag $parameters)
 {
     /**
      * @TODO: should be refactored in BAP-6849
      */
     $minified = $parameters->get(ParameterBag::MINIFIED_PARAMETERS);
     if (is_array($minified) && array_key_exists('g', $minified) && is_array($minified['g'])) {
         $gridParams = [];
         foreach ($minified['g'] as $gridParamName => $gridParamValue) {
             $gridParams[$gridParamName] = $gridParamValue;
         }
         $parameters->add($gridParams);
     }
     /**
      * @TODO: should be refactored in BAP-6826
      */
     $event = new PreBuild($config, $parameters);
     $this->eventDispatcher->dispatch(PreBuild::NAME, $event);
     $class = $config->offsetGetByPath(self::BASE_DATAGRID_CLASS_PATH, $this->baseDatagridClass);
     $name = $config->getName();
     /** @var DatagridInterface $datagrid */
     $datagrid = new $class($name, $config, $parameters);
     $datagrid->setScope($config->offsetGetOr('scope'));
     $event = new BuildBefore($datagrid, $config);
     $this->eventDispatcher->dispatch(BuildBefore::NAME, $event);
     $acceptor = $this->createAcceptor($config, $parameters);
     $datagrid->setAcceptor($acceptor);
     $this->buildDataSource($datagrid, $config);
     $acceptor->processConfiguration();
     $event = new BuildAfter($datagrid);
     $this->eventDispatcher->dispatch(BuildAfter::NAME, $event);
     return $datagrid;
 }
 /**
  * This listener is applicable for marketing list grids that has emailCampaign parameter set.
  *
  * @param string $gridName
  * @param ParameterBag $parameterBag
  *
  * @return bool
  */
 public function isApplicable($gridName, ParameterBag $parameterBag)
 {
     if (!$parameterBag->has('emailCampaign')) {
         return false;
     }
     return (bool) $this->marketingListHelper->getMarketingListIdByGridName($gridName);
 }
 /**
  * Accept orocrm_marketing_list_items_grid_* grids only in case when they has mixin to apply.
  *
  * @param string       $gridName
  * @param ParameterBag $parameters
  *
  * @return bool
  */
 public function isApplicable($gridName, $parameters)
 {
     if (!$parameters->get(self::MIXIN, false)) {
         return false;
     }
     return (bool) $this->marketingListHelper->getMarketingListIdByGridName($gridName);
 }
 /**
  * @param string       $gridName
  * @param ParameterBag $parameterBag
  *
  * @return bool
  */
 public function isApplicable($gridName, ParameterBag $parameterBag)
 {
     if ($parameterBag->get(MarketingListItemsListener::MIXIN, false) !== self::MIXIN_NAME) {
         return false;
     }
     $segmentId = $this->segmentHelper->getSegmentIdByGridName($gridName);
     return $segmentId && (bool) $this->segmentHelper->getMarketingListBySegment($segmentId);
 }
 /**
  * @test
  */
 public function testProcess()
 {
     $this->doctrineRegistry->expects($this->any())->method('getManager')->will($this->returnValue($this->manager));
     $this->manager->expects($this->once())->method('createQueryBuilder')->will($this->returnValue($this->queryBuilder))->with($this->equalTo('a'));
     $this->grid->expects($this->once())->method('getParameters')->will($this->returnValue($this->parameterBag));
     $this->parameterBag->expects($this->once())->method('get')->will($this->returnValue(1));
     $this->grid->expects($this->once())->method('setDatasource');
     $this->combinedAuditDatasource->process($this->grid, []);
 }
 /**
  * @param ParameterBag $parameters
  * @param mixed        $userId
  */
 public function handleRefresh($parameters, $userId)
 {
     $additionalParameters = $parameters->get(ParameterBag::ADDITIONAL_PARAMETERS);
     if (!empty($additionalParameters) && array_key_exists('refresh', $additionalParameters)) {
         $emailOrigins = $this->getEmailOrigins($userId);
         if (!empty($emailOrigins)) {
             $this->emailSyncManager->syncOrigins($emailOrigins);
         }
     }
 }
 /**
  * @param ParameterBag $parameters
  */
 public function setParameters(ParameterBag $parameters)
 {
     if ($parameters->has(ParameterBag::MINIFIED_PARAMETERS)) {
         $minifiedParameters = $parameters->get(ParameterBag::MINIFIED_PARAMETERS);
         $additional = $parameters->get(ParameterBag::ADDITIONAL_PARAMETERS, []);
         if (array_key_exists(self::MINIFIED_VIEWS_PARAM_KEY, $minifiedParameters)) {
             $additional[self::VIEWS_PARAM_KEY] = $minifiedParameters[self::MINIFIED_VIEWS_PARAM_KEY];
         }
         $parameters->set(ParameterBag::ADDITIONAL_PARAMETERS, $additional);
     }
     parent::setParameters($parameters);
 }
 /**
  *
  * @dataProvider preBuildDataProvider
  * @param bool $isSent
  * @param string $expectedMixin
  */
 public function testOnPreBuildSentCampaign($isSent, $expectedMixin)
 {
     $id = 1;
     $gridName = ConfigurationProvider::GRID_PREFIX;
     $parameters = new ParameterBag(['emailCampaign' => $id]);
     $config = DatagridConfiguration::create(['name' => $gridName, 'source' => ['query' => ['where' => '1 = 0']]]);
     $this->marketingListHelper->expects($this->any())->method('getMarketingListIdByGridName')->with($this->equalTo($gridName))->will($this->returnValue($id));
     $marketingList = $this->getMockBuilder('OroCRM\\Bundle\\CampaignBundle\\Entity\\EmailCampaign')->disableOriginalConstructor()->getMock();
     $marketingList->expects($this->once())->method('isSent')->will($this->returnValue($isSent));
     $this->assertEntityFind($id, $marketingList);
     $this->listener->onPreBuild(new PreBuild($config, $parameters));
     if ($isSent) {
         $this->assertEmpty($config->offsetGetByPath(CampaignStatisticDatagridListener::PATH_DATAGRID_WHERE));
     }
     $this->assertEquals($expectedMixin, $parameters->get(MixinListener::GRID_MIXIN));
 }
 /**
  * @param ParameterBag $parameters
  */
 public function setParameters(ParameterBag $parameters)
 {
     if ($parameters->has(ParameterBag::MINIFIED_PARAMETERS)) {
         $minifiedParameters = $parameters->get(ParameterBag::MINIFIED_PARAMETERS);
         $sorters = [];
         if (array_key_exists(self::MINIFIED_SORTERS_PARAM, $minifiedParameters)) {
             $sorters = $minifiedParameters[self::MINIFIED_SORTERS_PARAM];
             if (is_array($sorters)) {
                 foreach ($sorters as $field => $direction) {
                     $sorters[$field] = $direction > 0 ? self::DIRECTION_DESC : self::DIRECTION_ASC;
                 }
             }
         }
         $parameters->set(self::SORTERS_ROOT_PARAM, $sorters);
     }
     parent::setParameters($parameters);
 }
 /**
  * Set columns params data from minified params
  *
  * @param ParameterBag $parameters
  */
 public function setParameters(ParameterBag $parameters)
 {
     if ($parameters->has(ParameterBag::MINIFIED_PARAMETERS)) {
         $minifiedParameters = $parameters->get(ParameterBag::MINIFIED_PARAMETERS);
         $columns = '';
         if (array_key_exists(self::MINIFIED_COLUMNS_PARAM, $minifiedParameters)) {
             $columns = $minifiedParameters[self::MINIFIED_COLUMNS_PARAM];
         }
         $parameters->set(self::MINIFIED_COLUMNS_PARAM, $columns);
     }
     parent::setParameters($parameters);
 }
 /**
  * @param ParameterBag $parameters
  */
 public function setParameters(ParameterBag $parameters)
 {
     if ($parameters->has(ParameterBag::MINIFIED_PARAMETERS)) {
         $minifiedParameters = $parameters->get(ParameterBag::MINIFIED_PARAMETERS);
         $filters = [];
         if (array_key_exists(self::MINIFIED_FILTER_PARAM, $minifiedParameters)) {
             $filters = $minifiedParameters[self::MINIFIED_FILTER_PARAM];
         }
         $parameters->set(self::FILTER_ROOT_PARAM, $filters);
     }
     parent::setParameters($parameters);
 }
 /**
  * @param ParameterBag $parameters
  */
 public function setParameters(ParameterBag $parameters)
 {
     if ($parameters->has(ParameterBag::MINIFIED_PARAMETERS)) {
         $minifiedParameters = $parameters->get(ParameterBag::MINIFIED_PARAMETERS);
         $pager = [];
         if (array_key_exists(PagerInterface::MINIFIED_PAGE_PARAM, $minifiedParameters)) {
             $pager[PagerInterface::PAGE_PARAM] = $minifiedParameters[PagerInterface::MINIFIED_PAGE_PARAM];
         }
         if (array_key_exists(PagerInterface::MINIFIED_PER_PAGE_PARAM, $minifiedParameters)) {
             $pager[PagerInterface::PER_PAGE_PARAM] = $minifiedParameters[PagerInterface::MINIFIED_PER_PAGE_PARAM];
         }
         $parameters->set(PagerInterface::PAGER_ROOT_PARAM, $pager);
     }
     parent::setParameters($parameters);
 }
 /**
  * {@inheritdoc}
  */
 protected function prepareQuery(QueryBuilder $query, $rootAlias, $alias, $itemsType)
 {
     $query->setParameter('entity_id', $this->parameters->get(self::ENTITY_PARAM, 0));
     return parent::prepareQuery($query, $rootAlias, $alias, $itemsType);
 }
Exemple #14
0
 /**
  * @param DatagridConfiguration $config
  * @param ParameterBag          $parameters
  *
  * @return string[]
  */
 protected function getMixins(DatagridConfiguration $config, ParameterBag $parameters)
 {
     $mixins = (array) $config->offsetGetOr(self::MIXINS, []);
     $mixins = array_merge($mixins, (array) $parameters->get(self::GRID_MIXIN, []));
     return $mixins;
 }
 /**
  * @param string       $gridName
  * @param ParameterBag $parameters
  *
  * @return bool
  */
 public function isApplicable($gridName, $parameters)
 {
     if (!$parameters->get(self::MIXIN, false)) {
         return false;
     }
     $segmentId = $this->segmentHelper->getSegmentIdByGridName($gridName);
     return $segmentId && (bool) $this->segmentHelper->getMarketingListBySegment($segmentId);
 }