Merge pull request #2033 from JoeMurray/master
[civicrm-core.git] / CRM / Report / Form / Mailing / Summary.php
index 9ed06252f016eae5afc482bf2116f6eaa6a2c487..c5fdc8f437637cd55819c4afa433482669af6702 100644 (file)
@@ -2,7 +2,7 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -51,6 +51,8 @@ class CRM_Report_Form_Mailing_Summary extends CRM_Report_Form {
     'bar_3dChart' => 'Bar Chart',
   );
 
+  public $campaignEnabled = False;
+
   function __construct() {
     $this->_columns = array();
 
@@ -64,6 +66,9 @@ class CRM_Report_Form_Mailing_Summary extends CRM_Report_Form {
         'created_date' => array(
           'title' => ts('Date Created'),
         ),
+        'subject' => array(
+          'title' => ts('Subject'),
+        ),
       ),
       'filters' => array(
         'is_completed' => array(
@@ -89,7 +94,7 @@ class CRM_Report_Form_Mailing_Summary extends CRM_Report_Form {
     );
 
     $this->_columns['civicrm_mailing_job'] = array(
-      'dao' => 'CRM_Mailing_DAO_Job',
+      'dao' => 'CRM_Mailing_DAO_MailingJob',
       'fields' => array(
         'start_date' => array(
           'title' => ts('Start Date'),
@@ -225,7 +230,23 @@ class CRM_Report_Form_Mailing_Summary extends CRM_Report_Form {
         ),
       ),
     );
-
+    $config = CRM_Core_Config::singleton();
+    $this->campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
+    if ($this->campaignEnabled) {
+      $this->_columns['civicrm_campaign'] = array(
+        'dao' => 'CRM_Campaign_DAO_Campaign',
+        'fields' => array(
+          'title' => array(
+            'title' => ts('Campaign Name'),
+          ),
+        ),
+        'filters' => array(
+          'title' => array(
+            'type' => CRM_Utils_Type::T_STRING,
+          ),
+        ),
+      );
+    }
     parent::__construct();
   }
 
@@ -322,6 +343,13 @@ class CRM_Report_Form_Mailing_Summary extends CRM_Report_Form {
         ON {$this->_aliases['civicrm_mailing_event_trackable_url_open']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id
       LEFT JOIN civicrm_mailing_event_unsubscribe {$this->_aliases['civicrm_mailing_event_unsubscribe']}
         ON {$this->_aliases['civicrm_mailing_event_unsubscribe']}.event_queue_id = {$this->_aliases['civicrm_mailing_event_queue']}.id";
+
+    if ($this->campaignEnabled) {
+      $this->_from .= "
+        LEFT JOIN civicrm_campaign {$this->_aliases['civicrm_campaign']}
+        ON {$this->_aliases['civicrm_campaign']}.id = {$this->_aliases['civicrm_mailing']}.campaign_id";
+    }
+
     // need group by and order by
 
     //print_r($this->_from);
@@ -341,7 +369,7 @@ class CRM_Report_Form_Mailing_Summary extends CRM_Report_Form {
             $from     = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
             $to       = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
 
-            $clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
+            $clause = $this->dateClause($this->_aliases[$tableName] . '.' . $field['name'], $relative, $from, $to, $field['type']);
           }
           else {
             $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);