/**
  * @return ViewModel|Response
  */
 public function updateAction()
 {
     $campaignId = $this->params('entityId');
     /** @var Campaign $campaign */
     $campaign = $this->campaignRepository->getOneById($campaignId);
     if (!$campaign) {
         return $this->redirect()->toRoute(static::BASE_ROUTE);
     }
     $message = $this->messageRepository->getSystemMessage($campaignId);
     if (!$message) {
         $message = $this->messageRepository->getNewEntity();
     }
     try {
         if ($this->manager->handlePost($campaign, $message)) {
             $msg = $this->userText->getMessage(EntityName::CAMPAIGN, Message::UPDATE_SUCCESS);
             $this->flashMessenger()->addSuccessMessage($msg);
             $this->addSystemMessageMessages();
             return $this->redirect()->toRoute(static::BASE_ROUTE);
         }
     } catch (Manager\Exception\Db $exc) {
         $campaignMsg = $this->userText->getMessage(EntityName::CAMPAIGN, Message::SAVE_FAILED);
         $messageMsg = $this->userText->getMessage(EntityName::MESSAGE, Message::SAVE_FAILED);
         $this->currentMessages[FeedbackType::DANGER][] = $campaignMsg;
         $this->currentMessages[FeedbackType::DANGER][] = $messageMsg;
     }
     $this->layout()->currentMessages = $this->currentMessages;
     return new ViewModel(['form' => $this->manager->getForm(), 'tinyMceLang' => $this->tinyMceLang]);
 }
示例#2
0
 /**
  * @param ServiceLocatorInterface $serviceLocator
  *
  * @return CampaignManager
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var EntityManager $entityManager */
     $entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
     /** @var PhpRequest $request */
     $request = $serviceLocator->get('request');
     /** @var CampaignRepository $mainRepository */
     $mainRepository = $serviceLocator->get('DmMailer\\Repository\\Campaign');
     /** @var CampaignForm $form */
     $form = $serviceLocator->get('DmMailer\\Form\\CampaignForm');
     /** @var Paginator $paginatorFactory */
     $paginatorFactory = $serviceLocator->get('DmMailer\\Service\\Factory\\Paginator');
     $manager = new CampaignManager($entityManager, $request, $mainRepository, $form, $paginatorFactory);
     /** @var TemplateRepository $templateRepository */
     $templateRepository = $serviceLocator->get('DmMailer\\Repository\\Template');
     $manager->setTemplateRepository($templateRepository);
     return $manager;
 }
示例#3
0
 /**
  * @TODO   Remove when Handle system message is moved to an event
  *
  * @covers DmMailer\Manager\Campaign
  */
 public function testHandleSystemMessageSkipsMessageOperation()
 {
     $this->formMock->expects($this->any())->method('isValid')->willReturn(true);
     $this->formMock->expects($this->any())->method('get')->willReturn($this->getInputMock());
     $this->requestMock->expects($this->any())->method('isPost')->willReturn(true);
     $this->requestMock->expects($this->any())->method('getPost')->willReturn([]);
     // Actual test
     $this->messageMock->expects($this->any())->method('getBody')->willReturn('');
     $this->messageMock->expects($this->any())->method('getSubject')->willReturn('');
     $this->messageMock->expects($this->any())->method('getId')->willReturn(0);
     // End of actual test
     $actualResult = $this->sut->handlePost($this->campaignMock, $this->messageMock);
     $this->assertTrue($actualResult);
     $this->assertEquals(Campaign::SYSTEM_MESSAGE_SKIPPED, $this->sut->getSystemMessageOp());
 }