Add count of bounced emails into API response
[MAILPOET-3766]
This commit is contained in:
@ -16,16 +16,27 @@ class NewsletterStatistics {
|
||||
/** @var int */
|
||||
private $unsubscribeCount;
|
||||
|
||||
/** @var int */
|
||||
private $bounceCount;
|
||||
|
||||
/** @var int */
|
||||
private $totalSentCount;
|
||||
|
||||
/** @var WooCommerceRevenue|null */
|
||||
private $wooCommerceRevenue;
|
||||
|
||||
public function __construct($clickCount, $openCount, $unsubscribeCount, $totalSentCount, $wooCommerceRevenue) {
|
||||
public function __construct(
|
||||
$clickCount,
|
||||
$openCount,
|
||||
$unsubscribeCount,
|
||||
$bounceCount,
|
||||
$totalSentCount,
|
||||
$wooCommerceRevenue
|
||||
) {
|
||||
$this->clickCount = $clickCount;
|
||||
$this->openCount = $openCount;
|
||||
$this->unsubscribeCount = $unsubscribeCount;
|
||||
$this->bounceCount = $bounceCount;
|
||||
$this->totalSentCount = $totalSentCount;
|
||||
$this->wooCommerceRevenue = $wooCommerceRevenue;
|
||||
}
|
||||
@ -42,6 +53,10 @@ class NewsletterStatistics {
|
||||
return $this->unsubscribeCount;
|
||||
}
|
||||
|
||||
public function getBounceCount(): int {
|
||||
return $this->unsubscribeCount;
|
||||
}
|
||||
|
||||
public function getTotalSentCount(): int {
|
||||
return $this->totalSentCount;
|
||||
}
|
||||
@ -64,6 +79,7 @@ class NewsletterStatistics {
|
||||
'opened' => $this->openCount,
|
||||
'machineOpened' => $this->machineOpenCount,
|
||||
'unsubscribed' => $this->unsubscribeCount,
|
||||
'bounced' => $this->bounceCount,
|
||||
'revenue' => empty($this->wooCommerceRevenue) ? null : $this->wooCommerceRevenue->asArray(),
|
||||
];
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ namespace MailPoet\Newsletter\Statistics;
|
||||
use MailPoet\Doctrine\Repository;
|
||||
use MailPoet\Entities\NewsletterEntity;
|
||||
use MailPoet\Entities\ScheduledTaskEntity;
|
||||
use MailPoet\Entities\StatisticsBounceEntity;
|
||||
use MailPoet\Entities\StatisticsClickEntity;
|
||||
use MailPoet\Entities\StatisticsOpenEntity;
|
||||
use MailPoet\Entities\StatisticsUnsubscribeEntity;
|
||||
@ -37,6 +38,7 @@ class NewsletterStatisticsRepository extends Repository {
|
||||
$this->getStatisticsClickCount($newsletter),
|
||||
$this->getStatisticsOpenCount($newsletter),
|
||||
$this->getStatisticsUnsubscribeCount($newsletter),
|
||||
$this->getStatisticsBounceCount($newsletter),
|
||||
$this->getTotalSentCount($newsletter),
|
||||
$this->getWooCommerceRevenue($newsletter)
|
||||
);
|
||||
@ -53,6 +55,7 @@ class NewsletterStatisticsRepository extends Repository {
|
||||
$clickCounts = $this->getStatisticCounts(StatisticsClickEntity::class, $newsletters);
|
||||
$openCounts = $this->getStatisticCounts(StatisticsOpenEntity::class, $newsletters);
|
||||
$unsubscribeCounts = $this->getStatisticCounts(StatisticsUnsubscribeEntity::class, $newsletters);
|
||||
$bounceCounts = $this->getStatisticCounts(StatisticsBounceEntity::class, $newsletters);
|
||||
$wooCommerceRevenues = $this->getWooCommerceRevenues($newsletters);
|
||||
|
||||
$statistics = [];
|
||||
@ -62,6 +65,7 @@ class NewsletterStatisticsRepository extends Repository {
|
||||
$clickCounts[$id] ?? 0,
|
||||
$openCounts[$id] ?? 0,
|
||||
$unsubscribeCounts[$id] ?? 0,
|
||||
$bounceCounts[$id] ?? 0,
|
||||
$totalSentCounts[$id] ?? 0,
|
||||
$wooCommerceRevenues[$id] ?? null
|
||||
);
|
||||
@ -100,6 +104,11 @@ class NewsletterStatisticsRepository extends Repository {
|
||||
return $counts[$newsletter->getId()] ?? 0;
|
||||
}
|
||||
|
||||
public function getStatisticsBounceCount(NewsletterEntity $newsletter): int {
|
||||
$counts = $this->getStatisticCounts(StatisticsBounceEntity::class, [$newsletter]);
|
||||
return $counts[$newsletter->getId()] ?? 0;
|
||||
}
|
||||
|
||||
public function getWooCommerceRevenue(NewsletterEntity $newsletter) {
|
||||
$revenues = $this->getWooCommerceRevenues([$newsletter]);
|
||||
return $revenues[$newsletter->getId()] ?? null;
|
||||
|
@ -27,11 +27,12 @@ class NewslettersResponseBuilderTest extends \MailPoetTest {
|
||||
'opened' => 6,
|
||||
'clicked' => 4,
|
||||
'unsubscribed' => 2,
|
||||
'bounced' => 1,
|
||||
'machineOpened' => 9,
|
||||
'revenue' => null,
|
||||
],
|
||||
];
|
||||
$statistics = new NewsletterStatistics(4, 6, 2, 10, null);
|
||||
$statistics = new NewsletterStatistics(4, 6, 2, 1, 10, null);
|
||||
$statistics->setMachineOpenCount(9);
|
||||
$newsletterStatsRepository = Stub::make(NewsletterStatisticsRepository::class, [
|
||||
'getTotalSentCount' => $stats['total_sent'],
|
||||
|
Reference in New Issue
Block a user