Skip to content

Commit

Permalink
dev/report/#5 - Fix mailing report unique count issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunil Pawar authored and monishdeb committed Dec 19, 2018
1 parent 76b945c commit 57623a4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,7 @@ public static function &report($id, $skipDetails = FALSE, $isSMS = FALSE) {
'forward',
'reply',
'opened',
'opened_unique',
'optout',
) as $key) {
$url = 'mailing/detail';
Expand Down Expand Up @@ -2235,6 +2236,12 @@ public static function &report($id, $skipDetails = FALSE, $isSMS = FALSE) {
break;

case 'opened':
$url = "mailing/opened";
$searchFilter .= "&mailing_open_status=Y";
$reportFilter .= "&distinct=0"; // do not use group by clause in report, because same report used for total and unique open
break;

case 'opened_unique':
$url = "mailing/opened";
$searchFilter .= "&mailing_open_status=Y";
break;
Expand Down
18 changes: 12 additions & 6 deletions CRM/Report/Form/Mailing/Opened.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,19 @@ public function where() {
}

public function groupBy() {
$groupBys = empty($this->_params['charts']) ? array("civicrm_mailing_event_queue.email_id") : array("{$this->_aliases['civicrm_mailing']}.id");

if (!empty($this->_params['unique_opens_value'])) {
$groupBys[] = "civicrm_mailing_event_queue.id";
$groupBys = array();
// Do not use group by clause if distinct = 0 mentioned in url params. flag is used in mailing report screen, default value is TRUE
// this report is used to show total opened and unique opened
if (CRM_Utils_Request::retrieve('distinct', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, TRUE)) {
$groupBys = empty($this->_params['charts']) ? array("civicrm_mailing_event_queue.email_id") : array("{$this->_aliases['civicrm_mailing']}.id");
if (!empty($this->_params['unique_opens_value'])) {
$groupBys[] = "civicrm_mailing_event_queue.id";
}
}
if (!empty($groupBys)) {
$this->_select = CRM_Contact_BAO_Query::appendAnyValueToSelect($this->_selectClauses, $groupBys);
$this->_groupBy = "GROUP BY " . implode(', ', $groupBys);
}
$this->_select = CRM_Contact_BAO_Query::appendAnyValueToSelect($this->_selectClauses, $groupBys);
$this->_groupBy = "GROUP BY " . implode(', ', $groupBys);
}

public function postProcess() {
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Mailing/Page/Report.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
{if $report.mailing.open_tracking}
<tr><td class="label"><a href="{$report.event_totals.links.opened}&distinct=1">{ts}Unique Opens{/ts}</a></td>
<td>{$report.event_totals.opened} ({$report.event_totals.opened_rate|string_format:"%0.2f"}%)</td>
<td>{$report.event_totals.actionlinks.opened}</td></tr>
<td>{$report.event_totals.actionlinks.opened_unique}</td></tr>
<tr><td class="label"><a href="{$report.event_totals.links.opened}">{ts}Total Opens{/ts}</a></td>
<td>{$report.event_totals.total_opened}</td>
<td>{$report.event_totals.actionlinks.opened}</td></tr>
Expand Down

0 comments on commit 57623a4

Please sign in to comment.