コード例 #1
0
 /**
  * DynamicContentFilterEntryFiltersType constructor.
  *
  * @param MauticFactory $factory
  * @param ListModel     $listModel
  */
 public function __construct(MauticFactory $factory, ListModel $listModel)
 {
     $operatorChoices = $listModel->getFilterExpressionFunctions();
     foreach ($operatorChoices as $key => $value) {
         if (empty($value['hide'])) {
             $this->operatorChoices[$key] = $value['label'];
         }
     }
     $this->translator = $factory->getTranslator();
 }
コード例 #2
0
 /**
  * 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'];
     }
 }
コード例 #3
0
ファイル: CampaignModel.php プロジェクト: Yame-/mautic
 /**
  * Get a list of source choices
  *
  * @param $sourceType
  *
  * @return array
  */
 public function getSourceLists($sourceType = null)
 {
     $choices = array();
     switch ($sourceType) {
         case 'lists':
         case null:
             $choices['lists'] = array();
             $lists = empty($options['global_only']) ? $this->leadListModel->getUserLists() : $this->leadListModel->getGlobalLists();
             foreach ($lists as $list) {
                 $choices['lists'][$list['id']] = $list['name'];
             }
         case 'forms':
         case null:
             $choices['forms'] = array();
             $viewOther = $this->security->isGranted('form:forms:viewother');
             $repo = $this->formModel->getRepository();
             $repo->setCurrentUser($this->user);
             $forms = $repo->getFormList('', 0, 0, $viewOther, 'campaign');
             foreach ($forms as $form) {
                 $choices['forms'][$form['id']] = $form['name'];
             }
     }
     foreach ($choices as &$typeChoices) {
         asort($typeChoices);
     }
     return $sourceType == null ? $choices : $choices[$sourceType];
 }
コード例 #4
0
ファイル: LeadModel.php プロジェクト: Yame-/mautic
 /**
  * Get bar chart data of contacts
  *
  * @param char      $unit   {@link php.net/manual/en/function.date.php#refsect1-function.date-parameters}
  * @param \DateTime $dateFrom
  * @param \DateTime $dateTo
  * @param string    $dateFormat
  * @param array     $filter
  * @param boolean   $canViewOthers
  *
  * @return array
  */
 public function getLeadsLineChartData($unit, $dateFrom, $dateTo, $dateFormat = null, $filter = array(), $canViewOthers = true)
 {
     $flag = null;
     $topLists = null;
     $allLeadsT = $this->translator->trans('mautic.lead.all.leads');
     $identifiedT = $this->translator->trans('mautic.lead.identified');
     $anonymousT = $this->translator->trans('mautic.lead.lead.anonymous');
     if (isset($filter['flag'])) {
         $flag = $filter['flag'];
         unset($filter['flag']);
     }
     if (!$canViewOthers) {
         $filter['owner_id'] = $this->user->getId();
     }
     $chart = new LineChart($unit, $dateFrom, $dateTo, $dateFormat);
     $query = new ChartQuery($this->em->getConnection(), $dateFrom, $dateTo);
     $anonymousFilter = $filter;
     $anonymousFilter['date_identified'] = array('expression' => 'isNull');
     $identifiedFilter = $filter;
     $identifiedFilter['date_identified'] = array('expression' => 'isNotNull');
     if ($flag == 'top') {
         $topLists = $this->leadListModel->getTopLists(6, $dateFrom, $dateTo);
         if ($topLists) {
             foreach ($topLists as $list) {
                 $filter['leadlist_id'] = array('value' => $list['id'], 'list_column_name' => 't.id');
                 $all = $query->fetchTimeData('leads', 'date_added', $filter);
                 $chart->setDataset($list['name'] . ': ' . $allLeadsT, $all);
             }
         }
     } elseif ($flag == 'topIdentifiedVsAnonymous') {
         $topLists = $this->leadListModel->getTopLists(3, $dateFrom, $dateTo);
         if ($topLists) {
             foreach ($topLists as $list) {
                 $anonymousFilter['leadlist_id'] = array('value' => $list['id'], 'list_column_name' => 't.id');
                 $identifiedFilter['leadlist_id'] = array('value' => $list['id'], 'list_column_name' => 't.id');
                 $identified = $query->fetchTimeData('leads', 'date_added', $identifiedFilter);
                 $anonymous = $query->fetchTimeData('leads', 'date_added', $anonymousFilter);
                 $chart->setDataset($list['name'] . ': ' . $identifiedT, $identified);
                 $chart->setDataset($list['name'] . ': ' . $anonymousT, $anonymous);
             }
         }
     } elseif ($flag == 'identified') {
         $identified = $query->fetchTimeData('leads', 'date_added', $identifiedFilter);
         $chart->setDataset($identifiedT, $identified);
     } elseif ($flag == 'anonymous') {
         $anonymous = $query->fetchTimeData('leads', 'date_added', $anonymousFilter);
         $chart->setDataset($anonymousT, $anonymous);
     } elseif ($flag == 'identifiedVsAnonymous') {
         $identified = $query->fetchTimeData('leads', 'date_added', $identifiedFilter);
         $anonymous = $query->fetchTimeData('leads', 'date_added', $anonymousFilter);
         $chart->setDataset($identifiedT, $identified);
         $chart->setDataset($anonymousT, $anonymous);
     } else {
         $all = $query->fetchTimeData('leads', 'date_added', $filter);
         $chart->setDataset($allLeadsT, $all);
     }
     return $chart->render();
 }
