Exemplo n.º 1
0
 public function unsubscribe($number)
 {
     $phoneUtil = PhoneNumberUtil::getInstance();
     $phoneNumber = $phoneUtil->parse($number, 'US');
     $number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
     /** @var \Mautic\LeadBundle\Entity\LeadRepository $repo */
     $repo = $this->factory->getEntityManager()->getRepository('MauticLeadBundle:Lead');
     $args = array('filter' => array('force' => array(array('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;
         }
     }
     /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */
     $leadModel = $this->factory->getModel('lead.lead');
     return $leadModel->addDncForLead($lead, 'sms', null, DoNotContact::UNSUBSCRIBED);
 }
Exemplo n.º 2
0
 /**
  * @param string $email
  *
  * @return bool
  */
 public function unsubscribe($email)
 {
     /** @var \Mautic\LeadBundle\Entity\LeadRepository $repo */
     $repo = $this->factory->getEntityManager()->getRepository('MauticLeadBundle:Lead');
     $lead = $repo->getLeadByEmail($email);
     /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */
     $leadModel = $this->factory->getModel('lead.lead');
     return $leadModel->addDncForLead($lead, 'notification', null, DoNotContact::UNSUBSCRIBED);
 }
Exemplo n.º 3
0
 /**
  * Extacts the auth keys from response and saves entity
  *
  * @param $data
  *
  * @return bool|string false if no error; otherwise the error string
  */
 public function extractAuthKeys($data, $tokenOverride = null)
 {
     //check to see if an entity exists
     $entity = $this->getIntegrationSettings();
     if ($entity == null) {
         $entity = new Integration();
         $entity->setName($this->getName());
     }
     // Prepare the keys for extraction such as renaming, setting expiry, etc
     $data = $this->prepareResponseForExtraction($data);
     //parse the response
     $authTokenKey = $tokenOverride ? $tokenOverride : $this->getAuthTokenKey();
     if (is_array($data) && isset($data[$authTokenKey])) {
         $keys = $this->mergeApiKeys($data, null, true);
         $encrypted = $this->encryptApiKeys($keys);
         $entity->setApiKeys($encrypted);
         $error = false;
     } else {
         $error = $this->getErrorsFromResponse($data);
         if (empty($error)) {
             $error = $this->factory->getTranslator()->trans("mautic.integration.error.genericerror", array(), "flashes");
         }
     }
     //save the data
     $em = $this->factory->getEntityManager();
     $em->persist($entity);
     $em->flush();
     $this->setIntegrationSettings($entity);
     return $error;
 }
Exemplo n.º 4
0
 /**
  * @param MauticFactory $factory
  * @param               $lead
  * @param               $event
  *
  * @throws \Doctrine\ORM\ORMException
  */
 public static function addRemoveLead(MauticFactory $factory, $lead, $event)
 {
     /** @var \Mautic\CampaignBundle\Model\CampaignModel $campaignModel */
     $campaignModel = $factory->getModel('campaign');
     $properties = $event['properties'];
     $addToCampaigns = $properties['addTo'];
     $removeFromCampaigns = $properties['removeFrom'];
     $em = $factory->getEntityManager();
     $leadsModified = false;
     if (!empty($addToCampaigns)) {
         foreach ($addToCampaigns as $c) {
             $campaignModel->addLead($em->getReference('MauticCampaignBundle:Campaign', $c), $lead, true);
         }
         $leadsModified = true;
     }
     if (!empty($removeFromCampaigns)) {
         foreach ($removeFromCampaigns as $c) {
             if ($c == 'this') {
                 $c = $event['campaign']['id'];
             }
             $campaignModel->removeLead($em->getReference('MauticCampaignBundle:Campaign', $c), $lead, true);
         }
         $leadsModified = true;
     }
     return $leadsModified;
 }
Exemplo n.º 5
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->em = $factory->getEntityManager();
     $this->translator = $factory->getTranslator();
     $this->model = $factory->getModel('category');
     $this->router = $factory->getRouter();
 }
Exemplo n.º 6
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->translator = $factory->getTranslator();
     $this->defaultTheme = $factory->getParameter('theme');
     $this->em = $factory->getEntityManager();
     $this->request = $factory->getRequest();
 }
