Ejemplo n.º 1
0
 /**
  * @param MarketingList $marketingList
  * @return BufferedQueryResultIterator|null
  */
 public function getMarketingListEntitiesIterator(MarketingList $marketingList)
 {
     if ($marketingList->getType()->getName() !== MarketingListType::TYPE_MANUAL) {
         return new BufferedQueryResultIterator($this->getMarketingListEntitiesQueryBuilder($marketingList), false);
     }
     return null;
 }
 protected function setUp()
 {
     $this->marketingList = $this->getMockBuilder('OroCRM\\Bundle\\MarketingListBundle\\Entity\\MarketingList')->disableOriginalConstructor()->getMock();
     $this->segment = $this->getMockBuilder('Oro\\Bundle\\SegmentBundle\\Entity\\Segment')->disableOriginalConstructor()->getMock();
     $this->marketingList->expects($this->any())->method('getSegment')->will($this->returnValue($this->segment));
     $this->factory = new ColumnDefinitionListFactory();
 }
Ejemplo n.º 3
0
 /**
  * @param MarketingList $marketingList
  * @param array $result
  * @return MarketingListItem
  */
 public function contactResultRow(MarketingList $marketingList, array $result)
 {
     $idName = $this->doctrineHelper->getSingleEntityIdentifierFieldName($marketingList->getEntity());
     if (empty($result[$idName])) {
         throw new \InvalidArgumentException('Result row must contain identifier field');
     }
     return $this->contact($marketingList, $result[$idName]);
 }
Ejemplo n.º 4
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $type = $manager->getRepository('OroCRMMarketingListBundle:MarketingListType')->find(MarketingListType::TYPE_DYNAMIC);
     $entity = new MarketingList();
     $entity->setType($type)->setName('list_name')->setEntity('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->setOrganization($manager->getRepository('OroOrganizationBundle:Organization')->getFirst());
     $manager->persist($entity);
     $manager->flush($entity);
 }
Ejemplo n.º 5
0
 public function testGetEntityName()
 {
     $marketingList = new MarketingList();
     $marketingList->setEntity('\\stdClass');
     $campaign = new EmailCampaign();
     $this->assertNull($campaign->getEntityName());
     $campaign->setMarketingList($marketingList);
     $this->assertEquals($marketingList->getEntity(), $campaign->getEntityName());
 }
 /**
  * @param MarketingList $marketingList
  * @param string|null $type
  * @return array
  */
 public function getMarketingListTypedFields(MarketingList $marketingList, $type = null)
 {
     if ($marketingList->isManual()) {
         $typedFields = $this->getEntityTypedFields($marketingList->getEntity(), $type);
     } else {
         $typedFields = $this->getQueryTypedFields($marketingList->getSegment(), $type);
     }
     return $typedFields;
 }
 /**
  * {@inheritdoc}
  */
 public function getDataGridConfiguration(MarketingList $marketingList)
 {
     if ($marketingList->isManual()) {
         $mixin = MarketingListProvider::MANUAL_RESULT_ENTITIES_MIXIN;
     } else {
         $mixin = MarketingListProvider::RESULT_ENTITIES_MIXIN;
     }
     $dataGrid = $this->getMarketingListDataGrid($marketingList, $mixin);
     return $dataGrid->getConfig();
 }
Ejemplo n.º 8
0
 public function testDelete()
 {
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $type = $em->getRepository('OroCRMMarketingListBundle:MarketingListType')->find(MarketingListType::TYPE_DYNAMIC);
     $entity = new MarketingList();
     $entity->setType($type)->setName('list_name')->setEntity('entity');
     $em->persist($entity);
     $em->flush($entity);
     $this->assertNotNull($entity->getId());
     $this->client->request('DELETE', $this->getUrl('orocrm_api_delete_marketinglist', ['id' => $entity->getId()]), [], [], $this->generateWsseAuthHeader());
     $result = $this->client->getResponse();
     $this->assertEmptyResponseStatusCodeEquals($result, Codes::HTTP_NO_CONTENT);
 }
