-- CRM-12697 cleaned up the usage of removed civicrm_activity column source_contact_id
authorRavish Nair <ravish.nair@webaccess.co.in>
Thu, 6 Jun 2013 04:43:59 +0000 (10:13 +0530)
committerRavish Nair <ravish.nair@webaccess.co.in>
Thu, 6 Jun 2013 04:43:59 +0000 (10:13 +0530)
CRM/Activity/BAO/Activity.php
CRM/Case/BAO/Case.php
CRM/Contact/Form/Search/Custom/ActivitySearch.php
CRM/Report/Form/Activity.php
CRM/Report/Form/ActivitySummary.php
CRM/Report/Form/Case/TimeSpent.php
CRM/Report/Form/Contact/Detail.php

index 314594ca6f1cff5dd893510abf2d0b0ee237598a..be6f8be691be7e7ec3921061061373f62166aa59 100644 (file)
@@ -1084,7 +1084,7 @@ INNER JOIN civicrm_contact contact ON ac.contact_id = contact.id
                 civicrm_activity.activity_date_time,
                 civicrm_activity.status_id,
                 civicrm_activity.subject,
-                civicrm_activity.source_contact_id,
+                ac.contact_id,
                 civicrm_activity.source_record_id,
                 civicrm_option_value.value as activity_type_id,
                 civicrm_option_value.label as activity_type,
