Exemplo n.º 1
0
 public function testGetMarketingList()
 {
     $id = 100;
     $entity = new \stdClass();
     $repository = $this->getMockBuilder('\\Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('find')->with($id)->will($this->returnValue($entity));
     $this->managerRegistry->expects($this->once())->method('getRepository')->with(MarketingListHelper::MARKETING_LIST)->will($this->returnValue($repository));
     $this->assertEquals($entity, $this->helper->getMarketingList($id));
 }
Exemplo n.º 2
0
 /**
  * Add marketingList instance to parameters.
  *
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $dataGrid = $event->getDatagrid();
     $dataGridName = $dataGrid->getName();
     $parameters = $dataGrid->getParameters();
     if (!$this->isApplicable($dataGridName, $parameters)) {
         return;
     }
     $dataSource = $dataGrid->getDatasource();
     if ($dataSource instanceof OrmDatasource) {
         $marketingListId = $this->marketingListHelper->getMarketingListIdByGridName($dataGridName);
         $marketingList = $this->marketingListHelper->getMarketingList($marketingListId);
         $dataSource->getQueryBuilder()->addSelect($marketingList->getId() . ' as marketingList')->setParameter('marketingListEntity', $marketingList);
     }
 }
Exemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function isApplicable(DatagridConfiguration $config)
 {
     $gridName = $config->offsetGetByPath(self::NAME_PATH);
     if (!empty($this->appliedFor[$gridName])) {
         return false;
     }
     if ($config->offsetGetByPath(Builder::DATASOURCE_TYPE_PATH) !== OrmDatasource::TYPE) {
         return false;
     }
     $marketingListId = $this->marketingListHelper->getMarketingListIdByGridName($gridName);
     if (!$marketingListId) {
         return false;
     }
     $marketingList = $this->marketingListHelper->getMarketingList($marketingListId);
     // Accept only segment based marketing lists
     return $marketingList && !$marketingList->isManual();
 }
Exemplo n.º 4
0
 /**
  * Get grid configuration based on marketing list type.
  *
  * Get segments or concrete entity grid configuration by marketing list type and entity.
  * This configuration will be used as marketing list items grid configuration.
  *
  * @param string $gridName
  * @return DatagridConfiguration
  */
 public function getConfiguration($gridName)
 {
     if (empty($this->configuration[$gridName])) {
         $marketingListId = $this->helper->getMarketingListIdByGridName($gridName);
         $marketingList = $this->helper->getMarketingList($marketingListId);
         if (!$marketingList) {
             throw new \RuntimeException(sprintf('Marketing List with id "%s" not found.', $marketingListId));
         }
         // Get configuration based on marketing list type
         if ($marketingList->isManual()) {
             $concreteGridName = $this->getEntityGridName($marketingList->getEntity());
         } else {
             $postfix = str_replace(self::GRID_PREFIX . $marketingList->getId(), '', $gridName);
             $concreteGridName = Segment::GRID_PREFIX . $marketingList->getSegment()->getId() . $postfix;
         }
         $concreteGridConfiguration = $this->chainConfigurationProvider->getConfiguration($concreteGridName);
         // Reset configured name to current gridName for further usage in Listener and Extension
         $concreteGridConfiguration->offsetSetByPath(self::GRID_NAME_OFFSET, $gridName);
         $this->configuration[$gridName] = $concreteGridConfiguration;
     }
     return $this->configuration[$gridName];
 }