/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKeySent = 'email.sent'; $eventTypeNameSent = $this->translator->trans('mautic.email.sent'); $event->addEventType($eventTypeKeySent, $eventTypeNameSent); $eventTypeKeyRead = 'email.read'; $eventTypeNameRead = $this->translator->trans('mautic.email.read'); $event->addEventType($eventTypeKeyRead, $eventTypeNameRead); // Decide if those events are filtered $filters = $event->getEventFilters(); $lead = $event->getLead(); $options = array('ipIds' => array(), 'filters' => $filters); /** @var \Mautic\CoreBundle\Entity\IpAddress $ip */ /* foreach ($lead->getIpAddresses() as $ip) { $options['ipIds'][] = $ip->getId(); } */ /** @var \Mautic\EmailBundle\Entity\StatRepository $statRepository */ $statRepository = $this->factory->getEntityManager()->getRepository('MauticEmailBundle:Stat'); $stats = $statRepository->getLeadStats($lead->getId(), $options); // Add the events to the event array foreach ($stats as $stat) { if ($stat['dateRead'] && $event->isApplicable($eventTypeKeyRead, true)) { $event->addEvent(array('event' => $eventTypeKeyRead, 'eventLabel' => $eventTypeNameRead, 'timestamp' => $stat['dateRead'], 'extra' => array('stats' => $stat, 'type' => 'read'), 'contentTemplate' => 'MauticEmailBundle:SubscribedEvents\\Timeline:index.html.php')); } // Email read if ($stat['dateSent'] && $event->isApplicable($eventTypeKeySent)) { $event->addEvent(array('event' => $eventTypeKeySent, 'eventLabel' => $eventTypeNameSent, 'timestamp' => $stat['dateSent'], 'extra' => array('stats' => $stat, 'type' => 'sent'), 'contentTemplate' => 'MauticEmailBundle:SubscribedEvents\\Timeline:index.html.php')); } } }
private function addTaskEvents(LeadTimelineEvent $event) { $eventTypeKeyCreated = 'task.created'; $eventTypeKeyCompleted = 'task.completed'; $event->addEventType($eventTypeKeyCreated, $this->translator->trans('ddi.lead_actions.tasks.timeline.filter.created')); $event->addEventType($eventTypeKeyCompleted, $this->translator->trans('ddi.lead_actions.tasks.timeline.filter.completed')); $em = $this->factory->getEntityManager(); $query = $em->getRepository('CustomCrmBundle:Task')->createQueryBuilder('t'); $query->where('t.lead = :lead')->setParameter('lead', $event->getLead()); $filters = $event->getEventFilters(); if (isset($filters['search']) && $filters['search']) { $query->andWhere('t.name LIKE :name')->setParameter('name', '%' . $filters['search'] . '%'); } $tasks = $query->getQuery()->getResult(); if ($event->isApplicable($eventTypeKeyCreated)) { foreach ($tasks as $task) { $event->addEvent(array('event' => $eventTypeKeyCreated, 'eventLabel' => 'Task created', 'eventType' => 'Task created', 'timestamp' => $task->getDateAdded(), 'extra' => array('name' => $task->getName()), 'contentTemplate' => 'CustomCrmBundle:Task\\Timeline:created.html.php')); } } // Completed tasks if ($event->isApplicable($eventTypeKeyCompleted)) { foreach ($tasks as $task) { if ($task->getIsCompleted()) { $event->addEvent(array('event' => $eventTypeKeyCompleted, 'eventLabel' => 'task', 'timestamp' => $task->getDateCompleted(), 'extra' => array('name' => $task->getName()), 'contentTemplate' => 'CustomCrmBundle:Task\\Timeline:completed.html.php')); } } } }
/** * Compile events for the lead timeline. * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'stage.changed'; $eventTypeName = $this->translator->trans('mautic.stage.event.changed'); $event->addEventType($eventTypeKey, $eventTypeName); if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); /** @var StagesChangeLogRepository $logRepository */ $logRepository = $this->em->getRepository('MauticLeadBundle:StagesChangeLog'); $logs = $logRepository->getLeadTimelineEvents($lead->getId(), $event->getQueryOptions()); // Add to counter $event->addToCounter($eventTypeKey, $logs); if (!$event->isEngagementCount()) { // Add the logs to the event array foreach ($logs['results'] as $log) { if (isset($log['reference']) && $log['reference'] != null) { $eventLabel = ['label' => $log['eventName'], 'href' => $this->router->generate('mautic_stage_action', ['objectAction' => 'edit', 'objectId' => $log['reference']]), 'isExternal' => false]; } else { $eventLabel = $log['eventName']; } $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => $eventLabel, 'eventType' => $eventTypeName, 'timestamp' => $log['dateAdded'], 'extra' => ['log' => $log], 'icon' => 'fa-tachometer']); } } }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event * * @return void */ public function onTimelineGenerate(LeadTimelineEvent $event) { $lead = $event->getLead(); /** @var \Mautic\CoreBundle\Model\AuditLogModel $model */ $model = $this->factory->getModel('core.auditLog'); $rows = $model->getEntities(array('filter' => array('force' => array(array('column' => 'e.bundle', 'expr' => 'eq', 'value' => 'lead'), array('column' => 'e.object', 'expr' => 'eq', 'value' => 'lead'), array('column' => 'e.action', 'expr' => 'in', 'value' => array("create", "identified", "ipadded")), array('column' => 'e.objectId', 'expr' => 'eq', 'value' => $lead->getId()), array('column' => 'e.dateAdded', 'expr' => 'gte', 'value' => $lead->getDateAdded()))))); $filters = $event->getEventFilters(); // Add the entries to the event array /** @var \Mautic\CoreBundle\Entity\AuditLog $row */ $IpAddresses = $lead->getIpAddresses(); $foundIpAddresses = array(); foreach ($rows as $row) { $action = $row->getAction(); $eventTypeKey = 'lead.' . $action; //don't include if type is not applicable or if there is a search string as there is nothing to search for this if (!$event->isApplicable($eventTypeKey) || !empty($filters['search'])) { continue; } $eventLabel = $this->translator->trans('mautic.lead.event.' . $row->getAction()); $details = $row->getDetails(); // Guess the IP address if (is_string($details)) { $ipAddress = $details; } elseif (isset($details['ipAddresses'][1])) { $ipAddress = $details['ipAddresses'][1]; } elseif (isset($details[1])) { $ipAddress = $details[1]; } else { $ipAddress = $row->getIpAddress(); } // Prevent duplicate IP entries from showing if ($eventTypeKey == 'lead.ipadded') { $ipDate = $row->getDateAdded()->format('Y-m-d H:i'); if (isset($foundIpAddresses[$ipDate]) && in_array($ipAddress, $foundIpAddresses[$ipDate])) { continue; } if (!isset($foundIpAddresses[$ipDate])) { $foundIpAddresses[$ipDate] = array(); } $foundIpAddresses[$ipDate][] = $ipAddress; } $event->addEvent(array('event' => $eventTypeKey, 'eventLabel' => $eventLabel, 'timestamp' => $row->getDateAdded(), 'extra' => array('details' => $details, 'editor' => $row->getUserName(), 'ipDetails' => $eventTypeKey == 'lead.ipadded' ? $IpAddresses[$ipAddress] : array()), 'contentTemplate' => 'MauticLeadBundle:SubscribedEvents\\Timeline:' . $action . '.html.php')); } }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'point.gained'; $eventTypeName = $this->translator->trans('mautic.point.event.gained'); $event->addEventType($eventTypeKey, $eventTypeName); $filters = $event->getEventFilters(); if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); $options = array('ipIds' => array(), 'filters' => $filters); /** @var \Mautic\CoreBundle\Entity\IpAddress $ip */ /* foreach ($lead->getIpAddresses() as $ip) { $options['ipIds'][] = $ip->getId(); } */ /** @var \Mautic\PageBundle\Entity\HitRepository $hitRepository */ $logRepository = $this->factory->getEntityManager()->getRepository('MauticLeadBundle:PointsChangeLog'); $logs = $logRepository->getLeadTimelineEvents($lead->getId(), $options); // Add the logs to the event array foreach ($logs as $log) { $event->addEvent(array('event' => $eventTypeKey, 'eventLabel' => $eventTypeName, 'timestamp' => $log['dateAdded'], 'extra' => array('log' => $log), 'contentTemplate' => 'MauticPointBundle:SubscribedEvents\\Timeline:index.html.php', 'icon' => 'fa-calculator')); } }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'form.submitted'; $eventTypeName = $this->translator->trans('mautic.form.event.submitted'); $event->addEventType($eventTypeKey, $eventTypeName); $filters = $event->getEventFilters(); if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); $options = array('ipIds' => array(), 'leadId' => $lead->getId(), 'filters' => $filters); /** @var \Mautic\CoreBundle\Entity\IpAddress $ip */ /* foreach ($lead->getIpAddresses() as $ip) { $options['ipIds'][] = $ip->getId(); } */ /** @var \Mautic\FormBundle\Entity\SubmissionRepository $submissionRepository */ $submissionRepository = $this->factory->getEntityManager()->getRepository('MauticFormBundle:Submission'); $rows = $submissionRepository->getSubmissions($options); $pageModel = $this->factory->getModel('page.page'); $formModel = $this->factory->getModel('form.form'); // Add the submissions to the event array foreach ($rows as $row) { // Convert to local from UTC $dtHelper = $this->factory->getDate($row['dateSubmitted'], 'Y-m-d H:i:s', 'UTC'); $submission = $submissionRepository->getEntity($row['id']); $event->addEvent(array('event' => $eventTypeKey, 'eventLabel' => $eventTypeName, 'timestamp' => $dtHelper->getLocalDateTime(), 'extra' => array('submission' => $submission, 'form' => $formModel->getEntity($row['form_id']), 'page' => $pageModel->getEntity($row['page_id'])), 'contentTemplate' => 'MauticFormBundle:SubscribedEvents\\Timeline:index.html.php')); } }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'asset.download'; $eventTypeName = $this->translator->trans('mautic.asset.event.download'); $event->addEventType($eventTypeKey, $eventTypeName); // Decide if those events are filtered $filters = $event->getEventFilters(); if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); $options = array('ipIds' => array(), 'filters' => $filters); /** @var \Mautic\CoreBundle\Entity\IpAddress $ip */ /* foreach ($lead->getIpAddresses() as $ip) { $options['ipIds'][] = $ip->getId(); } */ /** @var \Mautic\AssetBundle\Entity\DownloadRepository $downloadRepository */ $downloadRepository = $this->factory->getEntityManager()->getRepository('MauticAssetBundle:Download'); $downloads = $downloadRepository->getLeadDownloads($lead->getId(), $options); /** @var \Mautic\AssetBundle\Model\AssetModel $model */ $model = $this->factory->getModel('asset.asset'); // Add the downloads to the event array foreach ($downloads as $download) { $event->addEvent(array('event' => $eventTypeKey, 'eventLabel' => $eventTypeName, 'timestamp' => $download['dateDownload'], 'extra' => array('asset' => $model->getEntity($download['asset_id'])), 'contentTemplate' => 'MauticAssetBundle:SubscribedEvents\\Timeline:index.html.php')); } }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'point.gained'; $eventTypeName = $this->translator->trans('mautic.point.event.gained'); $event->addEventType($eventTypeKey, $eventTypeName); if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); /** @var \Mautic\PageBundle\Entity\HitRepository $hitRepository */ $logRepository = $this->em->getRepository('MauticLeadBundle:PointsChangeLog'); $logs = $logRepository->getLeadTimelineEvents($lead->getId(), $event->getQueryOptions()); // Add to counter $event->addToCounter($eventTypeKey, $logs); if (!$event->isEngagementCount()) { // Add the logs to the event array foreach ($logs['results'] as $log) { $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => $log['eventName'] . ' / ' . $log['delta'], 'eventType' => $eventTypeName, 'timestamp' => $log['dateAdded'], 'extra' => ['log' => $log], 'icon' => 'fa-calculator']); } } }
/** * @param LeadTimelineEvent $event * @param $state */ protected function addEmailEvents(LeadTimelineEvent $event, $state) { // Set available event types $eventTypeKey = 'email.' . $state; $eventTypeName = $this->translator->trans('mautic.email.' . $state); $event->addEventType($eventTypeKey, $eventTypeName); // Decide if those events are filtered if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); /** @var \Mautic\EmailBundle\Entity\StatRepository $statRepository */ $statRepository = $this->em->getRepository('MauticEmailBundle:Stat'); $queryOptions = $event->getQueryOptions(); $queryOptions['state'] = $state; $stats = $statRepository->getLeadStats($lead->getId(), $queryOptions); // Add total to counter $event->addToCounter($eventTypeKey, $stats); if (!$event->isEngagementCount()) { // Add the events to the event array foreach ($stats['results'] as $stat) { if (!empty($stat['storedSubject'])) { $label = $this->translator->trans('mautic.email.timeline.event.custom_email') . ': ' . $stat['storedSubject']; } elseif (!empty($stat['email_name'])) { $label = $stat['email_name']; } else { $label = $this->translator->trans('mautic.email.timeline.event.custom_email'); } if (!empty($stat['idHash'])) { $eventName = ['label' => $label, 'href' => $this->router->generate('mautic_email_webview', ['idHash' => $stat['idHash']]), 'isExternal' => true]; } else { $eventName = $label; } if ('failed' == $state or 'sent' == $state) { //this is to get the correct column for date dateSent $dateSent = 'sent'; } else { $dateSent = 'read'; } $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => $eventName, 'eventType' => $eventTypeName, 'timestamp' => $stat['date' . ucfirst($dateSent)], 'dateSent' => $stat['dateSent'], 'extra' => ['stat' => $stat, 'type' => $state], 'contentTemplate' => 'MauticEmailBundle:SubscribedEvents\\Timeline:index.html.php', 'icon' => $state == 'read' ? 'fa-envelope-o' : 'fa-envelope']); } } }
/** * Compile events for the lead timeline. * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'dynamic.content.sent'; $eventTypeNameSent = $this->translator->trans('mautic.dynamic.content.sent'); $event->addEventType($eventTypeKey, $eventTypeNameSent); if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); /** @var \Mautic\DynamicContentBundle\Entity\StatRepository $statRepository */ $statRepository = $this->em->getRepository('MauticDynamicContentBundle:Stat'); $stats = $statRepository->getLeadStats($lead->getId(), $event->getQueryOptions()); // Add total number to counter $event->addToCounter($eventTypeKey, $stats); if (!$event->isEngagementCount()) { // Add the events to the event array foreach ($stats['results'] as $stat) { if ($stat['dateSent']) { $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => ['label' => $stat['name'], 'href' => $this->router->generate('mautic_dynamicContent_action', ['objectId' => $stat['dynamic_content_id'], 'objectAction' => 'view'])], 'eventType' => $eventTypeNameSent, 'timestamp' => $stat['dateSent'], 'extra' => ['stat' => $stat, 'type' => 'sent'], 'contentTemplate' => 'MauticDynamicContentBundle:SubscribedEvents\\Timeline:index.html.php', 'icon' => 'fa-envelope']); } } } }
/** * Compile events for the lead timeline. * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'asset.download'; $eventTypeName = $this->translator->trans('mautic.asset.event.download'); $event->addEventType($eventTypeKey, $eventTypeName); // Decide if those events are filtered if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); /** @var \Mautic\AssetBundle\Entity\DownloadRepository $downloadRepository */ $downloadRepository = $this->em->getRepository('MauticAssetBundle:Download'); $downloads = $downloadRepository->getLeadDownloads($lead->getId(), $event->getQueryOptions()); // Add total number to counter $event->addToCounter($eventTypeKey, $downloads); if (!$event->isEngagementCount()) { // Add the downloads to the event array foreach ($downloads['results'] as $download) { $asset = $this->assetModel->getEntity($download['asset_id']); $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => ['label' => $download['title'], 'href' => $this->router->generate('mautic_asset_action', ['objectAction' => 'view', 'objectId' => $download['asset_id']])], 'extra' => ['asset' => $asset, 'assetDownloadUrl' => $this->assetModel->generateUrl($asset)], 'eventType' => $eventTypeName, 'timestamp' => $download['dateDownload'], 'icon' => 'fa-download', 'contentTemplate' => 'MauticAssetBundle:SubscribedEvents\\Timeline:index.html.php']); } } }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'form.submitted'; $eventTypeName = $this->translator->trans('mautic.form.event.submitted'); $event->addEventType($eventTypeKey, $eventTypeName); if (!$event->isApplicable($eventTypeKey)) { return; } /** @var \Mautic\FormBundle\Entity\SubmissionRepository $submissionRepository */ $submissionRepository = $this->em->getRepository('MauticFormBundle:Submission'); $rows = $submissionRepository->getSubmissions($event->getQueryOptions()); // Add total to counter $event->addToCounter($eventTypeKey, $rows); if (!$event->isEngagementCount()) { // Add the submissions to the event array foreach ($rows['results'] as $row) { // Convert to local from UTC $form = $this->formModel->getEntity($row['form_id']); $submission = $submissionRepository->getEntity($row['id']); $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => ['label' => $form->getName(), 'href' => $this->router->generate('mautic_form_action', ['objectAction' => 'view', 'objectId' => $form->getId()])], 'eventType' => $eventTypeName, 'timestamp' => $row['dateSubmitted'], 'extra' => ['submission' => $submission, 'form' => $form, 'page' => $this->pageModel->getEntity($row['page_id'])], 'contentTemplate' => 'MauticFormBundle:SubscribedEvents\\Timeline:index.html.php', 'icon' => 'fa-pencil-square-o']); } } }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'page.hit'; $eventTypeName = $this->translator->trans('mautic.page.event.hit'); $event->addEventType($eventTypeKey, $eventTypeName); $filters = $event->getEventFilters(); if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); $options = array('ipIds' => array(), 'filters' => $filters); /** @var \Mautic\CoreBundle\Entity\IpAddress $ip */ /* foreach ($lead->getIpAddresses() as $ip) { $options['ipIds'][] = $ip->getId(); } */ /** @var \Mautic\PageBundle\Entity\HitRepository $hitRepository */ $hitRepository = $this->factory->getEntityManager()->getRepository('MauticPageBundle:Hit'); $hits = $hitRepository->getLeadHits($lead->getId(), $options); $model = $this->factory->getModel('page.page'); // Add the hits to the event array foreach ($hits as $hit) { if ($hit['source'] && $hit['sourceId']) { $sourceModel = $this->factory->getModel($hit['source'] . '.' . $hit['source']); $sourceEntity = $sourceModel->getEntity($hit['sourceId']); if (method_exists($sourceEntity, 'getName')) { $hit['sourceName'] = $sourceEntity->getName(); } if (method_exists($sourceEntity, 'getTitle')) { $hit['sourceName'] = $sourceEntity->getTitle(); } } $event->addEvent(array('event' => $eventTypeKey, 'eventLabel' => $eventTypeName, 'timestamp' => $hit['dateHit'], 'extra' => array('page' => $model->getEntity($hit['page_id']), 'hit' => $hit), 'contentTemplate' => 'MauticPageBundle:SubscribedEvents\\Timeline:index.html.php')); } }
/** * Get engagement counts by time unit * * @param Lead $lead * @param \DateTime|null $dateFrom * @param \DateTime|null $dateTo * @param string $unit Y, m, d, etc * * @return array|int */ public function getEngagementCount(Lead $lead, \DateTime $dateFrom = null, \DateTime $dateTo = null, $unit = 'm', ChartQuery $chartQuery = null) { $event = new LeadTimelineEvent($lead); $event->setCountOnly($dateFrom, $dateTo, $unit, $chartQuery); $this->dispatcher->dispatch(LeadEvents::TIMELINE_ON_GENERATE, $event); return $event->getEventCounter(); }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'page.hit'; $eventTypeName = $this->translator->trans('mautic.page.event.hit'); $event->addEventType($eventTypeKey, $eventTypeName); $filters = $event->getEventFilters(); if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); $options = array('ipIds' => array(), 'filters' => $filters); /** @var \Mautic\CoreBundle\Entity\IpAddress $ip */ /* foreach ($lead->getIpAddresses() as $ip) { $options['ipIds'][] = $ip->getId(); } */ /** @var \Mautic\PageBundle\Entity\HitRepository $hitRepository */ $hitRepository = $this->factory->getEntityManager()->getRepository('MauticPageBundle:Hit'); $hits = $hitRepository->getLeadHits($lead->getId(), $options); $model = $this->factory->getModel('page.page'); // Add the hits to the event array foreach ($hits as $hit) { $template = 'MauticPageBundle:SubscribedEvents\\Timeline:index.html.php'; $eventLabel = $eventTypeName; if ($hit['source'] && $hit['sourceId']) { $sourceModel = false; try { $sourceModel = $this->factory->getModel($hit['source']); } catch (\Exception $exception) { // Try a plugin try { $sourceModel = $this->factory->getModel('plugin.' . $hit['source']); } catch (\Exception $exception) { // No model found } } if ($sourceModel) { try { $sourceEntity = $sourceModel->getEntity($hit['sourceId']); if (method_exists($sourceEntity, $sourceModel->getNameGetter())) { $hit['sourceName'] = $sourceEntity->{$sourceModel->getNameGetter()}(); } $baseRouteName = str_replace('.', '_', $hit['source']); if (method_exists($sourceModel, 'getActionRouteBase')) { $baseRouteName = $sourceModel->getActionRouteBase(); } $routeSourceName = 'mautic_' . $baseRouteName . '_action'; if ($this->factory->getRouter()->getRouteCollection()->get($routeSourceName) !== null) { $hit['sourceRoute'] = $this->factory->getRouter()->generate($routeSourceName, array('objectAction' => 'view', 'objectId' => $hit['sourceId'])); } // Allow a custom template if applicable if (method_exists($sourceModel, 'getPageHitLeadTimelineTemplate')) { $template = $sourceModel->getPageHitLeadTimelineTemplate($hit); } if (method_exists($sourceModel, 'getPageHitLeadTimelineLabel')) { $eventLabel = $sourceModel->getPageHitLeadTimelineLabel($hit); } } catch (\Exception $exception) { // Not found } } } $event->addEvent(array('event' => $eventTypeKey, 'eventLabel' => $eventLabel, 'timestamp' => $hit['dateHit'], 'extra' => array('page' => $model->getEntity($hit['page_id']), 'hit' => $hit), 'contentTemplate' => $template)); } }
/** * Compile events for the lead timeline. * * @param LeadTimelineEvent $event */ public function onTimelineGenerateVideo(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'page.videohit'; $eventTypeName = $this->translator->trans('mautic.page.event.videohit'); $event->addEventType($eventTypeKey, $eventTypeName); if (!$event->isApplicable($eventTypeKey)) { return; } /** @var \Mautic\PageBundle\Entity\VideoHitRepository $hitRepository */ $hitRepository = $this->em->getRepository('MauticPageBundle:VideoHit'); $hits = $hitRepository->getTimelineStats($event->getLead()->getId(), $event->getQueryOptions()); $event->addToCounter($eventTypeKey, $hits); if (!$event->isEngagementCount()) { // Add the hits to the event array foreach ($hits['results'] as $hit) { $template = 'MauticPageBundle:SubscribedEvents\\Timeline:videohit.html.php'; $eventLabel = $eventTypeName; $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => $eventLabel, 'eventType' => $eventTypeName, 'timestamp' => $hit['date_hit'], 'extra' => ['hit' => $hit], 'contentTemplate' => $template, 'icon' => 'fa-video-camera']); } } }
/** * @param Events\LeadTimelineEvent $event * @param $eventTypeKey * @param $eventTypeName */ protected function addTimelineDoNotContactEntries(Events\LeadTimelineEvent $event, $eventTypeKey, $eventTypeName) { $lead = $event->getLead(); /** @var \Mautic\LeadBundle\Entity\DoNotContactRepository $dncRepo */ $dncRepo = $this->em->getRepository('MauticLeadBundle:DoNotContact'); /** @var \Mautic\LeadBundle\Entity\DoNotContact[] $entries */ $rows = $dncRepo->getTimelineStats($lead->getId(), $event->getQueryOptions()); // Add to counter $event->addToCounter($eventTypeKey, $rows); if (!$event->isEngagementCount()) { foreach ($rows['results'] as $row) { switch ($row['reason']) { case DoNotContact::UNSUBSCRIBED: $row['reason'] = $this->translator->trans('mautic.lead.event.donotcontact_unsubscribed'); break; case DoNotContact::BOUNCED: $row['reason'] = $this->translator->trans('mautic.lead.event.donotcontact_bounced'); break; case DoNotContact::MANUAL: $row['reason'] = $this->translator->trans('mautic.lead.event.donotcontact_manual'); break; } $template = 'MauticLeadBundle:SubscribedEvents\\Timeline:donotcontact.html.php'; $icon = 'fa-ban'; if (!empty($row['channel'])) { if ($channelModel = $this->getChannelModel($row['channel'])) { // Allow a custom template if applicable if (method_exists($channelModel, 'getDoNotContactLeadTimelineTemplate')) { $template = $channelModel->getDoNotContactLeadTimelineTemplate($row); } if (method_exists($channelModel, 'getDoNotContactLeadTimelineLabel')) { $eventTypeName = $channelModel->getDoNotContactLeadTimelineLabel($row); } if (method_exists($channelModel, 'getDoNotContactLeadTimelineIcon')) { $icon = $channelModel->getDoNotContactLeadTimelineIcon($row); } if (!empty($row['channel_id'])) { if ($item = $this->getChannelEntityName($row['channel'], $row['channel_id'], true)) { $row['itemName'] = $item['name']; $row['itemRoute'] = $item['url']; } } } } $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => isset($row['itemName']) ? ['label' => ucfirst($row['channel']) . ' / ' . $row['itemName'], 'href' => $row['itemRoute']] : ucfirst($row['channel']), 'eventType' => $eventTypeName, 'timestamp' => $row['date_added'], 'extra' => ['dnc' => $row], 'contentTemplate' => $template, 'icon' => $icon]); } } }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'campaign.event'; $eventTypeName = $this->translator->trans('mautic.campaign.triggered'); $event->addEventType($eventTypeKey, $eventTypeName); // Decide if those events are filtered if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); /** @var \Mautic\CampaignBundle\Entity\LeadEventLogRepository $logRepository */ $logRepository = $this->em->getRepository('MauticCampaignBundle:LeadEventLog'); $logs = $logRepository->getLeadLogs($lead->getId(), $event->getQueryOptions()); $eventSettings = $this->campaignModel->getEvents(); // Add total number to counter $event->addToCounter($eventTypeKey, $logs); if (!$event->isEngagementCount()) { foreach ($logs['results'] as $log) { // Hide this from the time line all together if (!empty($log['metadata']['failed'])) { $event->subtractFromCounter($eventTypeKey); continue; } $template = !empty($eventSettings['action'][$log['type']]['timelineTemplate']) ? $eventSettings['action'][$log['type']]['timelineTemplate'] : 'MauticCampaignBundle:SubscribedEvents\\Timeline:index.html.php'; $event->addEvent(['event' => $eventTypeKey, 'eventLabel' => ['label' => $log['event_name'] . ' / ' . $log['campaign_name'], 'href' => $this->router->generate('mautic_campaign_action', ['objectAction' => 'view', 'objectId' => $log['campaign_id']])], 'eventType' => $eventTypeName, 'timestamp' => $log['dateTriggered'], 'extra' => ['log' => $log], 'contentTemplate' => $template, 'icon' => 'fa-clock-o']); } } }
/** * Compile events for the lead timeline * * @param LeadTimelineEvent $event */ public function onTimelineGenerate(LeadTimelineEvent $event) { // Set available event types $eventTypeKey = 'campaign.evented'; $eventTypeName = $this->translator->trans('mautic.campaign.triggered'); $event->addEventType($eventTypeKey, $eventTypeName); // Decide if those events are filtered $filters = $event->getEventFilters(); if (!$event->isApplicable($eventTypeKey)) { return; } $lead = $event->getLead(); $options = array('ipIds' => array(), 'filters' => $filters); /** @var \Mautic\CoreBundle\Entity\IpAddress $ip */ /* foreach ($lead->getIpAddresses() as $ip) { $options['ipIds'][] = $ip->getId(); } */ /** @var \Mautic\CampaignBundle\Entity\LeadEventLogRepository $logRepository */ $logRepository = $this->factory->getEntityManager()->getRepository('MauticCampaignBundle:LeadEventLog'); $logs = $logRepository->getLeadLogs($lead->getId(), $options); $model = $this->factory->getModel('campaign'); $eventSettings = $model->getEvents(); // Add the hits to the event array foreach ($logs as $log) { if (!is_array($log['metadata'])) { $log['metadata'] = $log['metadata'] !== null ? unserialize($log['metadata']) : array(); } $template = !empty($eventSettings['action'][$log['type']]['timelineTemplate']) ? $eventSettings['action'][$log['type']]['timelineTemplate'] : 'MauticCampaignBundle:SubscribedEvents\\Timeline:index.html.php'; $event->addEvent(array('event' => $eventTypeKey, 'eventLabel' => $eventTypeName, 'timestamp' => $log['dateTriggered'], 'extra' => array('log' => $log), 'contentTemplate' => $template)); } }
/** * Compile events for the lead timeline * * @param Events\LeadTimelineEvent $event */ public function onTimelineGenerate(Events\LeadTimelineEvent $event) { $eventTypes = array('lead.create' => 'mautic.lead.event.create', 'lead.identified' => 'mautic.lead.event.identified', 'lead.ipadded' => 'mautic.lead.event.ipadded'); foreach ($eventTypes as $type => $label) { $event->addEventType($type, $this->translator->trans($label)); } }