Exemplo n.º 7
0
 /**
  * Determines the winner of A/B test based on dwell time rates
  *
  * @param MauticFactory $factory
  * @param Page          $parent
  * @param               $children
  *
  * @return array
  */
 public static function determineDwellTimeTestWinner($factory, $parent, $children)
 {
     //find the hits that did not go any further
     $repo = $factory->getEntityManager()->getRepository('MauticPageBundle:Hit');
     $pageIds = array($parent->getId());
     foreach ($children as $c) {
         $pageIds[] = $c->getId();
     }
     $startDate = $parent->getVariantStartDate();
     if ($startDate != null && !empty($pageIds)) {
         //get their bounce rates
         $counts = $repo->getDwellTimes(array('pageIds' => $pageIds, 'startDate' => $startDate));
         $translator = $factory->getTranslator();
         $support = array();
         if ($counts) {
             //in order to get a fair grade, we have to compare the averages here since a page that is only shown
             //25% of the time will have a significantly lower sum than a page shown 75% of the time
             $avgs = array();
             $support['data'] = array();
             $support['labels'] = array();
             foreach ($counts as $pid => $stats) {
                 $avgs[$pid] = $stats['average'];
                 $support['data'][$translator->trans('mautic.page.abtest.label.dewlltime.average')][] = $stats['average'];
                 $support['labels'][] = $pid . ':' . $stats['title'];
             }
             //set max for scales
             $max = max($avgs);
             $support['step_width'] = ceil($max / 10) * 10;
             //get the page ids with the greatest average dwell time
             $winners = $max > 0 ? array_keys($avgs, $max) : array();
             return array('winners' => $winners, 'support' => $support, 'basedOn' => 'page.dwelltime', 'supportTemplate' => 'MauticPageBundle:SubscribedEvents\\AbTest:bargraph.html.php');
         }
     }
     return array('winners' => array(), 'support' => array(), 'basedOn' => 'page.dwelltime');
 }
Exemplo n.º 8
0
 /**
  * Create an email stat.
  *
  * @param bool|true   $persist
  * @param string|null $emailAddress
  * @param null        $listId
  *
  * @return Stat|void
  *
  * @throws \Doctrine\ORM\ORMException
  */
 public function createEmailStat($persist = true, $emailAddress = null, $listId = null)
 {
     static $copies = [];
     //create a stat
     $stat = new Stat();
     $stat->setDateSent(new \DateTime());
     $stat->setEmail($this->email);
     // Note if a lead
     if (null !== $this->lead) {
         $stat->setLead($this->factory->getEntityManager()->getReference('MauticLeadBundle:Lead', $this->lead['id']));
         $emailAddress = $this->lead['email'];
     }
     // Find email if applicable
     if (null === $emailAddress) {
         // Use the last address set
         $emailAddresses = $this->message->getTo();
         if (count($emailAddresses)) {
             end($emailAddresses);
             $emailAddress = key($emailAddresses);
         }
     }
     $stat->setEmailAddress($emailAddress);
     // Note if sent from a lead list
     if (null !== $listId) {
         $stat->setList($this->factory->getEntityManager()->getReference('MauticLeadBundle:LeadList', $listId));
     }
     $stat->setTrackingHash($this->idHash);
     if (!empty($this->source)) {
         $stat->setSource($this->source[0]);
         $stat->setSourceId($this->source[1]);
     }
     $stat->setTokens($this->getTokens());
     /** @var \Mautic\EmailBundle\Model\EmailModel $emailModel */
     $emailModel = $this->factory->getModel('email');
     // Save a copy of the email - use email ID if available simply to prevent from having to rehash over and over
     $id = null !== $this->email ? $this->email->getId() : md5($this->subject . $this->body['content']);
     if (!isset($copies[$id])) {
         $hash = strlen($id) !== 32 ? md5($this->subject . $this->body['content']) : $id;
         $copy = $emailModel->getCopyRepository()->findByHash($hash);
         $copyCreated = false;
         if (null === $copy) {
             if (!$emailModel->getCopyRepository()->saveCopy($hash, $this->subject, $this->body['content'])) {
                 // Try one more time to find the ID in case there was overlap when creating
                 $copy = $emailModel->getCopyRepository()->findByHash($hash);
             } else {
                 $copyCreated = true;
             }
         }
         if ($copy || $copyCreated) {
             $copies[$id] = $hash;
         }
     }
     if (isset($copies[$id])) {
         $stat->setStoredCopy($this->factory->getEntityManager()->getReference('MauticEmailBundle:Copy', $copies[$id]));
     }
     if ($persist) {
         $emailModel->getStatRepository()->saveEntity($stat);
     }
     return $stat;
 }