Ejemplo n.º 9
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Sender email and name is empty
  */
 public function testFromEmpty()
 {
     $entity = new \stdClass();
     $this->helper->expects($this->once())->method('getSingleEntityIdentifier')->will($this->returnValue(1));
     $marketingList = new MarketingList();
     $marketingList->setEntity($entity);
     $template = new EmailTemplate();
     $template->setType('html');
     $settings = new InternalTransportSettings();
     $settings->setTemplate($template);
     $campaign = new EmailCampaign();
     $campaign->setMarketingList($marketingList)->setTransportSettings($settings);
     $this->transport->send($campaign, $entity, [], []);
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     foreach ($this->mlData as $data) {
         $entity = new MarketingList();
         $type = $manager->getRepository('OroCRMMarketingListBundle:MarketingListType')->find($data['type']);
         $segment = $this->getReference($data['segment']);
         $entity->setType($type);
         $entity->setSegment($segment);
         $this->setEntityPropertyValues($entity, $data, ['reference', 'type', 'segment']);
         $this->setReference($data['reference'], $entity);
         $manager->persist($entity);
     }
     $manager->flush();
 }
Ejemplo n.º 11
0
 protected function assertSegmentData()
 {
     $segmentType = new SegmentType(SegmentType::TYPE_DYNAMIC);
     $segment = $this->testEntity->getSegment();
     $this->assertEquals('Marketing List test segment', $segment->getName());
     $this->assertEquals('test', $segment->getDefinition());
     $this->assertEquals($this->testEntity->getOwner()->getOwner(), $segment->getOwner());
     $this->assertEquals($segmentType, $segment->getType());
 }
Ejemplo n.º 12
0
 protected function assertGetQueryBuilder(MarketingList $marketingList, $queryBuilder, $dataGrid, $mixin = null)
 {
     $dataSource = $this->getMockBuilder('Oro\\Bundle\\DataGridBundle\\Datasource\\Orm\\OrmDatasource')->disableOriginalConstructor()->getMock();
     $dataSource->expects($this->once())->method('getQueryBuilder')->will($this->returnValue($queryBuilder));
     $dataGrid->expects($this->once())->method('getAcceptedDatasource')->will($this->returnValue($dataSource));
     $parameters = [PagerInterface::PAGER_ROOT_PARAM => [PagerInterface::DISABLED_PARAM => true]];
     if ($mixin) {
         $parameters['grid-mixin'] = $mixin;
     }
     $this->dataGridManager->expects($this->atLeastOnce())->method('getDatagrid')->with(ConfigurationProvider::GRID_PREFIX . $marketingList->getId(), $parameters)->will($this->returnValue($dataGrid));
 }
 /**
  * {@inheritdoc}
  */
 protected function getEntitiesQueryBuilder(MarketingList $marketingList)
 {
     $className = $marketingList->getEntity();
     $qb = $this->doctrineHelper->getEntityManager($className)->getRepository($className)->createQueryBuilder('e');
     return $qb;
 }
Ejemplo n.º 14
0
 /**
  * @param MarketingList $marketingList
  * @param DatagridInterface $dataGrid
  * @param QueryBuilder $qb
  */
 protected function saveColumnInformation(MarketingList $marketingList, DatagridInterface $dataGrid, QueryBuilder $qb)
 {
     /** @var Select[] $selects */
     $selects = $qb->getDQLPart('select');
     $columnToSelectExpr = [];
     foreach ($selects as $select) {
         foreach ($select->getParts() as $selectPart) {
             $selectData = explode(strrev(' as '), strrev($selectPart), 2);
             if (count($selectData) === 2) {
                 $columnToSelectExpr[strrev($selectData[0])] = strrev($selectData[1]);
             }
         }
     }
     $columnAliases = $dataGrid->getConfig()->offsetGetByPath(self::DATAGRID_COLUMN_ALIASES_PATH);
     $columnInformation = [];
     foreach ($columnAliases as $alias => $selectAlias) {
         if (array_key_exists($selectAlias, $columnToSelectExpr)) {
             $columnInformation[$alias] = $columnToSelectExpr[$selectAlias];
         }
     }
     $this->columnInformation[$marketingList->getId()] = $columnInformation;
 }
Ejemplo n.º 15
0
 /**
  * @return null|string
  */
 public function getEntityName()
 {
     if ($this->marketingList) {
         return $this->marketingList->getEntity();
     }
     return null;
 }
