/** * 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); } } } }