Exemplo n.º 9
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->translator = $factory->getTranslator();
     $this->em = $factory->getEntityManager();
     $this->model = $factory->getModel('page');
     $this->canViewOther = $factory->getSecurity()->isGranted('page:pages:viewother');
     $this->user = $factory->getUser();
 }
Exemplo n.º 10
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->em = $factory->getEntityManager();
     $this->security = $factory->getSecurity();
     $this->dispatcher = $factory->getDispatcher();
     $this->translator = $factory->getTranslator();
     $this->factory = $factory;
 }
Exemplo n.º 11
0
 /**
  * Create or update existing Mautic lead from the integration's profile data
  *
  * @param mixed       $data    Profile data from integration
  * @param bool|true   $persist Set to false to not persist lead to the database in this method
  * @param array|null  $socialCache
  * @param mixed||null $identifiers
  * @return Lead
  */
 public function getMauticLead($data, $persist = true, $socialCache = null, $identifiers = null)
 {
     if (is_object($data)) {
         // Convert to array in all levels
         $data = json_encode(json_decode($data), true);
     } elseif (is_string($data)) {
         // Assume JSON
         $data = json_decode($data, true);
     }
     // Match that data with mapped lead fields
     $matchedFields = $this->populateMauticLeadData($data);
     if (empty($matchedFields)) {
         return;
     }
     // Find unique identifier fields used by the integration
     /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */
     $leadModel = $this->factory->getModel('lead');
     $uniqueLeadFields = $this->factory->getModel('lead.field')->getUniqueIdentiferFields();
     $uniqueLeadFieldData = array();
     foreach ($matchedFields as $leadField => $value) {
         if (array_key_exists($leadField, $uniqueLeadFields) && !empty($value)) {
             $uniqueLeadFieldData[$leadField] = $value;
         }
     }
     // Default to new lead
     $lead = new Lead();
     $lead->setNewlyCreated(true);
     if (count($uniqueLeadFieldData)) {
         $existingLeads = $this->factory->getEntityManager()->getRepository('MauticLeadBundle:Lead')->getLeadsByUniqueFields($uniqueLeadFieldData);
         if (!empty($existingLeads)) {
             $lead = array_shift($existingLeads);
             // Update remaining leads
             if (count($existingLeads)) {
                 foreach ($existingLeads as $existingLead) {
                     $existingLead->setLastActive(new \DateTime());
                 }
             }
         }
     }
     $leadModel->setFieldValues($lead, $matchedFields, false, false);
     // Update the social cache
     $leadSocialCache = $lead->getSocialCache();
     if (!isset($leadSocialCache[$this->getName()])) {
         $leadSocialCache[$this->getName()] = array();
     }
     $leadSocialCache[$this->getName()] = array_merge($leadSocialCache[$this->getName()], $socialCache);
     // Check for activity while here
     if (null !== $identifiers && in_array('public_activity', $this->getSupportedFeatures())) {
         $this->getPublicActivity($identifiers, $leadSocialCache[$this->getName()]);
     }
     $lead->setSocialCache($leadSocialCache);
     $lead->setLastActive(new \DateTime());
     if ($persist) {
         // Only persist if instructed to do so as it could be that calling code needs to manipulate the lead prior to executing event listeners
         $leadModel->saveEntity($lead, false);
     }
     return $lead;
 }
Exemplo n.º 12
0
 /**
  * @param      $lead
  * @param bool $integration
  *
  * @return array
  */
 public function clearIntegrationCache($lead, $integration = false)
 {
     $socialCache = $lead->getSocialCache();
     if (!empty($integration)) {
         unset($socialCache[$integration]);
     } else {
         $socialCache = array();
     }
     $lead->setSocialCache($socialCache);
     $this->factory->getEntityManager()->getRepository('MauticLeadBundle:Lead')->saveEntity($lead);
     return $socialCache;
 }
Exemplo n.º 13
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->factory = $factory;
     $this->templating = $factory->getTemplating();
     $this->request = $factory->getRequest();
     $this->security = $factory->getSecurity();
     $this->serializer = $factory->getSerializer();
     $this->params = $factory->getSystemParameters();
     $this->dispatcher = $factory->getDispatcher();
     $this->translator = $factory->getTranslator();
     $this->em = $factory->getEntityManager();
     $this->router = $factory->getRouter();
     $this->init();
 }
