Fix statistics

[MAILPOET-2503]
This commit is contained in:
Amine Ben hammou
2020-02-03 12:19:15 +01:00
committed by Jack Kitterhing
parent 0069380da6
commit 22b9103460
3 changed files with 29 additions and 5 deletions

View File

@ -59,18 +59,18 @@ class NewslettersResponseBuilder {
$data['options'] = $this->buildOptions($newsletter); $data['options'] = $this->buildOptions($newsletter);
} }
if ($relation === self::RELATION_TOTAL_SENT) { if ($relation === self::RELATION_TOTAL_SENT) {
$data['totalSent'] = $this->newslettersStatsRepository->getTotalSentCount($newsletter); $data['total_sent'] = $this->newslettersStatsRepository->getTotalSentCount($newsletter);
} }
if ($relation === self::RELATION_CHILDREN_COUNT) { if ($relation === self::RELATION_CHILDREN_COUNT) {
$data['childrenCount'] = $this->newslettersStatsRepository->getChildrenCount($newsletter); $data['children_count'] = $this->newslettersStatsRepository->getChildrenCount($newsletter);
} }
if ($relation === self::RELATION_SCHEDULED) { if ($relation === self::RELATION_SCHEDULED) {
$data['totalScheduled'] = (int)SendingQueue::findTaskByNewsletterId($newsletter->getId()) $data['total_scheduled'] = (int)SendingQueue::findTaskByNewsletterId($newsletter->getId())
->where('tasks.status', SendingQueue::STATUS_SCHEDULED) ->where('tasks.status', SendingQueue::STATUS_SCHEDULED)
->count(); ->count();
} }
if ($relation === self::RELATION_STATISTICS) { if ($relation === self::RELATION_STATISTICS) {
$data['statistics'] = $this->newslettersStatsRepository->getStatistics($newsletter); $data['statistics'] = $this->newslettersStatsRepository->getStatistics($newsletter)->asArray();
} }
} }
return $data; return $data;

View File

@ -62,4 +62,16 @@ class NewsletterStatistics {
return $this->wooCommerceRevenue; return $this->wooCommerceRevenue;
} }
/**
* @return array
*/
public function asArray() {
return [
'clicked' => (int)$this->clickCount,
'opened' => (int)$this->openCount,
'unsubscribed' => (int)$this->unsubscribeCount,
'revenue' => empty($this->wooCommerceRevenue) ? null : $this->wooCommerceRevenue->asArray(),
];
}
} }

View File

@ -42,7 +42,19 @@ class NewsletterWooCommerceRevenue {
/** @return string */ /** @return string */
public function getFormattedValue() { public function getFormattedValue() {
return $this->wooCommerceHelper->getRawPrice($this->value, ['currency' => $this->getCurrency()]); return $this->wooCommerceHelper->getRawPrice($this->value, ['currency' => $this->currency]);
}
/**
* @return array
*/
public function asArray() {
return [
'currency' => $this->currency,
'value' => (float)$this->value,
'count' => (int)$this->ordersCount,
'formatted' => $this->getFormattedValue(),
];
} }
} }