CRM-17474 Provide additional information on bounce report
authorJKingsnorth <john@johnkingsnorth.co.uk>
Wed, 4 Nov 2015 14:06:40 +0000 (14:06 +0000)
committerJKingsnorth <john@johnkingsnorth.co.uk>
Wed, 4 Nov 2015 14:06:40 +0000 (14:06 +0000)
CRM/Report/Form/Mailing/Bounce.php

index 7d44bbc77e56dad38d2da8352e9a406142208ef0..144c3e7c04d06115fa4938affaf2d7c583d9dfe3 100644 (file)
@@ -29,8 +29,6 @@
  *
  * @package CRM
  * @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
  */
 class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form {
 
@@ -56,8 +54,6 @@ class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form {
     'pieChart' => 'Pie Chart',
   );
 
-  /**
-   */
   /**
    */
   public function __construct() {
@@ -137,9 +133,27 @@ class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form {
         'bounce_reason' => array(
           'title' => ts('Bounce Reason'),
         ),
+        'time_stamp' => array(
+          'title' => ts('Bounce Date'),
+        ),
+      ),
+      'filters' => array(
+        'bounce_reason' => array(
+          'title' => ts('Bounce Reason'),
+        ),
+        'time_stamp' => array(
+          'title' => ts('Bounce Date'),
+          'operatorType' => CRM_Report_Form::OP_DATE,
+          'type' => CRM_Utils_Type::T_DATE,
+        ),
       ),
       'order_bys' => array(
-        'bounce_reason' => array('title' => ts('Bounce Reason')),
+        'bounce_reason' => array(
+          'title' => ts('Bounce Reason')
+        ),
+        'time_stamp' => array(
+          'title' => ts('Bounce Date')
+        ),
       ),
       'grouping' => 'mailing-fields',
     );
@@ -179,6 +193,30 @@ class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form {
           'no_repeat' => TRUE,
           'required' => TRUE,
         ),
+        'on_hold' => array(
+          'title' => ts('On hold'),
+        ),
+        'hold_date' => array(
+          'title' => ts('Hold date'),
+        ),
+        'reset_date' => array(
+          'title' => ts('Hold reset date'),
+        ),
+      ),
+      'filters' => array(
+        'on_hold' => array(
+          'title' => ts('On hold'),
+        ),
+        'hold_date' => array(
+          'title' => ts('Hold date'),
+          'operatorType' => CRM_Report_Form::OP_DATE,
+          'type' => CRM_Utils_Type::T_DATE,
+        ),
+        'reset_date' => array(
+          'title' => ts('Hold reset date'),
+          'operatorType' => CRM_Report_Form::OP_DATE,
+          'type' => CRM_Utils_Type::T_DATE,
+        ),
       ),
       'order_bys' => array(
         'email' => array('title' => ts('Email'), 'default_order' => 'ASC'),
@@ -279,8 +317,46 @@ class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form {
   }
 
   public function where() {
-    parent::where();
-    $this->_where .= " AND {$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
+    
+    $clauses = array();
+    
+    // Exclude SMS mailing type
+    $clauses[] = "{$this->_aliases['civicrm_mailing']}.sms_provider_id IS NULL";
+    
+    // Build date filter clauses
+    foreach ($this->_columns as $tableName => $table) {
+      if (array_key_exists('filters', $table)) {
+        foreach ($table['filters'] as $fieldName => $field) {
+          $clause = NULL;
+          if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
+            $relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
+            $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
+            $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
+
+            $clause = $this->dateClause($this->_aliases[$tableName] . '.' . $field['name'], $relative, $from, $to, $field['type']);
+          }
+          else {
+            $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
+
+            if ($op) {
+              $clause = $this->whereClause($field,
+                $op,
+                CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
+                CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
+                CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
+              );
+            }
+
+          }
+
+          if (!empty($clause)) {
+            $clauses[] = $clause;
+          }
+        }
+      }
+    }
+
+    $this->_where = "WHERE " . implode(' AND ', $clauses);
   }
 
   public function groupBy() {
@@ -360,6 +436,9 @@ class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form {
    *   Rows generated by SQL, with an array for each row.
    */
   public function alterDisplay(&$rows) {
+    
+    $config = CRM_Core_Config::Singleton();
+    
     $entryFound = FALSE;
     foreach ($rows as $rowNum => $row) {
       // make count columns point to detail report
@@ -375,6 +454,28 @@ class CRM_Report_Form_Mailing_Bounce extends CRM_Report_Form {
         $rows[$rowNum]['civicrm_contact_sort_name_hover'] = ts("View Contact details for this contact.");
         $entryFound = TRUE;
       }
+      
+      // Handle on_hold boolean display
+      if (array_key_exists('civicrm_email_on_hold', $row)) {
+        $rows[$rowNum]['civicrm_email_on_hold'] = (!empty($row['civicrm_email_on_hold'])) ? 'Yes' : 'No';
+        $entryFound = TRUE;
+      }
+      
+      // Convert datetime values to custom date and time format
+      $dateFields = array(
+        'civicrm_mailing_event_bounce_time_stamp',
+        'civicrm_email_hold_date',
+        'civicrm_email_reset_date',
+      );
+      
+      foreach($dateFields as $dateField) {
+        if (array_key_exists($dateField, $row)) {
+          if (!empty($rows[$rowNum][$dateField])) {
+            $rows[$rowNum][$dateField] = CRM_Utils_Date::customFormat($row[$dateField], $config->dateformatDatetime);
+          }
+          $entryFound = TRUE;
+        }
+      }
 
       // skip looking further in rows, if first row itself doesn't
       // have the column we need