CRM-16720 : Activity Details report: add source, target and assignee phone number...
authoryashodha <yashodha.chaku@webaccessglobal.com>
Fri, 19 Jun 2015 03:52:31 +0000 (09:22 +0530)
committeryashodha <yashodha.chaku@webaccessglobal.com>
Fri, 19 Jun 2015 03:52:31 +0000 (09:22 +0530)
----------------------------------------
* CRM-16720: Activity Details report: add source, target and assignee phone number columns
  https://issues.civicrm.org/jira/browse/CRM-16720

CRM/Report/Form/Activity.php

index 0766288043f42f269a03b57f341c3ea4bbeec342..12c4199a9831a99506d225dcb96c785776f3c668 100644 (file)
@@ -66,20 +66,20 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
         'fields' => array(
           'contact_source' => array(
             'name' => 'sort_name',
-            'title' => ts('Source Contact Name'),
+            'title' => ts('Source Name'),
             'alias' => 'civicrm_contact_source',
             'no_repeat' => TRUE,
           ),
           'contact_assignee' => array(
             'name' => 'sort_name',
-            'title' => ts('Assignee Contact Name'),
+            'title' => ts('Assignee Name'),
             'alias' => 'civicrm_contact_assignee',
             'dbAlias' => "civicrm_contact_assignee.sort_name",
             'default' => TRUE,
           ),
           'contact_target' => array(
             'name' => 'sort_name',
-            'title' => ts('Target Contact Name'),
+            'title' => ts('Target Name'),
             'alias' => 'civicrm_contact_target',
             'dbAlias' => "civicrm_contact_target.sort_name",
             'default' => TRUE,
@@ -113,21 +113,21 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
           'contact_source' => array(
             'name' => 'sort_name',
             'alias' => 'civicrm_contact_source',
-            'title' => ts('Source Contact Name'),
+            'title' => ts('Source Name'),
             'operator' => 'like',
             'type' => CRM_Report_Form::OP_STRING,
           ),
           'contact_assignee' => array(
             'name' => 'sort_name',
             'alias' => 'civicrm_contact_assignee',
-            'title' => ts('Assignee Contact Name'),
+            'title' => ts('Assignee Name'),
             'operator' => 'like',
             'type' => CRM_Report_Form::OP_STRING,
           ),
           'contact_target' => array(
             'name' => 'sort_name',
             'alias' => 'civicrm_contact_target',
-            'title' => ts('Target Contact Name'),
+            'title' => ts('Target Name'),
             'operator' => 'like',
             'type' => CRM_Report_Form::OP_STRING,
           ),
@@ -146,28 +146,48 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
         'fields' => array(
           'contact_source_email' => array(
             'name' => 'email',
-            'title' => ts('Source Contact Email'),
+            'title' => ts('Source Email'),
             'alias' => 'civicrm_email_source',
           ),
           'contact_assignee_email' => array(
             'name' => 'email',
-            'title' => ts('Assignee Contact Email'),
+            'title' => ts('Assignee Email'),
             'alias' => 'civicrm_email_assignee',
           ),
           'contact_target_email' => array(
             'name' => 'email',
-            'title' => ts('Target Contact Email'),
+            'title' => ts('Target Email'),
             'alias' => 'civicrm_email_target',
           ),
         ),
         'order_bys' => array(
           'source_contact_email' => array(
             'name' => 'email',
-            'title' => ts('Source Contact Email'),
+            'title' => ts('Source Email'),
             'dbAlias' => 'civicrm_email_contact_source_email',
           ),
         ),
       ),
+      'civicrm_phone' => array(
+        'dao' => 'CRM_Core_DAO_Phone',
+        'fields' => array(
+          'contact_source_phone' => array(
+            'name' => 'phone',
+            'title' => ts('Source Phone'),
+            'alias' => 'civicrm_phone_source',
+          ),
+          'contact_assignee_phone' => array(
+            'name' => 'phone',
+            'title' => ts('Assignee Phone'),
+            'alias' => 'civicrm_phone_assignee',
+          ),
+          'contact_target_phone' => array(
+            'name' => 'phone',
+               'title' => ts('Target Phone'),
+            'alias' => 'civicrm_phone_target',
+          ),
+        ),
+      ),
       'civicrm_activity' => array(
         'dao' => 'CRM_Activity_DAO_Activity',
         'fields' => array(
@@ -388,7 +408,9 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
         if (strstr($clause, 'civicrm_contact_assignee.') ||
           strstr($clause, 'civicrm_contact_source.') ||
           strstr($clause, 'civicrm_email_assignee.') ||
-          strstr($clause, 'civicrm_email_source.')
+          strstr($clause, 'civicrm_email_source.') ||
+          strstr($clause, 'civicrm_phone_assignee.') ||
+          strstr($clause, 'civicrm_phone_source.')
         ) {
           $removeKeys[] = $key;
           unset($this->_selectClauses[$key]);
@@ -400,7 +422,9 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
         if (strstr($clause, 'civicrm_contact_target.') ||
           strstr($clause, 'civicrm_contact_source.') ||
           strstr($clause, 'civicrm_email_target.') ||
-          strstr($clause, 'civicrm_email_source.')
+          strstr($clause, 'civicrm_email_source.') ||
+          strstr($clause, 'civicrm_phone_target.') ||
+          strstr($clause, 'civicrm_phone_source.')
         ) {
           $removeKeys[] = $key;
           unset($this->_selectClauses[$key]);
@@ -412,7 +436,9 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
         if (strstr($clause, 'civicrm_contact_target.') ||
           strstr($clause, 'civicrm_contact_assignee.') ||
           strstr($clause, 'civicrm_email_target.') ||
-          strstr($clause, 'civicrm_email_assignee.')
+          strstr($clause, 'civicrm_email_assignee.') ||
+          strstr($clause, 'civicrm_phone_target.') ||
+          strstr($clause, 'civicrm_phone_assignee.')
         ) {
           $removeKeys[] = $key;
           unset($this->_selectClauses[$key]);
@@ -424,9 +450,15 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
       foreach ($this->_selectClauses as $key => $clause) {
         if (strstr($clause, 'civicrm_contact_contact_target') ||
           strstr($clause, 'civicrm_contact_contact_assignee') ||
-          strstr($clause, 'civicrm_contact_contact_source')
+          strstr($clause, 'civicrm_contact_contact_source') ||
+          strstr($clause, 'civicrm_phone_contact_source_phone') ||
+          strstr($clause, 'civicrm_phone_contact_assignee_phone') ||
+          strstr($clause, 'civicrm_email_contact_source_email') ||
+          strstr($clause, 'civicrm_email_contact_assignee_email') ||
+          strstr($clause, 'civicrm_email_contact_target_email') ||
+          strstr($clause, 'civicrm_phone_contact_target_phone')
         ) {
-          $this->_selectClauses[$key] = "GROUP_CONCAT($clause SEPARATOR ';') as $clause";
+          $this->_selectClauses[$key] = "GROUP_CONCAT($clause SEPARATOR '; ') as $clause";
         }
       }
     }
@@ -478,6 +510,13 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
                    ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_email_target.contact_id AND
                       civicrm_email_target.is_primary = 1";
       }
+
+      if ($this->isTableSelected('civicrm_phone')) {
+        $this->_from .= "
+            LEFT JOIN civicrm_phone civicrm_phone_target
+                   ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_phone_target.contact_id AND
+                      civicrm_phone_target.is_primary = 1 ";
+      }
       $this->_aliases['civicrm_contact'] = 'civicrm_contact_target';
     }
 
@@ -497,6 +536,12 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
                    ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_email_assignee.contact_id AND
                       civicrm_email_assignee.is_primary = 1";
       }
+      if ($this->isTableSelected('civicrm_phone')) {
+        $this->_from .= "
+            LEFT JOIN civicrm_phone civicrm_phone_assignee
+                   ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_phone_assignee.contact_id AND
+                      civicrm_phone_assignee.is_primary = 1 ";
+      }
       $this->_aliases['civicrm_contact'] = 'civicrm_contact_assignee';
     }
 
@@ -516,9 +561,15 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
                    ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_email_source.contact_id AND
                       civicrm_email_source.is_primary = 1";
       }
