예제 #1
0
 /**
  * @param Subscription $subscription
  * @param string       $status
  *
  * @return $this
  */
 public function updateStatus(Subscription $subscription, $status)
 {
     $subscription->setStatus($status);
     $this->em->persist($subscription);
     $this->em->flush($subscription);
     return $this;
 }
예제 #2
0
 /**
  * @param Subscription $subscription
  */
 public function save(Subscription $subscription)
 {
     if (!$subscription->getId()) {
         $this->em->persist($subscription);
     }
     $this->em->flush($subscription);
 }
예제 #3
0
 /**
  * Synchronize a subscription
  *
  * @param Subscription $subscription
  * @return bool
  */
 public function synchronise(Subscription $subscription)
 {
     try {
         $contact = ['update' => true, 'purge' => false, 'contact' => ['externalId' => $subscription->getId(), 'properties' => ['email' => $subscription->getEmail()]]];
         $response = $this->post('contact', $contact);
         if ($response->getStatusCode() == '204') {
             //Contact added successfully status code
             $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_SYNCED);
             return true;
         } else {
             $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_FAILED);
             return false;
         }
     } catch (\Exception $e) {
         $this->subscriptionManager->updateStatus($subscription, Subscription::STATUS_FAILED);
         return true;
     }
 }
예제 #4
0
 /**
  * This method is called right after the post is stored in the database during the Form submit.
  *
  * @param FormSubmitEvent $event
  */
 public function postFormSubmit(FormSubmitEvent $event)
 {
     $post = $event->getPost();
     $mailinglists = $email = null;
     foreach ($post->getValueSet()->getValues() as $value) {
         if ($value instanceof MailingListSubscribeValue && $value->getValue() == true) {
             $parameters = $value->getAttribute()->getParameters();
             if (isset($parameters['mailingLists'])) {
                 $mailinglists = $this->mailingListManager->getRepository()->findByIds($parameters['mailingLists']);
             }
         } elseif ($value instanceof EmailValue) {
             $email = $value->getValue();
         }
     }
     if ($email && $mailinglists) {
         foreach ($mailinglists as $mailinglist) {
             $subscription = new Subscription();
             $subscription->setEmail($email);
             $subscription->setMailingList($mailinglist);
             $this->subscriptionManager->save($subscription);
         }
     }
 }
 /**
  * @param BlockInterface $block
  */
 public function load(BlockInterface $block)
 {
     $this->form = $this->formFactory->create(SubscribeType::class, $this->subscription);
     $this->form->handleRequest($this->request);
     if ($this->form->isValid()) {
         foreach ($this->getMailingLists($block) as $mailingList) {
             $this->subscription->setMailingList($mailingList);
             $this->em->persist($this->subscription);
             $this->em->flush($this->subscription);
             // Reset to add to another mailing list
             $this->em->detach($this->subscription);
             $this->subscription = clone $this->subscription;
             $this->subscription->setId(null);
         }
         $this->subscribed = true;
     }
 }
예제 #6
0
 /**
  * @param BlockInterface $block
  */
 public function load(BlockInterface $block)
 {
     $properties = $block->getProperties();
     $opts = array();
     if (isset($properties['responseType']) && $properties['responseType'] == 'redirect') {
         $opts['action'] = $this->router->generate('opifer_mailing_list_subscribe_block', ['id' => $block->getId()]);
     }
     $this->form = $this->formFactory->create(SubscribeType::class, $this->subscription, $opts);
     $this->form->handleRequest($this->request);
     if ($this->form->isValid()) {
         foreach ($this->getMailingLists($block) as $list) {
             $subscription = $this->subscriptionManager->findOrCreate($list, $this->subscription->getEmail());
             $this->subscriptionManager->save($subscription);
         }
         $this->subscribed = true;
     }
 }