/** * Remove list. * * @param LeadList $list */ public function removeList(LeadList $list) { $this->changes['lists']['removed'][$list->getId()] = $list->getName(); $this->lists->removeElement($list); }
/** * 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); }
/** * {@inheritDoc} */ public function getId() { if ($this->__isInitialized__ === false) { return (int) parent::getId(); } $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array()); return parent::getId(); }