Skip to content

Commit

Permalink
Merge pull request #24 from helsingborg-stad/fix/dont-send-empty-emails
Browse files Browse the repository at this point in the history
Fix: Do not send empty emails
  • Loading branch information
sebastianthulin authored Oct 18, 2023
2 parents 08f5cfb + 2e70da4 commit 6040606
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions source/php/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@ public function emailSummary($email, $interval)
if ($this->getCachedResult($interval) !== false) {
$report = $this->getCachedResult($interval);
} else {
$report = self::$resultCache[$interval] = $this->renderReport($from, $to, true);
[$rendered, $hasContent] = $this->renderReport($from, $to, true);
$report = self::$resultCache[$interval] = $rendered;
}

//Send non empty reports
if (!empty($report)) {

if (!empty($report) && !empty($hasContent)) {
$report = '<html><body style="background:#fff;padding: 50px; font-family: Arial, Verdana, sans-serif;">' . $report . '</body></html>';

wp_mail(
$email,
__('Feedback summary', 'customer-feedback') . ' (' . get_option('blogname') . ')',
Expand All @@ -116,7 +115,7 @@ public function emailSummary($email, $interval)
'Content-Type: text/html; charset=UTF-8',
'From: ' . get_option('admin_email')
)
);
);
}
}

Expand Down Expand Up @@ -173,7 +172,7 @@ public function renderReport($from = null, $to = null, $return = false)
}

// Get data from dates
$data = $this->getDataBetween($from, $to);
[$data, $hasContent] = $this->getDataBetween($from, $to);

// Get question
$mainQuestion = __('Did the information on this page help you?', 'customer-feedback');
Expand All @@ -190,7 +189,7 @@ public function renderReport($from = null, $to = null, $return = false)
if ($return) {
ob_start();
include CUSTOMERFEEDBACK_TEMPLATE_PATH . '/summary-view.php';
return ob_get_clean();
return [ob_get_clean(), $hasContent];
} else {
include CUSTOMERFEEDBACK_TEMPLATE_PATH . '/summary-view.php';
}
Expand Down Expand Up @@ -258,7 +257,7 @@ public function getDataBetween($from = null, $to = null)
'pending' => $pending
);

return $data;
return [$data, (!empty($yesno) || !empty($yesnoPercent) || !empty($pending))];
}

/**
Expand Down

0 comments on commit 6040606

Please sign in to comment.