Ejemplo n.º 16
0
 /**
  * @param array $iterable
  *
  * @dataProvider sendDataProvider
  */
 public function testSendError($iterable, $to)
 {
     $segment = new Segment();
     $marketingList = new MarketingList();
     $marketingList->setSegment($segment);
     $campaign = new EmailCampaign();
     $campaign->setMarketingList($marketingList)->setSenderEmail(reset($to));
     $itCount = count($iterable);
     $this->marketingListProvider->expects($this->once())->method('getMarketingListEntitiesIterator')->will($this->returnValue($iterable));
     $manager = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($manager));
     $manager->expects($this->once())->method('persist')->with($campaign);
     $manager->expects($this->atLeastOnce())->method('flush');
     $manager->expects($this->exactly($itCount))->method('beginTransaction');
     $manager->expects($this->exactly($itCount))->method('rollback');
     if ($itCount) {
         $this->contactInformationFieldsProvider->expects($this->exactly($itCount))->method('getQueryContactInformationFields')->with($this->equalTo($segment), $this->isType('object'), $this->equalTo(ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL))->will($this->returnValue($to));
         $this->marketingListConnector->expects($this->exactly($itCount))->method('contact')->with($this->equalTo($marketingList), $this->equalTo(self::ENTITY_ID))->will($this->returnCallback(function () {
             throw new \Exception('Error');
         }));
         $this->logger->expects($this->exactly($itCount))->method('error');
     }
     $this->transport->expects($this->exactly($itCount))->method('send');
     $this->transportProvider->expects($this->once())->method('getTransportByName')->will($this->returnValue($this->transport));
     $this->sender->setEmailCampaign($campaign);
     $this->sender->send($campaign);
 }
Ejemplo n.º 17
0
 public function testDoUpdate()
 {
     $this->assertNull($this->entity->getUpdatedAt());
     $this->entity->doUpdate();
     $this->assertInstanceOf('\\DateTime', $this->entity->getUpdatedAt());
 }
Ejemplo n.º 18
0
 /**
  * @param MarketingList $marketingList
  * @param null|string $mixin
  *
  * @return DatagridInterface
  */
 protected function getMarketingListDataGrid(MarketingList $marketingList, $mixin = null)
 {
     $dataGridName = ConfigurationProvider::GRID_PREFIX . $marketingList->getId();
     $resultKey = $dataGridName . $mixin;
     if (empty($this->dataGrid[$resultKey])) {
         $gridParameters = [PagerInterface::PAGER_ROOT_PARAM => [PagerInterface::DISABLED_PARAM => true], TagsExtension::TAGS_ROOT_PARAM => [TagsExtension::DISABLED_PARAM => true]];
         if ($mixin) {
             $gridParameters['grid-mixin'] = $mixin;
         }
         $this->dataGrid[$resultKey] = $this->dataGridManager->getDatagrid($dataGridName, $gridParameters);
     }
     return $this->dataGrid[$resultKey];
 }
 /**
  * @param MarketingList $marketingList
  * @return ColumnDefinitionListInterface
  */
 public function create(MarketingList $marketingList)
 {
     $segment = $marketingList->getSegment();
     $columnDefinitionList = new ColumnDefinitionList($segment);
     return $columnDefinitionList;
 }
 /**
  * @param MarketingList $marketingList
  * @param int           $id
  *
  * @Rest\Get(
  *      "/marketinglist/{marketingList}/unremove/{id}"
  * )
  * @ApiDoc(
  *     description="Delete MarketingListRemovedItem by marketing list entity",
  *     resource=true
  * )
  * @AclAncestor("orocrm_marketing_list_removed_item_delete")
  *
  * @return Response
  */
 public function unremoveAction(MarketingList $marketingList, $id)
 {
     /** @var MarketingListRemovedItem[] $forRemove */
     $forRemove = $this->getManager()->getRepository()->findBy(array('marketingList' => $marketingList, 'entityId' => $id));
     if ($forRemove) {
         try {
             $item = $forRemove[0];
             $this->getDeleteHandler()->handleDelete($item->getId(), $this->getManager());
         } catch (EntityNotFoundException $notFoundEx) {
             return $this->handleView($this->view(null, Codes::HTTP_NOT_FOUND));
         } catch (ForbiddenException $forbiddenEx) {
             return $this->handleView($this->view(['reason' => $forbiddenEx->getReason()], Codes::HTTP_FORBIDDEN));
         }
     }
     $entityName = $this->get('oro_entity_config.provider.entity')->getConfig($marketingList->getEntity())->get('label');
     return $this->handleView($this->view(array('successful' => true, 'message' => $this->get('translator')->trans('orocrm.marketinglist.controller.unremoved', ['%entityName%' => $this->get('translator')->trans($entityName)])), Codes::HTTP_OK));
 }
