Ejemplo n.º 1
0
 public function unsubscribe($number)
 {
     $number = $this->phoneNumberHelper->format($number, PhoneNumberFormat::E164);
     /** @var \Mautic\LeadBundle\Entity\LeadRepository $repo */
     $repo = $this->em->getRepository('MauticLeadBundle:Lead');
     $args = ['filter' => ['force' => [['column' => 'mobile', 'expr' => 'eq', 'value' => $number]]]];
     $leads = $repo->getEntities($args);
     if (!empty($leads)) {
         $lead = array_shift($leads);
     } else {
         // Try to find the lead based on the given phone number
         $args['filter']['force'][0]['column'] = 'phone';
         $leads = $repo->getEntities($args);
         if (!empty($leads)) {
             $lead = array_shift($leads);
         } else {
             return false;
         }
     }
     return $this->leadModel->addDncForLead($lead, 'sms', null, DoNotContact::UNSUBSCRIBED);
 }
Ejemplo n.º 2
0
 /**
  * @param        $email
  * @param int    $reason
  * @param string $comments
  * @param bool   $flush
  * @param null   $leadId
  *
  * @return array
  */
 public function setEmailDoNotContact($email, $reason = DoNotContact::BOUNCED, $comments = '', $flush = true, $leadId = null)
 {
     /** @var \Mautic\LeadBundle\Entity\LeadRepository $leadRepo */
     $leadRepo = $this->em->getRepository('MauticLeadBundle:Lead');
     if (null === $leadId) {
         $leadId = (array) $leadRepo->getLeadByEmail($email, true);
     } elseif (!is_array($leadId)) {
         $leadId = [$leadId];
     }
     $dnc = [];
     foreach ($leadId as $lead) {
         $dnc[] = $this->leadModel->addDncForLead($this->em->getReference('MauticLeadBundle:Lead', $lead), 'email', $comments, $reason, $flush);
     }
     return $dnc;
 }