Skip to content

Commit

Permalink
Bugfixing mail type stats view when no stats are present yet
Browse files Browse the repository at this point in the history
  • Loading branch information
rootpd committed May 7, 2019
1 parent 23c8d41 commit b417af8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Mailer/app/models/Repositories/MailTypeStatsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getDashboardDataGroupedByTypes(DateTime $from, DateTime $to)
public function getDashboardDetailData($id, DateTime $from, DateTime $to)
{
return $this->getTable()
->select('mail_type_id, SUM(subscribers_count) AS count, DATE(created_at) AS created_date')
->select('SUM(subscribers_count) AS count, DATE(created_at) AS created_date')
->where('id IN (
SELECT MAX(id) FROM mail_type_stats
WHERE mail_type_id = ?
Expand Down
9 changes: 5 additions & 4 deletions Mailer/app/presenters/ListPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function renderShow($id)

$week = new DateTime('-7 days');
$month = new DateTime('-30 days');

$this->template->stats = [
'subscribed' => $list->related('mail_user_subscriptions')
->where(['subscribed' => true])
Expand All @@ -163,21 +164,21 @@ public function renderShow($id)
'7-days' => $this->mailTemplateStatsRepository->byMailTypeId($list->id)
->where('date > DATE(?)', $week)
->select('SUM(mail_template_stats.opened) AS opened')
->fetch()->opened,
->fetch()->opened ?? 0,
'30-days' => $this->mailTemplateStatsRepository->byMailTypeId($list->id)
->where('date > DATE(?)', $month)
->select('SUM(mail_template_stats.opened) AS opened')
->fetch()->opened,
->fetch()->opened ?? 0,
],
'clicked' => [
'7-days' => $this->mailTemplateStatsRepository->byMailTypeId($list->id)
->where('date > DATE(?)', $week)
->select('SUM(mail_template_stats.clicked) AS opened')
->fetch()->opened,
->fetch()->opened ?? 0,
'30-days' => $this->mailTemplateStatsRepository->byMailTypeId($list->id)
->where('date > DATE(?)', $month)
->select('SUM(mail_template_stats.clicked) AS opened')
->fetch()->opened,
->fetch()->opened ?? 0,
]
];

Expand Down

0 comments on commit b417af8

Please sign in to comment.