Exemplo n.º 14
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->translator = $factory->getTranslator();
     $this->defaultTheme = $factory->getParameter('theme');
     $this->em = $factory->getEntityManager();
     $this->request = $factory->getRequest();
     $this->countryChoices = FormFieldHelper::getCountryChoices();
     $this->regionChoices = FormFieldHelper::getRegionChoices();
     $this->timezoneChoices = FormFieldHelper::getTimezonesChoices();
     $this->localeChoices = FormFieldHelper::getLocaleChoices();
     $stages = $factory->getModel('stage')->getRepository()->getSimpleList();
     foreach ($stages as $stage) {
         $this->stageChoices[$stage['value']] = $stage['label'];
     }
 }
Exemplo n.º 15
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->translator = $factory->getTranslator();
     $this->em = $factory->getEntityManager();
     $this->model = $factory->getModel('user');
     // Get the list of available languages
     /** @var \Mautic\CoreBundle\Helper\LanguageHelper $languageHelper */
     $languageHelper = $factory->getHelper('language');
     $languages = $languageHelper->fetchLanguages(false, false);
     $langChoices = array();
     foreach ($languages as $code => $langData) {
         $langChoices[$code] = $langData['name'];
     }
     $langChoices = array_merge($langChoices, $factory->getParameter('supported_languages'));
     // Alpha sort the languages by name
     asort($langChoices);
     $this->supportedLanguages = $langChoices;
 }
Exemplo n.º 16
0
 /**
  * Create an email stat
  */
 public function createLeadEmailStat()
 {
     if (!$this->lead) {
         return;
     }
     //create a stat
     $stat = new Stat();
     $stat->setDateSent(new \DateTime());
     $stat->setEmail($this->email);
     $stat->setLead($this->factory->getEntityManager()->getReference('MauticLeadBundle:Lead', $this->lead['id']));
     $stat->setEmailAddress($this->lead['email']);
     $stat->setTrackingHash($this->idHash);
     if (!empty($this->source)) {
         $stat->setSource($this->source[0]);
         $stat->setSourceId($this->source[1]);
     }
     $stat->setCopy($this->getBody());
     $stat->setTokens($this->getTokens());
     /** @var \Mautic\EmailBundle\Model\EmailModel $emailModel */
     $emailModel = $this->factory->getModel('email');
     $emailModel->getStatRepository()->saveEntity($stat);
 }
Exemplo n.º 17
0
 /**
  * Drops plugin's tables based on Doctrine metadata.
  *
  * @param array         $metadata
  * @param MauticFactory $factory
  *
  * @throws \Doctrine\DBAL\ConnectionException
  * @throws \Exception
  */
 public static function dropPluginSchema(array $metadata, MauticFactory $factory)
 {
     $db = $factory->getDatabase();
     $schemaTool = new SchemaTool($factory->getEntityManager());
     $dropQueries = $schemaTool->getDropSchemaSQL($metadata);
     $db->beginTransaction();
     try {
         foreach ($dropQueries as $q) {
             $db->query($q);
         }
         $db->commit();
     } catch (\Exception $e) {
         $db->rollback();
         throw $e;
     }
 }
