/**
  * @return ViewModel
  */
 public function indexAction()
 {
     $campaign = $this->campaignRepository->getOneBySecurityKey($this->params('securityKey'));
     if (!$campaign) {
         return $this->redirect()->toRoute(static::ERROR_ROUTE);
     }
     /** @var Request $request */
     $request = $this->getRequest();
     $subscriber = $this->subscriberRepository->getOneByEmailAddress($request->getPost('emailAddress'));
     if (!$subscriber) {
         $subscriber = $this->subscriberRepository->getNewEntity();
     }
     try {
         if ($this->manager->handlePost($subscriber, $campaign)) {
             if ($request->getPost('successUrl')) {
                 return $this->redirect()->toUrl($request->getPost('successUrl'));
             }
             return $this->redirect()->toRoute($this->baseRoute, array('securityKey' => $this->params('securityKey')));
         }
         if ($request->getPost('failureUrl')) {
             return $this->redirect()->toUrl($request->getPost('failureUrl'));
         }
     } catch (Manager\Exception\Db $exc) {
         $feedback = $this->userText->getMessage(EntityName::MESSAGE, Message::SAVE_FAILED);
         $this->currentMessages[FeedbackType::DANGER][] = $feedback;
     }
     $this->layout()->currentMessages = $this->currentMessages;
     return new ViewModel(array('form' => $this->manager->getForm(), 'campaignName' => $campaign->getName()));
 }
Beispiel #2
0
 /**
  * @return array
  */
 private function getPopulateData()
 {
     $formData = (array) $this->getForm()->getData();
     if ($formData[Entity::CAMPAIGNS]) {
         $formData[Entity::CAMPAIGNS] = $this->campaignRepository->getByIds($formData[Entity::CAMPAIGNS]);
     } else {
         $formData[Entity::CAMPAIGNS] = [];
     }
     return $formData;
 }
 /**
  * @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]);
 }
Beispiel #4
0
 /**
  * @covers DmMailer\Repository\Campaign
  */
 public function testAdminPageExecutesSearch()
 {
     $actualResult = $this->sut->getAdminPage(['c.entityId = 1']);
     $this->assertInstanceOf('Doctrine\\ORM\\Query', $actualResult);
     /** @var \DmMailer\Entity\Campaign $queryResult */
     $queryResult = $actualResult->getOneOrNullResult();
     $this->assertInstanceOf('DmMailer\\Entity\\Campaign', $queryResult);
     $this->assertEquals('Winter 2013', $queryResult->getName());
 }
Beispiel #5
0
 /**
  * @return array
  */
 private function getCampaignCount()
 {
     $count = $this->campaignRepo->getCampaignCount();
     $kpiType = self::INFO;
     if ($count < 1 || $count > 50) {
         $kpiType = self::DANGER;
     } elseif ($count > 10) {
         $kpiType = self::WARNING;
     }
     return [self::CAMPAIGN_COUNT => [self::VALUE => $count, self::TYPE => $kpiType]];
 }
Beispiel #6
0
 /**
  * @covers DmMailer\Repository\QueueItem
  */
 public function testQueueMessage()
 {
     $oldQueueSize = count($this->sut->findAll());
     $campaign = $this->campaignRepo->findOneBy(['entityId' => 1]);
     $message = $this->messageRepo->getNewEntity();
     $message->setSubject('Subject');
     $message->setBody('Body');
     $message->setCampaign($campaign);
     $this->sut->queueMessage($message);
     $newQueueSize = count($this->sut->findAll());
     $this->assertGreaterThan($oldQueueSize, $newQueueSize);
     $this->assertEquals($oldQueueSize + count($campaign->getSubscribers()), $newQueueSize);
 }
 /**
  * @return JsonModel
  */
 public function create($data = [])
 {
     $this->response->setStatusCode(400);
     $campaign = $this->campaignRepository->getOneBySecurityKey($this->getRequest()->getPost('securityKey'));
     if (!$campaign) {
         return $this->sendResult('Campaign not found.');
     }
     $subscriber = $this->subscriberRepository->getOneByEmailAddress($this->getRequest()->getPost('emailAddress'));
     if (!$subscriber) {
         $subscriber = $this->subscriberRepository->getNewEntity();
     }
     try {
         if ($this->manager->handlePost($subscriber, $campaign)) {
             $this->response->setStatusCode(201);
             return $this->sendResult(true);
         }
     } catch (\Exception $exc) {
         $this->exceptionLogger->log(0, $exc->getMessage());
         $this->response->setStatusCode(500);
         return $this->sendResult('Unexpected error while saving data');
     }
     return $this->sendResult($this->manager->getForm()->getMessages());
 }