index 4050d5a7dd1fe394e8106c54d2b9b40684eaa5b0..3cfbd0c118e5993204a646fa8974e88b1fbe57f8 100644 (file)
@@ -1017,7 +1017,7 @@ SELECT case_status.label AS case_status, status_id, case_type.label AS case_type
                     AND ca.is_current_revision = 1';
 
     if (CRM_Utils_Array::value('reporter_id', $params)) {
-      $where .= " AND ca.source_contact_id = " . CRM_Utils_Type::escape($params['reporter_id'], 'Integer');
+      $where .= " AND cac.contact_id = " . CRM_Utils_Type::escape($params['reporter_id'], 'Integer');
     }
 
     if (CRM_Utils_Array::value('status_id', $params)) {
index 2c50ebc7e282a204be4c7cbea16f760fe3e9ce42..cacc8352a98fba2c1e67f6cfbaa410500040f413 100644 (file)
@@ -226,16 +226,23 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch implements CRM_Contact_Form_
   function from() {
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+    $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+
     return "
-        civicrm_contact contact_a
-            JOIN civicrm_activity activity
-                 ON contact_a.id = activity.source_contact_id
+        civicrm_activity activity
+            LEFT JOIN civicrm_activity_contact target
+                 ON activity.id = target.activity_id AND target.record_type_id = {$targetID}
+            JOIN civicrm_contact contact_a
+                 ON contact_a.id = target.contact_id
             JOIN civicrm_option_value ov1
                  ON activity.activity_type_id = ov1.value AND ov1.option_group_id = 2
             JOIN civicrm_option_value ov2
                  ON activity.status_id = ov2.value AND ov2.option_group_id = {$this->_groupId}
+            LEFT JOIN civicrm_activity_contact sourceContact
+                 ON activity.id = sourceContact.activity_id AND sourceContact.record_type_id = {$sourceID} 
             JOIN civicrm_contact contact_b
-                 ON activity.source_contact_id = contact_b.id
+                 ON sourceContact.contact_id = contact_b.id
             LEFT JOIN civicrm_case_activity cca
                  ON activity.id = cca.activity_id
             LEFT JOIN civicrm_activity_contact assignment
index 2514afa7f9ce450fbc0f5b042bbfb6282ccb997b..ea646e294f0681862a7af24422f3dda98e8a684a 100644 (file)
@@ -364,7 +364,7 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
                        {$this->_aliases['civicrm_activity_assignment']}.record_type_id = {$assigneeID}
              LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']}
                     ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id AND
-                       {$this->_aliases['civicrm_activity_target']}.record_type_id = {$sourceID}
+                       {$this->_aliases['civicrm_activity_source']}.record_type_id = {$sourceID}
              LEFT JOIN civicrm_contact contact_civireport
                     ON {$this->_aliases['civicrm_activity_target']}.contact_id = contact_civireport.id
              LEFT JOIN civicrm_contact civicrm_contact_assignee
index c7dadeb5ec09f004b576d6a683396231d5190d44..02783a824edac93011b012c588a902a599ef159e 100644 (file)
@@ -287,18 +287,29 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
   }
 
   function from() {
+    $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+    $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
 
     $this->_from = "
         FROM civicrm_activity {$this->_aliases['civicrm_activity']}
 
-             LEFT JOIN civicrm_activity_target target_activity
-                    ON {$this->_aliases['civicrm_activity']}.id = target_activity.activity_id
-             LEFT JOIN civicrm_activity_assignment assignment_activity
-                    ON {$this->_aliases['civicrm_activity']}.id = assignment_activity.activity_id
-             LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
-                    ON ({$this->_aliases['civicrm_activity']}.source_contact_id = {$this->_aliases['civicrm_contact']}.id OR
-                         target_activity.target_contact_id = {$this->_aliases['civicrm_contact']}.id                      OR
-                         assignment_activity.assignee_contact_id = {$this->_aliases['civicrm_contact']}.id )
+             LEFT JOIN civicrm_activity_contact target_activity
+                    ON {$this->_aliases['civicrm_activity']}.id = target_activity.activity_id AND
+                       target_activity.record_type_id = {$targetID}
+             LEFT JOIN civicrm_activity_contact assignment_activity
+                    ON {$this->_aliases['civicrm_activity']}.id = assignment_activity.activity_id AND
+                       assignment_activity.record_type_id = {$assigneeID}
+             LEFT JOIN civicrm_activity_contact source_activity
+                    ON {$this->_aliases['civicrm_activity']}.id = source_activity.activity_id AND
+                       source_activity.record_type_id = {$sourceID}
+             LEFT JOIN civicrm_contact contact_civireport
+                    ON target_activity.contact_id = contact_civireport.id
+             LEFT JOIN civicrm_contact civicrm_contact_assignee
+                    ON assignment_activity.contact_id = civicrm_contact_assignee.id
+             LEFT JOIN civicrm_contact civicrm_contact_source
+                    ON source_activity.contact_id = civicrm_contact_source.id
              {$this->_aclFrom}
              LEFT JOIN civicrm_option_value
                     ON ( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value )
index bd6ff58adfb0fa9c5d63024d3e72b9c15bbc8e41..3b4ff1d57eb1dde3e0a74d3305f9e27304c46bf5 100644 (file)
@@ -71,11 +71,6 @@ class CRM_Report_Form_Case_TimeSpent extends CRM_Report_Form {
         'dao' => 'CRM_Activity_DAO_Activity',
         'fields' =>
         array(
-          'source_contact_id' =>
-          array('title' => ts('Contact ID'),
-            'default' => TRUE,
-            'no_display' => TRUE,
-          ),
           'activity_type_id' =>
           array('title' => ts('Activity Type'),
             'default' => TRUE,
@@ -126,14 +121,28 @@ class CRM_Report_Form_Case_TimeSpent extends CRM_Report_Form {
             'options' => $this->activityStatuses,
           ),
         ),
-        'group_bys' =>
+      ),
+      'civicrm_activity_source' =>
         array(
-          'source_contact_id' =>
-          array('title' => ts('Totals Only'),
-            'default' => TRUE,
+          'dao' => 'CRM_Activity_DAO_ActivityContact',
+          'fields' =>
+          array(
+            'contact_id' =>
+            array(
+              'title' => ts('Contact ID'),
+              'default' => TRUE,
+              'no_display' => TRUE,
+            ),
           ),
-        ),
-      ),
+          'group_bys' =>
+          array(
+            'contact_id' =>
+            array('title' => ts('Totals Only'),
+              'default' => TRUE,
+            ),
+          ),
+        'grouping' => 'activity-fields',
+      ), 
       'civicrm_case_activity' =>
       array(
         'dao' => 'CRM_Case_DAO_CaseActivity',
@@ -211,9 +220,10 @@ class CRM_Report_Form_Case_TimeSpent extends CRM_Report_Form {
 
     $this->_from = "
         FROM civicrm_activity {$this->_aliases['civicrm_activity']}
-
+             LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_source']}
+                    ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_source']}.activity_id
              LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
-                    ON {$this->_aliases['civicrm_activity']}.source_contact_id = {$this->_aliases['civicrm_contact']}.id
+                    ON {$this->_aliases['civicrm_activity_source']}.contact_id = {$this->_aliases['civicrm_contact']}.id
              LEFT JOIN civicrm_case_activity {$this->_aliases['civicrm_case_activity']}
                     ON {$this->_aliases['civicrm_case_activity']}.activity_id = {$this->_aliases['civicrm_activity']}.id
 ";
index b0864385e8e1ed7c7f4ab24ae799d7d1326284ab..28e07467026f2c9b4ca4c7a4edde164c0f3a4451 100644 (file)
@@ -278,10 +278,6 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
           array('title' => ts('Subject'),
             'default' => TRUE,
           ),
-          'source_contact_id' =>
-          array('title' => ts('Added By'),
-            'default' => TRUE,
-          ),
           'activity_date_time' =>
           array('title' => ts('Activity Date'),
             'default' => TRUE,
@@ -300,8 +296,9 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
         'dao' => 'CRM_Activity_DAO_ActivityContact',
         'fields' =>
         array(
-          'contact_id' =>
+          'target_contact_id' =>
           array('title' => ts('With Contact'),
+            'name' => 'contact_id',
             'default' => TRUE,
           ),
         ),
@@ -312,13 +309,28 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
         'dao' => 'CRM_Activity_DAO_ActivityContact',
         'fields' =>
         array(
-          'contact_id' =>
+          'assignee_contact_id' =>
           array('title' => ts('Assigned To'),
+            'name' => 'contact_id',
             'default' => TRUE,
           ),
         ),
         'grouping' => 'activity-fields',
       ),
+      'civicrm_activity_source' =>
+        array(
+          'dao' => 'CRM_Activity_DAO_ActivityContact',
+          'fields' =>
+          array(
+            'source_contact_id' =>
+            array(
+              'title' => ts('Added By'),
+              'name' => 'contact_id',
+              'default' => TRUE,
+            ),
+          ),
+        'grouping' => 'activity-fields',
+      ), 
       'civicrm_group' =>
       array(
         'dao' => 'CRM_Contact_DAO_Group',
@@ -370,13 +382,17 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
               $this->_columnHeadersComponent[$table['alias']]["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
             }
             elseif ($table['alias'] == $this->_aliases['civicrm_activity_target'] ||
-              $table['alias'] == $this->_aliases['civicrm_activity_assignment']
+              $table['alias'] == $this->_aliases['civicrm_activity_assignment'] ||
+              $table['alias'] == $this->_aliases['civicrm_activity_source']
             ) {
               if ($table['alias'] == $this->_aliases['civicrm_activity_target']) {
-                $addContactId = 'civicrm_activity_target.contact_id';
+                $addContactId = 'civicrm_activity_target.contact_id as target_contact_id';
+              }
+              elseif ($table['alias'] == $this->_aliases['civicrm_activity_source']) {
+                $addContactId = 'civicrm_activity_source.contact_id';
               }
               else {
-                $addContactId = 'civicrm_activity_assignment.contact_id';
+                $addContactId = 'civicrm_activity_assignment.contact_id as assignee_contact_id';
               }
 
               $tableName = $table['alias'];
@@ -472,6 +488,7 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
         $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
         $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
         $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+        $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
 
         $this->_formComponent['activity_civireport'] = "FROM
                         civicrm_activity {$this->_aliases['civicrm_activity']}
@@ -479,14 +496,17 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
                             {$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id AND
                             civicrm_activity_target.record_type_id = {$targetID}
                         LEFT JOIN civicrm_activity_contact civicrm_activity_assignment ON
-                            {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND                                                                                                                   civicrm_activity_assignment.record_type_id = {$assigneeID}
-                        LEFT JOIN civicrm_contact sourceContact ON
-                            {$this->_aliases['civicrm_activity']}.source_contact_id = sourceContact.id
+                            {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id AND                                                                      civicrm_activity_assignment.record_type_id = {$assigneeID}
+                        LEFT JOIN civicrm_activity_contact civicrm_activity_source
+                            ON {$this->_aliases['civicrm_activity']}.id = civicrm_activity_source.activity_id AND
+                            civicrm_activity_source.record_type_id = {$sourceID} 
                         LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_target']} ON
                             civicrm_activity_target.contact_id = {$this->_aliases['civicrm_activity_target']}.id
 
                         LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_assignment']} ON
                             civicrm_activity_assignment.contact_id = {$this->_aliases['civicrm_activity_assignment']}.id
+                        LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_source']} ON
+                            civicrm_activity_source.contact_id = {$this->_aliases['civicrm_activity_source']}.id
                         LEFT JOIN civicrm_option_value ON
                             ( {$this->_aliases['civicrm_activity']}.activity_type_id = civicrm_option_value.value )
                         LEFT JOIN civicrm_option_group ON
@@ -637,9 +657,9 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
       $val = 'activity_civireport';
       $eligibleResult[$val] = $val;
       $sql = "{$this->_selectComponent[$val]} ,
-                 sourceContact.display_name as added_by {$this->_formComponent[$val]}
+                 {$this->_aliases['civicrm_activity_source']}.display_name as added_by {$this->_formComponent[$val]}
 
-                 WHERE ( {$this->_aliases['civicrm_activity']}.source_contact_id IN ($selectedContacts) OR
+                 WHERE ( civicrm_activity_source.contact_id IN ($selectedContacts) OR
                          civicrm_activity_target.contact_id IN ($selectedContacts) OR
                          civicrm_activity_assignment.contact_id IN ($selectedContacts) OR
                          civicrm_case_contact.contact_id IN ($selectedContacts) ) AND