Exemplo n.º 18
0
 /**
  * Determines the winner of A/B test based on number of asset downloads
  *
  * @param MauticFactory $factory
  * @param Page          $parent
  * @param               $children
  *
  * @return array
  */
 public static function determineDownloadWinner($factory, $parent, $children)
 {
     $repo = $factory->getEntityManager()->getRepository('MauticAssetBundle:Download');
     //if this is an email A/B test, then link email to page to form submission
     //if it is a page A/B test, then link form submission to page
     $type = $parent instanceof Email ? 'email' : 'page';
     $ids = array($parent->getId());
     foreach ($children as $c) {
         if ($c->isPublished()) {
             $id = $c->getId();
             $ids[] = $id;
         }
     }
     $startDate = $parent->getVariantStartDate();
     if ($startDate != null && !empty($ids)) {
         $counts = $type == 'page' ? $repo->getDownloadCountsByPage($ids, $startDate) : $repo->getDownloadCountsByEmail($ids, $startDate);
         $translator = $factory->getTranslator();
         if ($counts) {
             $downloads = $support = $data = array();
             $hasResults = array();
             $downloadsLabel = $translator->trans('mautic.asset.abtest.label.downloads');
             $hitsLabel = $type == 'page' ? $translator->trans('mautic.asset.abtest.label.hits') : $translator->trans('mautic.asset.abtest.label.sentemils');
             foreach ($counts as $stats) {
                 $rate = $stats['total'] ? round($stats['count'] / $stats['total'] * 100, 2) : 0;
                 $downloads[$stats['id']] = $rate;
                 $data[$downloadsLabel][] = $stats['count'];
                 $data[$hitsLabel][] = $stats['total'];
                 $support['labels'][] = $stats['id'] . ':' . $stats['name'] . ' (' . $rate . '%)';
                 $hasResults[] = $stats['id'];
             }
             //make sure that parent and published children are included
             if (!in_array($parent->getId(), $hasResults)) {
                 $data[$downloadsLabel][] = 0;
                 $data[$hitsLabel][] = 0;
                 $support['labels'][] = $parent->getId() . ':' . ($type == 'page' ? $parent->getTitle() : $parent->getName()) . ' (0%)';
             }
             foreach ($children as $c) {
                 if ($c->isPublished()) {
                     if (!in_array($c->getId(), $hasResults)) {
                         $data[$downloadsLabel][] = 0;
                         $data[$hitsLabel][] = 0;
                         $support['labels'][] = $c->getId() . ':' . ($type == 'page' ? $c->getTitle() : $c->getName()) . ' (0%)';
                     }
                 }
             }
             $support['data'] = $data;
             //set max for scales
             $maxes = array();
             foreach ($support['data'] as $label => $data) {
                 $maxes[] = max($data);
             }
             $top = max($maxes);
             $support['step_width'] = ceil($top / 10) * 10;
             //put in order from least to greatest just because
             asort($downloads);
             //who's the winner?
             $max = max($downloads);
             //get the page ids with the most number of downloads
             $winners = $max > 0 ? array_keys($downloads, $max) : array();
             return array('winners' => $winners, 'support' => $support, 'basedOn' => 'asset.downloads', 'supportTemplate' => 'MauticPageBundle:SubscribedEvents\\AbTest:bargraph.html.php');
         }
     }
     return array('winners' => array(), 'support' => array(), 'basedOn' => 'asset.downloads');
 }
Exemplo n.º 19
0
 /**
  * @param MauticFactory $factory
  * @param               $eventDetails
  * @param               $action
  *
  * @return bool
  */
 public static function validateUrlHit($factory, $eventDetails, $action)
 {
     $changePoints = array();
     $url = $eventDetails->getUrl();
     $limitToUrl = html_entity_decode(trim($action['properties']['page_url']));
     if (!$limitToUrl || !fnmatch($limitToUrl, $url)) {
         //no points change
         return false;
     }
     $hitRepository = $factory->getEntityManager()->getRepository('MauticPageBundle:Hit');
     $lead = $eventDetails->getLead();
     if ($action['properties']['first_time'] === true) {
         $hitStats = $hitRepository->getDwellTimes(array('leadId' => $lead->getId(), 'urls' => str_replace('*', '%', $url)));
         if (isset($hitStats['count']) && $hitStats['count']) {
             $changePoints['first_time'] = false;
         } else {
             $changePoints['first_time'] = true;
         }
     }
     if ($action['properties']['accumulative_time']) {
         if (!isset($hitStats)) {
             $hitStats = $hitRepository->getDwellTimes(array('leadId' => $lead->getId(), 'urls' => str_replace('*', '%', $url)));
         }
         if (isset($hitStats['sum']) && $hitStats['sum'] >= $action['properties']['accumulative_time']) {
             $changePoints['accumulative_time'] = true;
         } else {
             $changePoints['accumulative_time'] = false;
         }
     }
     if ($action['properties']['page_hits']) {
         if (!isset($hitStats)) {
             $hitStats = $hitRepository->getDwellTimes(array('leadId' => $lead->getId(), 'urls' => str_replace('*', '%', $url)));
         }
         if (isset($hitStats['count']) && $hitStats['count'] >= $action['properties']['page_hits']) {
             $changePoints['page_hits'] = true;
         } else {
             $changePoints['page_hits'] = false;
         }
     }
     if ($action['properties']['returns_within']) {
         $latestHit = $hitRepository->getLatestHit(array('leadId' => $lead->getId(), 'urls' => str_replace('*', '%', $url)));
         $latestPlus = clone $latestHit;
         $latestPlus->add(new \DateInterval('PT' . $action['properties']['returns_within'] . 'S'));
         $now = new \dateTime();
         if ($latestPlus >= $now) {
             $changePoints['returns_within'] = true;
         } else {
             $changePoints['returns_within'] = false;
         }
     }
     if ($action['properties']['returns_after']) {
         if (!isset($latestHit)) {
             $latestHit = $hitRepository->getLatestHit(array('leadId' => $lead->getId(), 'urls' => str_replace('*', '%', $url)));
         }
         $latestPlus = clone $latestHit;
         $latestPlus->add(new \DateInterval('PT' . $action['properties']['returns_after'] . 'S'));
         $now = new \dateTime();
         if ($latestPlus >= $now) {
             $changePoints['returns_after'] = true;
         } else {
             $changePoints['returns_after'] = false;
         }
     }
     // return true only if all configured options are true
     return !in_array(false, $changePoints);
 }
 public function __construct(MauticFactory $factory)
 {
     $this->em = $factory->getEntityManager();
     $this->currentUser = $factory->getUser();
 }
