diff --git a/Assets/img/icon.png b/Assets/img/icon.png new file mode 100644 index 0000000..af39121 Binary files /dev/null and b/Assets/img/icon.png differ diff --git a/Command/SourceCreatedMigrationCommand.php b/Command/SourceCreatedMigrationCommand.php new file mode 100644 index 0000000..b9e3b2e --- /dev/null +++ b/Command/SourceCreatedMigrationCommand.php @@ -0,0 +1,87 @@ +entityManager = $entityManager; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('mautic:source:created:cotnacts:migration') + ->setDescription('Created contacts source migration') + ->setHelp('Created contacts source migration'); + + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $key = __CLASS__; + if (!$this->checkRunStatus($input, $output, $key)) { + return 0; + } + + $maxIdQuery = 'SELECT MAX(ccl.log_id) FROM '.MAUTIC_TABLE_PREFIX.'custom_contact_log ccl'; + $maxLogId = (int) $this->entityManager->getConnection()->query($maxIdQuery)->fetchColumn(); + + $countQuery = 'SELECT COUNT(lel.id) FROM '.$this->getLeadEventLogQueryPart().' AND lel.id > '.$maxLogId; + $numberOfImportedRows = $this->entityManager->getConnection()->query($countQuery)->fetchColumn(); + + $query = 'INSERT INTO '.MAUTIC_TABLE_PREFIX.'custom_contact_log (lead_id, log_id, url, date_added) +SELECT lel.lead_id, lel.id,ph.url,lel.date_added FROM '.$this->getLeadEventLogQueryPart(); + if ($maxLogId) { + $query.= ' AND lel.id > '.$maxLogId; + } + $this->entityManager->getConnection()->query($query); + + $output->writeln(sprintf("Migrated %s lines", $numberOfImportedRows)); + } + + /** + * @return string + */ + private function getLeadEventLogQueryPart() + { + return MAUTIC_TABLE_PREFIX.'lead_event_log lel + LEFT JOIN '.MAUTIC_TABLE_PREFIX.'page_hits ph ON ph.id = lel.object_id +WHERE lel.bundle = \'page\' and lel.object = \'hit\' AND lel.action = \'created_contact\''; + } +} diff --git a/Config/config.php b/Config/config.php new file mode 100644 index 0000000..1fb1329 --- /dev/null +++ b/Config/config.php @@ -0,0 +1,50 @@ + 'MauticCustomReportBundle', + 'description' => 'Custom reports for Mautic', + 'version' => '1.0', + 'author' => 'MTCExtendee', + + 'routes' => [ + ], + + 'services' => [ + 'events'=>[ + 'mautic.customreport.created_contact' => [ + 'class' => \MauticPlugin\MauticCustomReportBundle\EventListener\SourceCreatedContactReportSubscriber::class, + 'arguments' => [ + 'mautic.lead.reportbundle.fields_builder', + ], + ], + ], + 'forms' => [ + ], + 'models' => [ + + ], + 'integrations' => [ + 'mautic.integration.customreport' => [ + 'class' => \MauticPlugin\MauticCustomReportBundle\Integration\CustomReportIntegration::class, + 'arguments' => [ + ], + ], + ], + 'others' => [ + + ], + 'controllers' => [ + ], + 'commands'=>[ + 'mautic.customreport.command' => [ + 'class' => \MauticPlugin\MauticCustomReportBundle\Command\SourceCreatedMigrationCommand::class, + 'arguments' => [ + 'doctrine.orm.entity_manager' + ], + 'tag' => 'console.command', + ], + ] + ], + 'parameters' => [ + ], +]; diff --git a/EventListener/SourceCreatedContactReportSubscriber.php b/EventListener/SourceCreatedContactReportSubscriber.php new file mode 100644 index 0000000..40e0eb7 --- /dev/null +++ b/EventListener/SourceCreatedContactReportSubscriber.php @@ -0,0 +1,121 @@ +fieldsBuilder = $fieldsBuilder; + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return [ + ReportEvents::REPORT_ON_BUILD => ['onReportBuilder', 0], + ReportEvents::REPORT_ON_GENERATE => ['onReportGenerate', 0], + ]; + } + + /** + * Add available tables and columns to the report builder lookup. + * + * @param ReportBuilderEvent $event + */ + public function onReportBuilder(ReportBuilderEvent $event) + { + if (!$event->checkContext([self::SOURCE_CREATED_CONTACT])) { + return; + } + + $columns = $this->fieldsBuilder->getLeadFieldsColumns('l.'); + + + $addColumns = [ + 'ccl.url' => [ + 'label' => 'mautic.customreport.report.source.created_contact', + 'type' => 'string', + ], + 'ccl.date_added' => [ + 'label' => 'mautic.customreport.report.date_added', + 'type' => 'datetime', + ], + 'hits' => [ + 'formula'=>'(SELECT COUNT(ccl2.url) FROM '.MAUTIC_TABLE_PREFIX.'custom_contact_log ccl2 +INNER JOIN '.MAUTIC_TABLE_PREFIX.'leads l ON l.id = ccl2.lead_id AND l.email IS NOT NULL +WHERE ccl2.date_added BETWEEN :dateFrom AND :dateTo AND ccl2.url = ccl.url)', + 'label' => 'mautic.customreport.report.hits', + 'type' => 'int', + ], + ]; + + $data = [ + 'display_name' => 'mautic.customreport.report.source.created_contact', + 'columns' => array_merge($columns, $addColumns), + 'filters' => $columns, + ]; + $event->addTable(self::SOURCE_CREATED_CONTACT, $data, ReportSubscriber::GROUP_CONTACTS); + + unset($columns, $filters, $columns, $data); + } + + /** + * Initialize the QueryBuilder object to generate reports from. + * + * @param ReportGeneratorEvent $event + */ + public function onReportGenerate(ReportGeneratorEvent $event) + { + if (!$event->checkContext([self::SOURCE_CREATED_CONTACT])) { + return; + } + + $qb = $event->getQueryBuilder(); + $qb->from(MAUTIC_TABLE_PREFIX.'custom_contact_log', 'ccl'); + $qb->innerJoin('ccl',MAUTIC_TABLE_PREFIX.'leads', 'l', 'l.id = ccl.lead_id AND l.email IS NOT NULL'); + + + if (empty($event->getReport()->getGroupBy())) { + $qb->addGroupBy('ccl.url'); + $qb->addGroupBy('l.id'); + } + + if (empty($event->getReport()->getOrderColumns())) { + $qb->addOrderBy('hits1','DESC'); + $qb->addOrderBy('l.points','DESC'); + } + + $event->applyDateFilters($qb, 'date_added', 'ccl'); + + $event->setQueryBuilder($qb); + } +} diff --git a/Integration/CustomReportIntegration.php b/Integration/CustomReportIntegration.php new file mode 100644 index 0000000..401a61c --- /dev/null +++ b/Integration/CustomReportIntegration.php @@ -0,0 +1,43 @@ +Icons made by Pause08 \ No newline at end of file