From 6c630dc0e113ad8434c055573cc4e8e2a44ea44c Mon Sep 17 00:00:00 2001 From: Ondrej Sibl Date: Wed, 7 Aug 2019 14:52:50 +0200 Subject: [PATCH] Report not showing properly clicks for multiple emails --- .../EventListener/ReportSubscriber.php | 4 +-- app/bundles/ReportBundle/Entity/Report.php | 25 +++++++++++++++++++ .../Event/ReportGeneratorEvent.php | 14 +++++++++++ .../ReportBundle/Model/ReportModel.php | 3 +++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/bundles/EmailBundle/EventListener/ReportSubscriber.php b/app/bundles/EmailBundle/EventListener/ReportSubscriber.php index 4c72c9f1979..7cfee9c8acb 100644 --- a/app/bundles/EmailBundle/EventListener/ReportSubscriber.php +++ b/app/bundles/EmailBundle/EventListener/ReportSubscriber.php @@ -376,8 +376,8 @@ public function onReportGenerate(ReportGeneratorEvent $event) if ($event->hasFilter('e.id')) { $filterParam = $event->createParameterName(); - $qbcut->andWhere("cut2.channel_id = :{$filterParam}"); - $qb->setParameter($filterParam, $event->getFilterValue('e.id'), \PDO::PARAM_INT); + $qbcut->andWhere($qb->expr()->in('cut2.channel_id', ":{$filterParam}")); + $qb->setParameter($filterParam, $event->getFilterValues('e.id'), Connection::PARAM_INT_ARRAY); } $qb->leftJoin( diff --git a/app/bundles/ReportBundle/Entity/Report.php b/app/bundles/ReportBundle/Entity/Report.php index 5def6fa46f3..b2bcf5e6827 100644 --- a/app/bundles/ReportBundle/Entity/Report.php +++ b/app/bundles/ReportBundle/Entity/Report.php @@ -384,6 +384,31 @@ public function getFilterValue($column) throw new \UnexpectedValueException("Column {$column} doesn't have any filter."); } + /** + * Get filter values from a specific filter. + * + * @param string $column + * + * @return array + * + * @throws \UnexpectedValueException + */ + public function getFilterValues($column) + { + $values = []; + foreach ($this->getFilters() as $field) { + if ($column === $field['column']) { + $values[] = $field['value']; + } + } + + if (empty($values)) { + throw new \UnexpectedValueException("Column {$column} doesn't have any filter."); + } + + return $values; + } + /** * @return mixed */ diff --git a/app/bundles/ReportBundle/Event/ReportGeneratorEvent.php b/app/bundles/ReportBundle/Event/ReportGeneratorEvent.php index 9c1f08684b7..42184953ec1 100644 --- a/app/bundles/ReportBundle/Event/ReportGeneratorEvent.php +++ b/app/bundles/ReportBundle/Event/ReportGeneratorEvent.php @@ -447,6 +447,20 @@ public function getFilterValue($column) return $this->getReport()->getFilterValue($column); } + /** + * Get filter values from a specific filter. + * + * @param string $column + * + * @return array + * + * @throws \UnexpectedValueException + */ + public function getFilterValues($column) + { + return $this->getReport()->getFilterValues($column); + } + /** * Check if the report has a groupBy columns selected. * diff --git a/app/bundles/ReportBundle/Model/ReportModel.php b/app/bundles/ReportBundle/Model/ReportModel.php index b45b3c62ee0..642f428e26d 100644 --- a/app/bundles/ReportBundle/Model/ReportModel.php +++ b/app/bundles/ReportBundle/Model/ReportModel.php @@ -689,6 +689,9 @@ public function getReportData(Report $entity, FormFactoryInterface $formFactory $params = $query->getParameters(); foreach ($params as $name => $param) { + if (is_array($param)) { + $param = implode("','", $param); + } $debugData['query'] = str_replace(":$name", "'$param'", $debugData['query']); }