From: Ravish Nair Date: Thu, 6 Jun 2013 04:43:59 +0000 (+0530) Subject: -- CRM-12697 cleaned up the usage of removed civicrm_activity column source_contact_id X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ecaec004cc2b2f96257b29bd2f998c3393610a67;p=civicrm-core.git -- CRM-12697 cleaned up the usage of removed civicrm_activity column source_contact_id --- diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 314594ca6f..be6f8be691 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -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, diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 4050d5a7dd..3cfbd0c118 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -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)) { diff --git a/CRM/Contact/Form/Search/Custom/ActivitySearch.php b/CRM/Contact/Form/Search/Custom/ActivitySearch.php index 2c50ebc7e2..cacc8352a9 100644 --- a/CRM/Contact/Form/Search/Custom/ActivitySearch.php +++ b/CRM/Contact/Form/Search/Custom/ActivitySearch.php @@ -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 diff --git a/CRM/Report/Form/Activity.php b/CRM/Report/Form/Activity.php index 2514afa7f9..ea646e294f 100644 --- a/CRM/Report/Form/Activity.php +++ b/CRM/Report/Form/Activity.php @@ -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 diff --git a/CRM/Report/Form/ActivitySummary.php b/CRM/Report/Form/ActivitySummary.php index c7dadeb5ec..02783a824e 100644 --- a/CRM/Report/Form/ActivitySummary.php +++ b/CRM/Report/Form/ActivitySummary.php @@ -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 ) diff --git a/CRM/Report/Form/Case/TimeSpent.php b/CRM/Report/Form/Case/TimeSpent.php index bd6ff58adf..3b4ff1d57e 100644 --- a/CRM/Report/Form/Case/TimeSpent.php +++ b/CRM/Report/Form/Case/TimeSpent.php @@ -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 "; diff --git a/CRM/Report/Form/Contact/Detail.php b/CRM/Report/Form/Contact/Detail.php index b0864385e8..28e0746702 100644 --- a/CRM/Report/Form/Contact/Detail.php +++ b/CRM/Report/Form/Contact/Detail.php @@ -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