Ejemplo n.º 1
0
 /**
  * @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()));
 }
Ejemplo n.º 2
0
 /**
  * @param int $inputCount
  *
  * @return SubscriberEntity|null
  */
 private function getSubscriber($inputCount)
 {
     $subscriberId = $this->request->getPost('testMail' . $inputCount);
     if (!is_numeric($subscriberId)) {
         return null;
     }
     return $this->subscriberRepository->getOneById($subscriberId);
 }
 /**
  * @return ViewModel
  */
 public function updateAction()
 {
     /** @var Subscriber $entity */
     $entity = $this->subscriberRepository->getOneById($this->params('entityId'));
     if (!$entity) {
         return $this->redirect()->toRoute(static::BASE_ROUTE);
     }
     try {
         if ($this->manager->handlePost($entity)) {
             $msg = $this->userText->getMessage(EntityName::SUBSCRIBER, Message::UPDATE_SUCCESS);
             $this->flashMessenger()->addSuccessMessage($msg);
             return $this->redirect()->toRoute(static::BASE_ROUTE);
         }
     } catch (\Exception $ex) {
         $msg = $this->userText->getMessage(EntityName::SUBSCRIBER, Message::SAVE_FAILED);
         $this->currentMessages[FeedbackType::DANGER][] = $msg;
     }
     $this->layout()->currentMessages = $this->currentMessages;
     return new ViewModel(['form' => $this->manager->getForm()]);
 }
Ejemplo n.º 4
0
 /**
  * @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());
 }
Ejemplo n.º 5
0
 /**
  * @covers DmMailer\Repository\Subscriber
  */
 public function testGetOneByEmailAddress()
 {
     $actualResult = $this->sut->getOneByEmailAddress('*****@*****.**');
     $this->assertInstanceOf('DmMailer\\Entity\\Subscriber', $actualResult);
     $this->assertEquals('Alice Foo', $actualResult->getFullName());
 }