コード例 #5
0
 /**
  * Add available tables and columns to the report builder lookup.
  *
  * @param ReportBuilderEvent $event
  */
 public function onReportBuilder(ReportBuilderEvent $event)
 {
     $leadContexts = ['leads', 'lead.pointlog', 'contact.attribution.multi', 'contact.attribution.first', 'contact.attribution.last'];
     if ($event->checkContext($leadContexts)) {
         $columns = ['l.id' => ['label' => 'mautic.lead.report.contact_id', 'type' => 'int', 'link' => 'mautic_contact_action'], 'i.ip_address' => ['label' => 'mautic.core.ipaddress', 'type' => 'text'], 'l.date_identified' => ['label' => 'mautic.lead.report.date_identified', 'type' => 'datetime'], 'l.points' => ['label' => 'mautic.lead.points', 'type' => 'int'], 'l.owner_id' => ['label' => 'mautic.lead.report.owner_id', 'type' => 'int', 'link' => 'mautic_user_action'], 'u.first_name' => ['label' => 'mautic.lead.report.owner_firstname', 'type' => 'string'], 'u.last_name' => ['label' => 'mautic.lead.report.owner_lastname', 'type' => 'string']];
         $leadFields = $this->fieldModel->getEntities();
         $fieldColumns = [];
         foreach ($leadFields as $f) {
             switch ($f->getType()) {
                 case 'boolean':
                     $type = 'bool';
                     break;
                 case 'date':
                     $type = 'date';
                     break;
                 case 'datetime':
                     $type = 'datetime';
                     break;
                 case 'time':
                     $type = 'time';
                     break;
                 case 'url':
                     $type = 'url';
                     break;
                 case 'email':
                     $type = 'email';
                     break;
                 case 'number':
                     $type = 'float';
                     break;
                 default:
                     $type = 'string';
                     break;
             }
             $fieldColumns['l.' . $f->getAlias()] = ['label' => $f->getLabel(), 'type' => $type];
         }
         $filters = $columns = array_merge($columns, $fieldColumns);
         // Append segment filters
         $userSegments = $this->listModel->getUserLists();
         $list = [];
         foreach ($userSegments as $segment) {
             $list[$segment['id']] = $segment['name'];
         }
         $filters['s.leadlist_id'] = ['alias' => 'segment_id', 'label' => 'mautic.core.filter.lists', 'type' => 'select', 'list' => $list, 'operators' => ['eq' => 'mautic.core.operator.equals']];
         $filters['l.owner_id'] = ['label' => 'mautic.lead.list.filter.owner', 'type' => 'select', 'list' => $this->userModel->getRepository()->getUserList('', 0)];
         $data = ['display_name' => 'mautic.lead.leads', 'columns' => $columns, 'filters' => $filters];
         $event->addTable('leads', $data, 'contacts');
         $attributionTypes = ['contact.attribution.multi', 'contact.attribution.first', 'contact.attribution.last'];
         if ($event->checkContext($attributionTypes)) {
             $context = $event->getContext();
             foreach ($attributionTypes as $attributionType) {
                 if (empty($context) || $event->checkContext($attributionType)) {
                     $type = str_replace('contact.attribution.', '', $attributionType);
                     $this->injectAttributionReportData($event, $columns, $type);
                 }
             }
         }
         if ($event->checkContext(['leads', 'lead.pointlog'])) {
             // Add shared graphs
             $event->addGraph('leads', 'line', 'mautic.lead.graph.line.leads');
             if ($event->checkContext('lead.pointlog')) {
                 $this->injectPointsReportData($event, $columns);
             }
         }
     }
 }
