Ejemplo n.º 1
0
 /**
  * Handle
  *
  * @param Subscription $subscription
  */
 public function handle(Subscription $subscription)
 {
     // Init variables
     $mergeFields = array();
     $interests = array();
     try {
         // We must overwrite existing interests
         if ($this->modulesSettings->get('Mailmotor', 'overwrite_interests', true)) {
             $possibleInterests = $this->subscriber->getInterests();
             // Loop interests
             foreach ($possibleInterests as $categoryId => $categoryInterest) {
                 foreach ($categoryInterest['children'] as $categoryChildId => $categoryChildTitle) {
                     // Add interest
                     $interests[$categoryChildId] = in_array($categoryChildId, $subscription->interests);
                 }
             }
         } elseif (!empty($subscription->interests)) {
             // Loop checked interests
             foreach ($subscription->interests as $checkedInterestId) {
                 // Add interest
                 $interests[$checkedInterestId] = true;
             }
         }
         // Fallback for when no mail-engine is chosen in the Backend
     } catch (NotImplementedException $e) {
     }
     // Subscribing the user, will dispatch an event
     $this->subscriber->subscribe($subscription->email, $subscription->language, $mergeFields, $interests);
 }
 /**
  * On FormBuilderSubmittedEvent
  *
  * @param FormBuilderSubmittedEvent $event
  */
 public function onFormBuilderSubmittedEvent(FormBuilderSubmittedEvent $event)
 {
     if ($this->modulesSettings->get('Mailmotor', 'automatically_subscribe_from_form_builder_submitted_form', false)) {
         $form = $event->getForm();
         $data = $event->getData();
         $email = null;
         // Check if we have a replyTo email set
         foreach ($form['fields'] as $field) {
             if (array_key_exists('reply_to', $field['settings']) && $field['settings']['reply_to'] === true) {
                 $email = unserialize($data[$field['id']]['value']);
             }
         }
         // Define language
         $language = array_key_exists('language', $form) ? $form['language'] : $this->modulesSettings->get('Core', 'default_language', 'en');
         // We subscribe the replyTo email
         try {
             // Does email exists or not in our mailing list
             $exists = (bool) $this->subscriber->exists($email);
             // We only need to subscribe when not exists
             if (!$exists) {
                 $this->subscriber->subscribe($email, $language, array(), array(), false);
             }
         } catch (NotImplementedException $e) {
             // We do nothing as fallback when no mail-engine is chosen in the Backend
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param mixed $value
  * @param Constraint $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     try {
         // The email is already in our mailing list
         if ($this->subscriber->isSubscribed($value)) {
             $this->context->buildViolation($constraint->alreadySubscribedMessage)->addViolation();
         }
         // fallback for when no mail-engine is chosen in the Backend
     } catch (NotImplementedException $e) {
         // do nothing
     }
 }
Ejemplo n.º 4
0
 /**
  * @return array
  */
 public function getInterests()
 {
     $interests = array();
     try {
         $mailMotorInterests = $this->subscriber->getInterests();
         // Has interests
         if (!empty($mailMotorInterests)) {
             // Loop interests
             foreach ($mailMotorInterests as $categoryId => $categoryInterest) {
                 foreach ($categoryInterest['children'] as $categoryChildId => $categoryChildTitle) {
                     // Add interest value for checkbox
                     $interests[$categoryChildId] = $categoryChildTitle;
                 }
             }
         }
         // Fallback for when no mail-engine is chosen in the Backend
     } catch (NotImplementedException $e) {
     }
     return $interests;
 }
Ejemplo n.º 5
0
 /**
  * Handle
  *
  * @param Unsubscription $unsubscription
  */
 public function handle(Unsubscription $unsubscription)
 {
     // Unsubscribing the user, will dispatch an event
     $this->subscriber->unsubscribe($unsubscription->email);
 }