+      if ($this->isTableSelected('civicrm_phone')) {
+        $this->_from .= "
+            LEFT JOIN civicrm_phone civicrm_phone_source
+                   ON {$this->_aliases['civicrm_activity_contact']}.contact_id = civicrm_phone_source.contact_id AND
+                      civicrm_phone_source.is_primary = 1 ";
+      }
       $this->_aliases['civicrm_contact'] = 'civicrm_contact_source';
     }
-    $this->_from .= "INNER JOIN civicrm_option_value {$this->_aliases['civicrm_option_value']}
+    $this->_from .= " INNER JOIN civicrm_option_value {$this->_aliases['civicrm_option_value']}
             ON {$this->_aliases['civicrm_option_value']}.option_group_id = {$activityTypeId}
             AND {$this->_aliases['civicrm_option_value']}.value = {$this->_aliases['civicrm_activity']}.activity_type_id";
     $this->addAddressFromClause();
@@ -728,6 +779,8 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}";
   ADD COLUMN civicrm_contact_contact_source VARCHAR(128),
   ADD COLUMN civicrm_contact_contact_assignee_id VARCHAR(128),
   ADD COLUMN civicrm_contact_contact_source_id VARCHAR(128),
+  ADD COLUMN civicrm_phone_contact_assignee_phone VARCHAR(128),
+  ADD COLUMN civicrm_phone_contact_source_phone VARCHAR(128),
   ADD COLUMN civicrm_email_contact_assignee_email VARCHAR(128),
   ADD COLUMN civicrm_email_contact_source_email VARCHAR(128)";
     CRM_Core_DAO::executeQuery($tempQuery);
@@ -802,7 +855,6 @@ GROUP BY civicrm_activity_id {$this->_having} {$this->_orderBy} {$this->_limit}"
       $onHover = ts('View Contact Summary for this Contact');
       $onHoverAct = ts('View Activity Record');
     }
-
     foreach ($rows as $rowNum => $row) {
       // if we have an activity type, format the View Activity link for use in various columns
       if ($viewLinks &&