/** * 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); }
/** * {@inheritdoc} */ public function visitDatasource(DatagridConfiguration $config, DatasourceInterface $datasource) { if (!$this->isApplicable($config)) { return; } /** @var OrmDatasource $datasource */ $qb = $datasource->getQueryBuilder(); $dqlParts = $qb->getDQLParts(); if (empty($dqlParts['where'])) { return; } /** @var Andx $conditions */ $conditions = $dqlParts['where']; $parts = $conditions->getParts(); if (empty($parts)) { return; } $qb->resetDQLPart('where'); $addParameter = false; foreach ($parts as $part) { if (!is_string($part)) { $part = $qb->expr()->orX($part, $this->createItemsFunc($qb)); $addParameter = true; } $qb->andWhere($part); } $gridName = $config->offsetGetByPath(self::NAME_PATH); if ($addParameter) { $qb->setParameter('marketingListId', $this->marketingListHelper->getMarketingListIdByGridName($gridName)); } $this->appliedFor[$gridName] = true; }
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)); }
/** * 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]; }