/**
  * @param Action        $action
  * @param MauticFactory $factory
  *
  * @return array
  */
 public static function onFormSubmit(Action $action, MauticFactory $factory)
 {
     $properties = $action->getProperties();
     $assetId = $properties['asset'];
     /** @var \Mautic\AssetBundle\Model\AssetModel $model */
     $model = $factory->getModel('asset');
     $asset = $model->getEntity($assetId);
     $form = $action->getForm();
     //make sure the asset still exists and is published
     if ($asset != null && $asset->isPublished()) {
         //register a callback after the other actions have been fired
         return array('callback' => '\\Mautic\\AssetBundle\\Helper\\FormSubmitHelper::downloadFile', 'form' => $form, 'asset' => $asset, 'message' => isset($properties['message']) ? $properties['message'] : '');
     }
 }
Esempio n. 2
0
 /**
  * @param       $action
  *
  * @return array
  */
 public static function sendEmail($tokens, Action $action, MauticFactory $factory, $feedback)
 {
     $properties = $action->getProperties();
     $emailId = isset($properties['useremail']) ? (int) $properties['useremail']['email'] : (int) $properties['email'];
     $form = $action->getForm();
     /** @var \Mautic\EmailBundle\Model\EmailModel $emailModel */
     $emailModel = $factory->getModel('email');
     $email = $emailModel->getEntity($emailId);
     /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */
     $leadModel = $factory->getModel('lead');
     //make sure the email still exists and is published
     if ($email != null && $email->isPublished()) {
         // Deal with Lead email
         if (!empty($feedback['lead.create']['lead'])) {
             //the lead was just created via the lead.create action
             $currentLead = $feedback['lead.create']['lead'];
         } else {
             $currentLead = $leadModel->getCurrentLead();
         }
         if ($currentLead instanceof Lead) {
             //flatten the lead
             $lead = $currentLead;
             $currentLead = array('id' => $lead->getId());
             $leadFields = $leadModel->flattenFields($lead->getFields());
             $currentLead = array_merge($currentLead, $leadFields);
         }
         if (isset($properties['user_id']) && $properties['user_id']) {
             // User email
             $emailModel->sendEmailToUser($email, $properties['user_id'], $currentLead, $tokens);
         } elseif (isset($currentLead)) {
             if (isset($leadFields['email'])) {
                 $options = array('source' => array('form', $form->getId()), 'tokens' => $tokens, 'ignoreDNC' => true);
                 $emailModel->sendEmail($email, $currentLead, $options);
             }
         }
     }
 }
 /**
  * @param Action        $action
  * @param MauticFactory $factory
  *
  * @return array
  */
 public static function onFormSubmit($tokens, Action $action, MauticFactory $factory, $feedback)
 {
     $properties = $action->getProperties();
     $leadModel = $factory->getModel('lead');
     $emailRepo = $factory->getModel('email');
     // Deal with Lead email
     if (!empty($feedback['lead.create']['lead'])) {
         //the lead was just created via the lead.create action
         $currentLead = $feedback['lead.create']['lead'];
     } else {
         $currentLead = $leadModel->getCurrentLead();
     }
     if ($currentLead instanceof Lead) {
         //flatten the lead
         $lead = $currentLead;
         $currentLead = array('id' => $lead->getId());
         $leadFields = $leadModel->flattenFields($lead->getFields());
         $currentLead = array_merge($currentLead, $leadFields);
     }
     $email_address = $currentLead->getEmail();
     if ($email_address) {
         $emailRepo->removeDoNotContact($email_address);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getProperties()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getProperties', array());
     return parent::getProperties();
 }