/** * @param $event * @param Lead $lead * * @return bool */ public static function validatePointChange($event, Lead $lead) { $properties = $event['properties']; $checkPoints = $properties['points']; if (!empty($checkPoints)) { $points = $lead->getPoints(); if ($points < $checkPoints) { return false; } } return true; }
/** * Trigger events for the current lead * * @param Lead $lead */ public function triggerEvents(Lead $lead) { $points = $lead->getPoints(); //find all published triggers that is applicable to this points /** @var \Mautic\PointBundle\Entity\TriggerEventRepository $repo */ $repo = $this->getEventRepository(); $events = $repo->getPublishedByPointTotal($points); if (!empty($events)) { //get a list of actions that has already been applied to this lead $appliedEvents = $repo->getLeadTriggeredEvents($lead->getId()); $ipAddress = $this->factory->getIpAddress(); $persist = array(); foreach ($events as $event) { if (isset($appliedEvents[$event['id']])) { //don't apply the event to the lead if it's already been done continue; } if ($this->triggerEvent($event, $lead, true)) { $log = new LeadTriggerLog(); $log->setIpAddress($ipAddress); $log->setEvent($this->em->getReference('MauticPointBundle:TriggerEvent', $event['id'])); $log->setLead($lead); $log->setDateFired(new \DateTime()); $persist[] = $log; } } if (!empty($persist)) { $this->getEventRepository()->saveEntities($persist); $this->em->clear('Mautic\\PointBundle\\Entity\\LeadTriggerLog'); $this->em->clear('Mautic\\PointBundle\\Entity\\TriggerEvent'); } } }
/** * {@inheritDoc} */ public function getPoints() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getPoints', array()); return parent::getPoints(); }