コード例 #6
0
 /**
  * Set a widget detail when needed.
  *
  * @param WidgetDetailEvent $event
  */
 public function onWidgetDetailGenerate(WidgetDetailEvent $event)
 {
     $this->checkPermissions($event);
     $canViewOthers = $event->hasPermission('form:forms:viewother');
     if ($event->getType() == 'created.leads.in.time') {
         $widget = $event->getWidget();
         $params = $widget->getParams();
         if (isset($params['flag'])) {
             $params['filter']['flag'] = $params['flag'];
         }
         if (!$event->isCached()) {
             $event->setTemplateData(['chartType' => 'line', 'chartHeight' => $widget->getHeight() - 80, 'chartData' => $this->leadModel->getLeadsLineChartData($params['timeUnit'], $params['dateFrom'], $params['dateTo'], $params['dateFormat'], $params['filter'], $canViewOthers)]);
         }
         $event->setTemplate('MauticCoreBundle:Helper:chart.html.php');
         $event->stopPropagation();
         return;
     }
     if ($event->getType() == 'anonymous.vs.identified.leads') {
         if (!$event->isCached()) {
             $params = $event->getWidget()->getParams();
             $event->setTemplateData(['chartType' => 'pie', 'chartHeight' => $event->getWidget()->getHeight() - 80, 'chartData' => $this->leadModel->getAnonymousVsIdentifiedPieChartData($params['dateFrom'], $params['dateTo'], $canViewOthers)]);
         }
         $event->setTemplate('MauticCoreBundle:Helper:chart.html.php');
         $event->stopPropagation();
         return;
     }
     if ($event->getType() == 'map.of.leads') {
         if (!$event->isCached()) {
             $params = $event->getWidget()->getParams();
             $event->setTemplateData(['height' => $event->getWidget()->getHeight() - 80, 'data' => $this->leadModel->getLeadMapData($params['dateFrom'], $params['dateTo'], $canViewOthers)]);
         }
         $event->setTemplate('MauticCoreBundle:Helper:map.html.php');
         $event->stopPropagation();
         return;
     }
     if ($event->getType() == 'top.lists') {
         if (!$event->isCached()) {
             $params = $event->getWidget()->getParams();
             if (empty($params['limit'])) {
                 // Count the list limit from the widget height
                 $limit = round(($event->getWidget()->getHeight() - 80) / 35 - 1);
             } else {
                 $limit = $params['limit'];
             }
             $lists = $this->leadListModel->getTopLists($limit, $params['dateFrom'], $params['dateTo'], $canViewOthers);
             $items = [];
             // Build table rows with links
             if ($lists) {
                 foreach ($lists as &$list) {
                     $listUrl = $this->router->generate('mautic_segment_action', ['objectAction' => 'edit', 'objectId' => $list['id']]);
                     $row = [['value' => $list['name'], 'type' => 'link', 'link' => $listUrl], ['value' => $list['leads']]];
                     $items[] = $row;
                 }
             }
             $event->setTemplateData(['headItems' => [$event->getTranslator()->trans('mautic.dashboard.label.title'), $event->getTranslator()->trans('mautic.lead.leads')], 'bodyItems' => $items, 'raw' => $lists]);
         }
         $event->setTemplate('MauticCoreBundle:Helper:table.html.php');
         $event->stopPropagation();
         return;
     }
     if ($event->getType() == 'lead.lifetime') {
         $params = $event->getWidget()->getParams();
         if (empty($params['limit'])) {
             // Count the list limit from the widget height
             $limit = round(($event->getWidget()->getHeight() - 80) / 35 - 1);
         } else {
             $limit = $params['limit'];
         }
         $maxSegmentsToshow = 4;
         $params['filter']['flag'] = [];
         if (isset($params['flag'])) {
             $params['filter']['flag'] = $params['flag'];
             $maxSegmentsToshow = count($params['filter']['flag']);
         }
         $lists = $this->leadListModel->getLifeCycleSegments($maxSegmentsToshow, $params['dateFrom'], $params['dateTo'], $canViewOthers, $params['filter']['flag']);
         $items = [];
         if (empty($lists)) {
             $lists[] = ['leads' => 0, 'id' => 0, 'name' => $event->getTranslator()->trans('mautic.lead.all.leads'), 'alias' => ''];
         }
         // Build table rows with links
         if ($lists) {
             $stages = [];
             $deviceGranularity = [];
             foreach ($lists as &$list) {
                 if ($list['alias'] != '') {
                     $listUrl = $this->router->generate('mautic_contact_index', ['search' => 'segment:' . $list['alias']]);
                 } else {
                     $listUrl = $this->router->generate('mautic_contact_index', []);
                 }
                 if ($list['id']) {
                     $params['filter']['leadlist_id'] = ['value' => $list['id'], 'list_column_name' => 't.id'];
                 } else {
                     unset($params['filter']['leadlist_id']);
                 }
                 $column = $this->leadListModel->getLifeCycleSegmentChartData($params['timeUnit'], $params['dateFrom'], $params['dateTo'], $params['dateFormat'], $params['filter'], $canViewOthers, $list['name']);
                 $items['columnName'][] = $list['name'];
                 $items['value'][] = $list['leads'];
                 $items['link'][] = $listUrl;
                 $items['chartItems'][] = $column;
                 $stages[] = $this->leadListModel->getStagesBarChartData($params['timeUnit'], $params['dateFrom'], $params['dateTo'], $params['dateFormat'], $params['filter'], $canViewOthers);
                 $deviceGranularity[] = $this->leadListModel->getDeviceGranularityData($params['timeUnit'], $params['dateFrom'], $params['dateTo'], $params['dateFormat'], $params['filter'], $canViewOthers);
             }
             $width = 100 / count($lists);
             $event->setTemplateData(['columnName' => $items['columnName'], 'value' => $items['value'], 'width' => $width, 'link' => $items['link'], 'chartType' => 'pie', 'chartHeight' => $event->getWidget()->getHeight() - 180, 'chartItems' => $items['chartItems'], 'stages' => $stages, 'devices' => $deviceGranularity]);
             $event->setTemplate('MauticCoreBundle:Helper:lifecycle.html.php');
             $event->stopPropagation();
         }
         return;
     }
     if ($event->getType() == 'top.owners') {
         if (!$canViewOthers) {
             $event->setErrorMessage($this->translator->trans('mautic.dashboard.missing.permission', ['%section%' => $this->bundle]));
             $event->stopPropagation();
             return;
         }
         if (!$event->isCached()) {
             $params = $event->getWidget()->getParams();
             if (empty($params['limit'])) {
                 // Count the list limit from the widget height
                 $limit = round(($event->getWidget()->getHeight() - 80) / 35 - 1);
             } else {
                 $limit = $params['limit'];
             }
             $owners = $this->leadModel->getTopOwners($limit, $params['dateFrom'], $params['dateTo']);
             $items = [];
             // Build table rows with links
             if ($owners) {
                 foreach ($owners as &$owner) {
                     $ownerUrl = $this->router->generate('mautic_user_action', ['objectAction' => 'edit', 'objectId' => $owner['owner_id']]);
                     $row = [['value' => $owner['first_name'] . ' ' . $owner['last_name'], 'type' => 'link', 'link' => $ownerUrl], ['value' => $owner['leads']]];
                     $items[] = $row;
                 }
             }
             $event->setTemplateData(['headItems' => [$event->getTranslator()->trans('mautic.user.account.permissions.editname'), $event->getTranslator()->trans('mautic.lead.leads')], 'bodyItems' => $items, 'raw' => $owners]);
         }
         $event->setTemplate('MauticCoreBundle:Helper:table.html.php');
         $event->stopPropagation();
         return;
     }
     if ($event->getType() == 'top.creators') {
         if (!$canViewOthers) {
             $event->setErrorMessage($this->translator->trans('mautic.dashboard.missing.permission', ['%section%' => $this->bundle]));
             $event->stopPropagation();
             return;
         }
         if (!$event->isCached()) {
             $params = $event->getWidget()->getParams();
             if (empty($params['limit'])) {
                 // Count the list limit from the widget height
                 $limit = round(($event->getWidget()->getHeight() - 80) / 35 - 1);
             } else {
                 $limit = $params['limit'];
             }
             $creators = $this->leadModel->getTopCreators($limit, $params['dateFrom'], $params['dateTo']);
             $items = [];
             // Build table rows with links
             if ($creators) {
                 foreach ($creators as &$creator) {
                     $creatorUrl = $this->router->generate('mautic_user_action', ['objectAction' => 'edit', 'objectId' => $creator['created_by']]);
                     $row = [['value' => $creator['created_by_user'], 'type' => 'link', 'link' => $creatorUrl], ['value' => $creator['leads']]];
                     $items[] = $row;
                 }
             }
             $event->setTemplateData(['headItems' => [$event->getTranslator()->trans('mautic.user.account.permissions.editname'), $event->getTranslator()->trans('mautic.lead.leads')], 'bodyItems' => $items, 'raw' => $creators]);
         }
         $event->setTemplate('MauticCoreBundle:Helper:table.html.php');
         $event->stopPropagation();
         return;
     }
     if ($event->getType() == 'created.leads') {
         if (!$event->isCached()) {
             $params = $event->getWidget()->getParams();
             if (empty($params['limit'])) {
                 // Count the leads limit from the widget height
                 $limit = round(($event->getWidget()->getHeight() - 80) / 35 - 1);
             } else {
                 $limit = $params['limit'];
             }
             $leads = $this->leadModel->getLeadList($limit, $params['dateFrom'], $params['dateTo'], $canViewOthers, [], ['canViewOthers' => $canViewOthers]);
             $items = [];
             if (empty($leads)) {
                 $leads[] = ['name' => $this->translator->trans('mautic.report.report.noresults')];
             }
             // Build table rows with links
             if ($leads) {
                 foreach ($leads as &$lead) {
                     $leadUrl = isset($lead['id']) ? $this->router->generate('mautic_contact_action', ['objectAction' => 'view', 'objectId' => $lead['id']]) : '';
                     $type = isset($lead['id']) ? 'link' : 'text';
                     $row = [['value' => $lead['name'], 'type' => $type, 'link' => $leadUrl]];
                     $items[] = $row;
                 }
             }
             $event->setTemplateData(['headItems' => [$event->getTranslator()->trans('mautic.dashboard.label.title')], 'bodyItems' => $items, 'raw' => $leads]);
         }
         $event->setTemplate('MauticCoreBundle:Helper:table.html.php');
         $event->stopPropagation();
         return;
     }
 }