Exemplo n.º 21
0
 /**
  * @return EntityManager
  */
 protected function getEm()
 {
     return $this->factory->getEntityManager();
 }
Exemplo n.º 22
0
 /**
  * @param MauticFactory $factory
  * @param               $eventDetails
  * @param               $action
  *
  * @return bool
  */
 public static function validateUrlHit($factory, $eventDetails, $action)
 {
     $changePoints = [];
     $url = $eventDetails->getUrl();
     $limitToUrl = html_entity_decode(trim($action['properties']['page_url']));
     if (!$limitToUrl || !fnmatch($limitToUrl, $url)) {
         //no points change
         return false;
     }
     $hitRepository = $factory->getEntityManager()->getRepository('MauticPageBundle:Hit');
     $lead = $eventDetails->getLead();
     $urlWithSqlWC = str_replace('*', '%', $url);
     if (isset($action['properties']['first_time']) && $action['properties']['first_time'] === true) {
         $hitStats = $hitRepository->getDwellTimesForUrl($urlWithSqlWC, ['leadId' => $lead->getId()]);
         if (isset($hitStats['count']) && $hitStats['count']) {
             $changePoints['first_time'] = false;
         } else {
             $changePoints['first_time'] = true;
         }
     }
     $now = new \DateTime();
     $latestHit = $hitRepository->getLatestHit(['leadId' => $lead->getId(), $urlWithSqlWC, 'second_to_last' => $eventDetails->getId()]);
     if ($action['properties']['accumulative_time']) {
         if (!isset($hitStats)) {
             $hitStats = $hitRepository->getDwellTimesForUrl($urlWithSqlWC, ['leadId' => $lead->getId()]);
         }
         if (isset($hitStats['sum'])) {
             if ($now->getTimestamp() - $latestHit->getTimestamp() == $hitStats['sum']) {
                 $changePoints['accumulative_time'] = true;
             } else {
                 $changePoints['accumulative_time'] = false;
             }
         } else {
             $changePoints['accumulative_time'] = false;
         }
     }
     if ($action['properties']['page_hits']) {
         if (!isset($hitStats)) {
             $hitStats = $hitRepository->getDwellTimesForUrl($urlWithSqlWC, ['leadId' => $lead->getId()]);
         }
         if (isset($hitStats['count']) && $hitStats['count'] === $action['properties']['page_hits']) {
             $changePoints['page_hits'] = true;
         } else {
             $changePoints['page_hits'] = false;
         }
     }
     if ($action['properties']['returns_within']) {
         if ($now->getTimestamp() - $latestHit->getTimestamp() <= $action['properties']['returns_within']) {
             $changePoints['returns_within'] = true;
         } else {
             $changePoints['returns_within'] = false;
         }
     }
     if ($action['properties']['returns_after']) {
         if ($now->getTimestamp() - $latestHit->getTimestamp() >= $action['properties']['returns_after']) {
             $changePoints['returns_after'] = true;
         } else {
             $changePoints['returns_after'] = false;
         }
     }
     // return true only if all configured options are true
     return !in_array(false, $changePoints);
 }
Exemplo n.º 23
0
 /**
  * @param MauticFactory $factory
  */
 public function __construct(MauticFactory $factory)
 {
     $this->translator = $factory->getTranslator();
     $this->em = $factory->getEntityManager();
 }