dev/report/#5 - Fix mailing report unique count issue
authorSunil Pawar <sunil@cividesk.com>
Mon, 2 Jul 2018 15:40:02 +0000 (21:10 +0530)
committerMonish Deb <deb.monish@gmail.com>
Wed, 19 Dec 2018 13:43:03 +0000 (19:13 +0530)
CRM/Mailing/BAO/Mailing.php
CRM/Report/Form/Mailing/Opened.php
templates/CRM/Mailing/Page/Report.tpl

index b0583b56eb8b11345ae8feaa2c6661941befbe80..03f6afb4d0dcb5e31f04e552315bc073aafe8a9e 100644 (file)
@@ -2198,6 +2198,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
                'forward',
                'reply',
                'opened',
+               'opened_unique',
                'optout',
              ) as $key) {
       $url = 'mailing/detail';
@@ -2235,6 +2236,12 @@ ORDER BY   civicrm_email.is_bulkmail DESC
           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;
index e893b75fc86adb05c710e6f314f830725e22658e..98ba274137278b38499de03b29dd42ac7d593fa3 100644 (file)
@@ -289,13 +289,19 @@ class CRM_Report_Form_Mailing_Opened extends CRM_Report_Form {
   }
 
   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() {
index 0767df8c743f071dd0a3508519f3b9c6cd97e1a1..9c95b3604692bb363d02717d89fba9a9c448a870 100644 (file)
@@ -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>