Ejemplo n.º 21
0
 /**
  * Validate Marketing List.
  *
  * @param MarketingList $marketingList
  * @return bool
  */
 protected function isValid(MarketingList $marketingList)
 {
     $errors = $this->validator->validate($marketingList->getSegment(), array('marketing_list'));
     if (count($errors) > 0) {
         /** @var ConstraintViolationInterface $error */
         foreach ($errors as $error) {
             $this->form->addError(new FormError($error->getMessage(), $error->getMessageTemplate(), $error->getMessageParameters(), $error->getMessagePluralization()));
         }
     }
     return $this->form->isValid();
 }
 /**
  * @return array
  */
 public function preSubmitDataProvider()
 {
     $marketingList = new MarketingList();
     $marketingList->setEntity('\\stdClass');
     return [[[], null, false], [['parentData' => ['marketingList' => 1]], null, false], [['parentData' => ['marketingList' => 1]], $marketingList, true]];
 }
Ejemplo n.º 23
0
 /**
  * @Route("/view/{id}", name="orocrm_marketing_list_view", requirements={"id"="\d+"}, defaults={"id"=0})
  * @Acl(
  *      id="orocrm_marketing_list_view",
  *      type="entity",
  *      permission="VIEW",
  *      class="OroCRMMarketingListBundle:MarketingList"
  * )
  * @Template
  *
  * @param MarketingList $entity
  *
  * @return array
  */
 public function viewAction(MarketingList $entity)
 {
     $entityConfig = $this->get('orocrm_marketing_list.entity_provider')->getEntity($entity->getEntity());
     return ['entity' => $entity, 'config' => $entityConfig, 'gridName' => Segment::GRID_PREFIX . $entity->getSegment()->getId()];
 }
Ejemplo n.º 24
0
 /**
  * @param array $iterable
  * @param array $to
  * @param object $type
  * @dataProvider sendDataProvider
  */
 public function testSendError($iterable, $to, $type)
 {
     $segment = new Segment();
     $entity = '\\stdClass';
     $marketingList = new MarketingList();
     $marketingList->setSegment($segment);
     $marketingList->setType($type);
     $marketingList->setEntity($entity);
     $campaign = new EmailCampaign();
     $campaign->setMarketingList($marketingList)->setSenderEmail(reset($to));
     $itCount = count($iterable);
     $this->marketingListProvider->expects($this->once())->method('getMarketingListEntitiesIterator')->will($this->returnValue($iterable));
     $manager = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($manager));
     $manager->expects($this->once())->method('persist')->with($campaign);
     $manager->expects($this->atLeastOnce())->method('flush');
     $manager->expects($this->exactly($itCount))->method('beginTransaction');
     $manager->expects($this->exactly($itCount))->method('rollback');
     $fields = ['email'];
     $this->assertFieldsCall($fields, $marketingList);
     if ($itCount) {
         $this->contactInformationFieldsProvider->expects($this->exactly($itCount))->method('getTypedFieldsValues')->with($this->equalTo($fields), $this->isType('object'))->will($this->returnValue($to));
         $this->statisticsConnector->expects($this->exactly($itCount))->method('getStatisticsRecord')->with($this->equalTo($campaign), $this->isInstanceOf('stdClass'))->willThrowException(new \Exception('Error'));
         $this->logger->expects($this->exactly($itCount))->method('error');
     }
     $this->transport->expects($this->exactly($itCount))->method('send');
     $this->transportProvider->expects($this->once())->method('getTransportByName')->will($this->returnValue($this->transport));
     $this->sender->setEmailCampaign($campaign);
     $this->sender->send($campaign);
 }