/** * @param CampaignExecutionEvent $event */ public function onCampaignTriggerActionChangeStage(CampaignExecutionEvent $event) { $stageChange = false; $lead = $event->getLead(); $leadStage = null; if ($lead instanceof Lead) { $leadStage = $lead->getStage(); } $stageId = (int) $event->getConfig()['stage']; $stageToChangeTo = $this->stageModel->getEntity($stageId); if ($stageToChangeTo != null && $stageToChangeTo->isPublished()) { if ($leadStage && $leadStage->getWeight() <= $stageToChangeTo->getWeight()) { $stageChange = true; } elseif (!$leadStage) { $stageChange = true; } } if ($stageChange) { $parsed = explode('.', $stageToChangeTo->getName()); $lead->stageChangeLogEntry($parsed[0], $stageToChangeTo->getId() . ": " . $stageToChangeTo->getName(), $event->getName()); $lead->setStage($stageToChangeTo); $this->leadModel->saveEntity($lead); } return $event->setResult($stageChange); }
/** * DynamicContentFilterEntryType constructor. * * @param ListModel $listModel * @param StageModel $stageModel */ public function __construct(ListModel $listModel, StageModel $stageModel) { $this->fieldChoices = $listModel->getChoiceFields(); $this->filterFieldChoices(); $this->countryChoices = FormFieldHelper::getCountryChoices(); $this->regionChoices = FormFieldHelper::getRegionChoices(); $this->timezoneChoices = FormFieldHelper::getTimezonesChoices(); $this->localeChoices = FormFieldHelper::getLocaleChoices(); $stages = $stageModel->getRepository()->getSimpleList(); foreach ($stages as $stage) { $this->stageChoices[$stage['value']] = $stage['label']; } }
/** * Set a widget detail when needed. * * @param WidgetDetailEvent $event */ public function onWidgetDetailGenerate(WidgetDetailEvent $event) { $this->checkPermissions($event); $canViewOthers = $event->hasPermission('stage:stages:viewother'); if ($event->getType() == 'stages.in.time') { $widget = $event->getWidget(); $params = $widget->getParams(); if (!$event->isCached()) { $event->setTemplateData(['chartType' => 'line', 'chartHeight' => $widget->getHeight() - 80, 'chartData' => $this->stageModel->getStageLineChartData($params['timeUnit'], $params['dateFrom'], $params['dateTo'], $params['dateFormat'], [], $canViewOthers)]); } $event->setTemplate('MauticCoreBundle:Helper:chart.html.php'); $event->stopPropagation(); } }
/** * @param ReportBuilderEvent $event * @param array $columns */ private function injectAttributionReportData(ReportBuilderEvent $event, array $columns, $type) { $attributionColumns = ['log.campaign_id' => ['label' => 'mautic.lead.report.attribution.campaign_id', 'type' => 'int', 'link' => 'mautic_campaign_action'], 'log.date_triggered' => ['label' => 'mautic.lead.report.attribution.action_date', 'type' => 'datetime'], 'c.name' => ['alias' => 'campaign_name', 'label' => 'mautic.lead.report.attribution.campaign_name', 'type' => 'string'], 'l.stage_id' => ['label' => 'mautic.lead.report.attribution.stage_id', 'type' => 'int', 'link' => 'mautic_stage_action'], 's.name' => ['alias' => 'stage_name', 'label' => 'mautic.lead.report.attribution.stage_name', 'type' => 'string'], 'channel' => ['alias' => 'channel', 'formula' => 'SUBSTRING_INDEX(e.type, \'.\', 1)', 'label' => 'mautic.lead.report.attribution.channel', 'type' => 'string'], 'channel_action' => ['alias' => 'channel_action', 'formula' => 'SUBSTRING_INDEX(e.type, \'.\', -1)', 'label' => 'mautic.lead.report.attribution.channel_action', 'type' => 'string'], 'e.name' => ['alias' => 'action_name', 'label' => 'mautic.lead.report.attribution.action_name', 'type' => 'string']]; $filters = $columns = array_merge($columns, $event->getCategoryColumns('cat.'), $attributionColumns); // Setup available channels $availableChannels = $this->campaignModel->getEvents(); $channels = []; $channelActions = []; foreach ($availableChannels['decision'] as $channel => $decision) { $parts = explode('.', $channel); $channelName = $parts[0]; $channels[$channelName] = $this->translator->hasId('mautic.channel.' . $channelName) ? $this->translator->trans('mautic.channel.' . $channelName) : ucfirst($channelName); unset($parts[0]); $actionValue = implode('.', $parts); if ($this->translator->hasId('mautic.channel.action.' . $channel)) { $actionName = $this->translator->trans('mautic.channel.action.' . $channel); } elseif ($this->translator->hasId('mautic.campaign.' . $channel)) { $actionName = $this->translator->trans('mautic.campaign.' . $channel); } else { $actionName = $channelName . ': ' . $actionValue; } $channelActions[$actionValue] = $actionName; } $filters['channel'] = ['label' => 'mautic.lead.report.attribution.channel', 'type' => 'select', 'list' => $channels]; $filters['channel_action'] = ['label' => 'mautic.lead.report.attribution.channel_action', 'type' => 'select', 'list' => $channelActions]; $this->channelActions = $channelActions; $this->channels = $channels; unset($channelActions, $channels); // Setup available channels $campaigns = $this->campaignModel->getRepository()->getSimpleList(); $filters['log.campaign_id'] = ['label' => 'mautic.lead.report.attribution.filter.campaign', 'type' => 'select', 'list' => $campaigns]; unset($campaigns); // Setup stages list $userStages = $this->stageModel->getUserStages(); $stages = []; foreach ($userStages as $stage) { $stages[$stage['id']] = $stage['name']; } $filters['l.stage_id'] = ['label' => 'mautic.lead.report.attribution.filter.stage', 'type' => 'select', 'list' => $stages]; unset($stages); $context = "contact.attribution.{$type}"; $event->addGraph($context, 'pie', 'mautic.lead.graph.pie.attribution_stages')->addGraph($context, 'pie', 'mautic.lead.graph.pie.attribution_campaigns')->addGraph($context, 'pie', 'mautic.lead.graph.pie.attribution_actions')->addGraph($context, 'pie', 'mautic.lead.graph.pie.attribution_channels'); $data = ['display_name' => 'mautic.lead.report.attribution.' . $type, 'columns' => $columns, 'filters' => $filters]; $event->addTable($context, $data, 'contacts'); }
/** * @param MauticEvents\CommandListEvent $event */ public function onBuildCommandList(MauticEvents\CommandListEvent $event) { if ($this->security->isGranted('stage:stages:view')) { $event->addCommands('mautic.stage.actions.header.index', $this->stageModel->getCommandList()); } }