示例#1
0
 /**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $adminUser = $this->getReference('admin-user');
     $list = new LeadList();
     $list->setName('United States');
     $list->setAlias('us');
     $list->setCreatedBy($adminUser);
     $list->setIsGlobal(true);
     $list->setFilters([['glue' => 'and', 'type' => 'lookup', 'field' => 'country', 'operator' => '=', 'filter' => 'United States', 'display' => '']]);
     $this->setReference('lead-list', $list);
     $manager->persist($list);
     $manager->flush();
     $this->container->get('mautic.factory')->getModel('lead.list')->rebuildListLeads($list);
 }
示例#2
0
 /**
  * Add lead to lists
  *
  * @param array|Lead        $lead
  * @param array|LeadList    $lists
  * @param bool              $manuallyAdded
  * @param bool              $batchProcess
  * @param int               $searchListLead 0 = reference, 1 = yes, -1 = known to not exist
  * @param \DateTime         $dateManipulated
  *
  * @throws \Doctrine\ORM\ORMException
  */
 public function addLead($lead, $lists, $manuallyAdded = false, $batchProcess = false, $searchListLead = 1, $dateManipulated = null)
 {
     if ($dateManipulated == null) {
         $dateManipulated = new \DateTime();
     }
     if (!$lead instanceof Lead) {
         $leadId = is_array($lead) && isset($lead['id']) ? $lead['id'] : $lead;
         $lead = $this->em->getReference('MauticLeadBundle:Lead', $leadId);
     } else {
         $leadId = $lead->getId();
     }
     if (!$lists instanceof LeadList) {
         //make sure they are ints
         $searchForLists = array();
         foreach ($lists as $k => &$l) {
             $l = (int) $l;
             if (!isset($this->leadChangeLists[$l])) {
                 $searchForLists[] = $l;
             }
         }
         if (!empty($searchForLists)) {
             $listEntities = $this->getEntities(array('filter' => array('force' => array(array('column' => 'l.id', 'expr' => 'in', 'value' => $searchForLists)))));
             foreach ($listEntities as $list) {
                 $this->leadChangeLists[$list->getId()] = $list;
             }
         }
         unset($listEntities, $searchForLists);
     } else {
         $this->leadChangeLists[$lists->getId()] = $lists;
         $lists = array($lists->getId());
     }
     if (!is_array($lists)) {
         $lists = array($lists);
     }
     $persistLists = array();
     $dispatchEvents = array();
     foreach ($lists as $listId) {
         if (!isset($this->leadChangeLists[$listId])) {
             // List no longer exists in the DB so continue to the next
             continue;
         }
         if ($searchListLead == -1) {
             $listLead = null;
         } elseif ($searchListLead) {
             $listLead = $this->getListLeadRepository()->findOneBy(array('lead' => $lead, 'list' => $this->leadChangeLists[$listId]));
         } else {
             $listLead = $this->em->getReference('MauticLeadBundle:ListLead', array('lead' => $leadId, 'list' => $listId));
         }
         if ($listLead != null) {
             if ($manuallyAdded && $listLead->wasManuallyRemoved()) {
                 $listLead->setManuallyRemoved(false);
                 $listLead->setManuallyAdded($manuallyAdded);
                 $persistLists[] = $listLead;
                 $dispatchEvents[] = $listId;
             } else {
                 // Detach from Doctrine
                 $this->em->detach($listLead);
                 continue;
             }
         } else {
             $listLead = new ListLead();
             $listLead->setList($this->leadChangeLists[$listId]);
             $listLead->setLead($lead);
             $listLead->setManuallyAdded($manuallyAdded);
             $listLead->setDateAdded($dateManipulated);
             $persistLists[] = $listLead;
             $dispatchEvents[] = $listId;
         }
     }
     if (!empty($persistLists)) {
         $this->getRepository()->saveEntities($persistLists);
     }
     // Clear ListLead entities from Doctrine memory
     $this->em->clear('Mautic\\LeadBundle\\Entity\\ListLead');
     if ($batchProcess) {
         // Detach for batch processing to preserve memory
         $this->em->detach($lead);
     } elseif (!empty($dispatchEvents) && $this->dispatcher->hasListeners(LeadEvents::LEAD_LIST_CHANGE)) {
         foreach ($dispatchEvents as $listId) {
             $event = new ListChangeEvent($lead, $this->leadChangeLists[$listId]);
             $this->dispatcher->dispatch(LeadEvents::LEAD_LIST_CHANGE, $event);
             unset($event);
         }
     }
     unset($lead, $persistLists, $lists);
 }
示例#3
0
 /**
  * Remove list.
  *
  * @param LeadList $list
  */
 public function removeList(LeadList $list)
 {
     $this->changes['lists']['removed'][$list->getId()] = $list->getName();
     $this->lists->removeElement($list);
 }
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array());
     return parent::__toString();
 }