CRM-12274
authoryashodha <yashodha.chaku@webaccess.co.in>
Sat, 20 Apr 2013 20:10:15 +0000 (01:40 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Sat, 20 Apr 2013 20:10:15 +0000 (01:40 +0530)
16 files changed:
CRM/Campaign/BAO/Query.php
CRM/Campaign/BAO/Survey.php
CRM/Case/BAO/Case.php
CRM/Case/Form/Activity.php
CRM/Case/XMLProcessor/Process.php
CRM/Case/XMLProcessor/Report.php
CRM/Contact/BAO/Query.php
CRM/Contact/Form/Search/Custom/ActivitySearch.php
CRM/Contact/Form/Task/PDFLetterCommon.php
CRM/Core/BAO/ActionSchedule.php
CRM/Friend/BAO/Friend.php
CRM/Logging/Differ.php
CRM/Report/Form/Activity.php
CRM/Report/Form/Campaign/SurveyDetails.php
CRM/Report/Form/Contact/Detail.php
CRM/Utils/Migrate/ExportJSON.php

index 3d1359febfcc3978e2d91c01f3544d6909564e24..8e05881dc8f34f41e8a1fb80b5d930b4e1df0a49 100755 (executable)
@@ -204,10 +204,15 @@ class CRM_Campaign_BAO_Query {
       return $from;
     }
 
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+    
     switch ($name) {
       case self::CIVICRM_ACTIVITY_TARGET:
         $from = " INNER JOIN civicrm_activity_contact civicrm_activity_target
-   ON ( civicrm_activity_target.contact_id = contact_a.id AND civicrm_activity_target.record_type = 'Target') ";
+   ON ( civicrm_activity_target.contact_id = contact_a.id AND civicrm_activity_target.record_type_id = $targetID) ";
         break;
 
       case self::CIVICRM_ACTIVITY:
@@ -220,7 +225,7 @@ class CRM_Campaign_BAO_Query {
       case self::CIVICRM_ACTIVITY_ASSIGNMENT:
         $from = "
 INNER JOIN  civicrm_activity_contact civicrm_activity_assignment ON ( civicrm_activity.id = civicrm_activity_assignment.activity_id AND
-civicrm_activity_assignment.record_type = 'Assignee' ) ";
+civicrm_activity_assignment.record_type_id = $assigneeID ) ";
         break;
 
       case 'civicrm_survey':
index 7e9911d9fdbd5a360822be541dd1312ded5c5930..19adda5437c49a168b5207049f3f043d32b31343 100644 (file)
@@ -517,16 +517,19 @@ Group By  contact.id";
     }
 
     $targetContactIds = ' ( ' . implode(',', $voterIds) . ' ) ';
-
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     $query = "
     SELECT  activity.id, activity.status_id,
             activityTarget.contact_id as voter_id,
             activityAssignment.contact_id as interviewer_id
       FROM  civicrm_activity activity
 INNER JOIN  civicrm_activity_contact activityTarget
-  ON ( activityTarget.activity_id = activity.id AND activityTarget.record_type = 'Target')
+  ON ( activityTarget.activity_id = activity.id AND activityTarget.record_type_id = $targetID )
 INNER JOIN  civicrm_activity_contact activityAssignment
-  ON ( activityAssignment.activity_id = activity.id AND activityAssignment.record_type = 'Assignee')
+  ON ( activityAssignment.activity_id = activity.id AND activityAssignment.record_type_id = $assigneeID )
      WHERE  activity.source_record_id = %1
        AND  ( activity.is_deleted IS NULL OR activity.is_deleted = 0 )
        AND  activityAssignment.contact_id = %2
@@ -604,13 +607,17 @@ INNER JOIN  civicrm_activity_contact activityAssignment
             contact_a.display_name as voter_name";
     }
 
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
     $query = "
             $select
       FROM  civicrm_activity activity
 INNER JOIN  civicrm_activity_contact activityTarget
-  ON ( activityTarget.activity_id = activity.id AND activityTarget.record_type = 'Target')
+  ON ( activityTarget.activity_id = activity.id AND activityTarget.record_type_id = $targetID )
 INNER JOIN  civicrm_activity_contact activityAssignment
-  ON ( activityAssignment.activity_id = activity.id AND activityAssignment.record_type = 'Assignee')
+  ON ( activityAssignment.activity_id = activity.id AND activityAssignment.record_type_id = $assigneeID )
 INNER JOIN  civicrm_contact contact_a ON ( activityTarget.contact_id = contact_a.id )
      WHERE  activity.source_record_id = %1
        AND  activity.activity_type_id = %2
@@ -1000,12 +1007,14 @@ INNER JOIN  civicrm_contact contact_a ON ( activityTarget.contact_id = contact_a
     }
 
     $interviewers = array();
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
 
     $query = "
     SELECT  contact.id as id,
             contact.sort_name as sort_name
       FROM  civicrm_contact contact
-INNER JOIN civicrm_activity_contact assignment ON ( assignment.contact_id = contact.id AND record_type = 'Assignee' )
+INNER JOIN civicrm_activity_contact assignment ON ( assignment.contact_id = contact.id AND record_type_id = $assigneeID )
 INNER JOIN  civicrm_activity activity ON ( activity.id = assignment.activity_id )
 INNER JOIN  civicrm_survey survey ON ( activity.source_record_id = survey.id )
             {$whereClause}";
index 8b6e31247c3d459ef5a1f79a9e117994023631b5..a7892ea03ff6b91ba79822856dc2bbbcdcac6762 100644 (file)
@@ -974,6 +974,9 @@ SELECT case_status.label AS case_status, status_id, case_type.label AS case_type
   static function getCaseActivity($caseID, &$params, $contactID, $context = NULL, $userID = NULL, $type = NULL) {
     $values = array();
 
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+
     // CRM-5081 - formatting the dates to omit seconds.
     // Note the 00 in the date format string is needed otherwise later on it thinks scheduled ones are overdue.
     $select = "SELECT count(ca.id) as ismultiple, ca.id as id,
@@ -1005,7 +1008,7 @@ SELECT case_status.label AS case_status, status_id, case_type.label AS case_type
                   LEFT OUTER JOIN civicrm_option_group og ON og.name="activity_status"
                   LEFT OUTER JOIN civicrm_option_value ov ON ov.option_group_id=og.id AND ov.name="Scheduled"
                   LEFT JOIN civicrm_activity_contact caa
-                                ON caa.activity_id = ca.id AND caa.record_type = "Assignee"                  
+                                ON caa.activity_id = ca.id AND caa.record_type_id = $assigneeID                  
                   LEFT JOIN civicrm_contact acc ON acc.id = caa.contact_id  ';
 
     $where = 'WHERE cca.case_id= %1
@@ -2253,7 +2256,12 @@ INNER JOIN  civicrm_case_contact ON ( civicrm_case.id = civicrm_case_contact.cas
 
     $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name');
     $activityStatuses = CRM_Core_PseudoConstant::activityStatus('name');
-
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+    if (isset($params
     $processCaseIds = array($otherCaseId);
     if ($duplicateContacts && !$duplicateCases) {
       if ($changeClient) {
@@ -2401,11 +2409,11 @@ SELECT  id
         //migrate target activities.
         $otherTargetActivity = new CRM_Activity_DAO_ActivityContact();
         $otherTargetActivity->activity_id = $otherActivityId;
-        $otherTargetActivity->record_type = 'Target';
+        $otherTargetActivity->record_type_id = $targetID;
         $otherTargetActivity->find();
         while ($otherTargetActivity->fetch()) {
           $mainActivityTarget = new CRM_Activity_DAO_ActivityContact();
-          $mainActivityTarget->record_type = 'Target';
+          $mainActivityTarget->record_type_id = $targetID;
           $mainActivityTarget->activity_id = $mainActivityId;
           $mainActivityTarget->contact_id = $otherTargetActivity->contact_id;
           if ($mainActivityTarget->contact_id == $otherContactId) {
@@ -2422,12 +2430,12 @@ SELECT  id
         //migrate assignee activities.
         $otherAssigneeActivity = new CRM_Activity_DAO_ActivityContact();
         $otherAssigneeActivity->activity_id = $otherActivityId;
-        $otherAssigneeActivity->record_type = 'Assignee';
+        $otherAssigneeActivity->record_type_id = $assigneeID;
         $otherAssigneeActivity->find();
         while ($otherAssigneeActivity->fetch()) {
           $mainAssigneeActivity = new CRM_Activity_DAO_ActivityContact();
           $mainAssigneeActivity->activity_id = $mainActivityId;
-          $mainAssigneeActivity->record_type = 'Assignee';
+          $mainAssigneeActivity->record_type_id = $assigneeID;
           $mainAssigneeActivity->contact_id = $otherAssigneeActivity->contact_id;
           if ($mainAssigneeActivity->contact_id == $otherContactId) {
             $mainAssigneeActivity->contact_id = $mainContactId;
@@ -2725,7 +2733,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
               $isTarget = $isAssignee = $isSource = FALSE;
 
               $target = new CRM_Activity_DAO_ActivityContact();
-              $target->record_type = 'Target';
+              $target->record_type_id = $targetID;
               $target->activity_id = $activityId;
               $target->contact_id = $contactId;
               if ($target->find(TRUE)) {
@@ -2734,7 +2742,7 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
 
               $assignee = new CRM_Activity_DAO_ActivityContact();
               $assignee->activity_id = $activityId;
-              $assignee->record_type = 'Assignee';
+              $assignee->record_type_id = $assigneeID;
               $assignee->contact_id = $contactId;
               if ($assignee->find(TRUE)) {
                 $isAssignee = TRUE;
index b9a856492c880a9ec211add0e1f6996ec57c385d..393e3acd79fee0a4128ef1cdd5e5ed059feecd29 100644 (file)
@@ -592,11 +592,12 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
     );
     CRM_Case_BAO_Case::processCaseActivity($caseParams);
 
-
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     // create activity assignee records
     $assigneeParams = array(
       'activity_id' => $activity->id,
-      'record_type' => 'Assignee'
+      'record_type_id' => $assigneeID 
     );
 
     if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
index 8a4c8b673aa0225925ddaec45e96d779f654ea2f..9e61115fc2f2cb5e9d82938919e95b2e98a7a3ba 100644 (file)
@@ -253,12 +253,15 @@ class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor {
   }
 
   function deleteEmptyActivity(&$params) {
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     $query = "
 DELETE a
 FROM   civicrm_activity a
 INNER JOIN civicrm_activity_contact t ON t.activity_id = a.id
 WHERE  t.contact_id = %1
-AND    t.record_type = 'Target'
+AND    t.record_type_id = $targetID
 AND    a.is_auto = 1
 AND    a.is_current_revision = 1
 ";
index 69bc3b69b6b5ade15d0ffdd0ae90766112dbb202..cfa5697e330b7fcb6668b4303c3a1bf00366c78b 100644 (file)
@@ -233,13 +233,17 @@ AND    ac.case_id = %1
         $joinCaseActivity = " INNER JOIN civicrm_case_activity ca ON a.id = ca.activity_id ";
       }
 
+      $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+      $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+      $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+      
       $query = "
 SELECT     a.*, aa.contact_id as assigneeID, at.contact_id as targetID
 {$selectCaseActivity}
 FROM       civicrm_activity a
 {$joinCaseActivity}
-LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type = 'Target'
-LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type = 'Assignee'
+LEFT JOIN civicrm_activity_contact at ON a.id = at.activity_id AND at.record_type_id = $targetID
+LEFT JOIN civicrm_activity_contact aa ON a.id = aa.activity_id AND aa.record_type_id = $assigneeID
 WHERE      a.id = %1
     ";
       $params = array(1 => array($activityID, 'Integer'));
index e544a45b26f3bce5c016987653317dbceb14d585..5ec9a352414085fa91a64f9b3433963386fab9c2 100644 (file)
@@ -2698,10 +2698,13 @@ WHERE  id IN ( $groupIDs )
       // search tag in activities
       $etActTable = "`civicrm_entity_act_tag-" . $value . "`";
       $tActTable = "`civicrm_act_tag-" . $value . "`";
+      $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+      $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+      
       $this->_tables[$etActTable] =
         $this->_whereTables[$etActTable] =
         " LEFT JOIN civicrm_activity_contact
-            ON ( civicrm_activity_contact.contact_id = contact_a.id AND civicrm_activity_contact.record_type = 'Target' )
+            ON ( civicrm_activity_contact.contact_id = contact_a.id AND civicrm_activity_contact.record_type_id = {$targetID} )
           LEFT JOIN civicrm_activity
             ON ( civicrm_activity.id = civicrm_activity_contact.activity_id
             AND civicrm_activity.is_deleted = 0 AND civicrm_activity.is_current_revision = 1 )
@@ -2759,6 +2762,9 @@ WHERE  id IN ( $groupIDs )
 
       // search tag in cases
       $etCaseTable = "`civicrm_entity_case_tag-" . $value . "`";
+      $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+      $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
       $this->_tables[$etCaseTable] =
         $this->_whereTables[$etCaseTable] =
         " LEFT JOIN civicrm_case_contact ON civicrm_case_contact.contact_id = contact_a.id
@@ -2771,7 +2777,7 @@ WHERE  id IN ( $groupIDs )
       $this->_tables[$etActTable] =
         $this->_whereTables[$etActTable] =
         " LEFT JOIN civicrm_activity_contact
-            ON ( civicrm_activity_contact.contact_id = contact_a.id AND civicrm_activity_contact.record_type = 'Target' )
+            ON ( civicrm_activity_contact.contact_id = contact_a.id AND civicrm_activity_contact.record_type_id = {$targetID} )
           LEFT JOIN civicrm_activity
             ON ( civicrm_activity.id = civicrm_activity_contact.activity_id
             AND civicrm_activity.is_deleted = 0 AND civicrm_activity.is_current_revision = 1 )
index f652a93e6225a08a4ecc6cd03fa98aab24bc3202..118adb09321e14c935e99341701beebdde3b1206 100644 (file)
@@ -224,6 +224,8 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch implements CRM_Contact_Form_
 
   // Regular JOIN statements here to limit results to contacts who have activities.
   function from() {
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     return "
         civicrm_contact contact_a
             JOIN civicrm_activity activity
@@ -237,7 +239,7 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch implements CRM_Contact_Form_
             LEFT JOIN civicrm_case_activity cca
                  ON activity.id = cca.activity_id
             LEFT JOIN civicrm_activity_contact assignment
-                 ON activity.id = assignment.activity_id AND assignment.record_type = 'Assignee'
+                 ON activity.id = assignment.activity_id AND assignment.record_type_id = {$assigneeID}
             LEFT JOIN civicrm_contact contact_c
                  ON assignment.contact_id = contact_c.id ";
   }
index 74269f0c7d8c5c5b3d6eb2013ed0b4db948aa3cb..e46361cc23bedcc81f754074ab220ae59e659405 100644 (file)
@@ -383,11 +383,14 @@ class CRM_Contact_Form_Task_PDFLetterCommon {
       }
     }
 
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     foreach ($form->_contactIds as $contactId) {
       $activityTargetParams = array(
         'activity_id' => empty($activity->id) ? $activityIds[$contactId] : $activity->id,
         'contact_id' => $contactId,
-        'record_type' => 'Target'
+        'record_type_id' => $targetID
       );
       CRM_Activity_BAO_ActivityContact::create($activityTargetParams);
     }
index 63b06ae9e334d737d8206ca76f3112cbe0fc3cc9..78062b0ed48272c191330f475af6b3522b0fce3a 100755 (executable)
@@ -751,18 +751,23 @@ WHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL
 
       if ($mapping->entity == 'civicrm_activity') {
         $contactField = 'r.contact_id';
+        $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+        $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+        $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+        $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
         switch (CRM_Utils_Array::value($actionSchedule->recipient, $recipientOptions)) {
           case 'Activity Assignees':
-            $join[] =  "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type = 'Assignee'";
+            $join[] =  "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$assigneeID}";
             break;
 
           case 'Activity Source':
-            $join[] =  "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type = 'Source'";  
+            $join[] =  "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$sourceID}";  
             break;
 
           default:
           case 'Activity Targets':
-            $join[] =  "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type = 'Target'";
+            $join[] =  "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$targetID}";
             break;
 
         }
index c33085f20fe2be1eadf63d2cd5b590b7cf780950..5aba88fe1c328e99f2c62c7f32b1cdc776216ed6 100644 (file)
@@ -135,7 +135,9 @@ class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend {
 
     //activity creation
     $activity = CRM_Activity_BAO_Activity::create($activityParams);
-
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     //friend contacts creation
     foreach ($contactParams as $key => $value) {
 
@@ -152,7 +154,7 @@ class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend {
       $targetParams = array(
         'activity_id' => $activity->id,
         'contact_id'  => $contact,
-        'record_type' => 'Target'
+        'record_type_id' => $targetID
       );
 
       // See if it already exists
index 56e941f6aec5e023a0fa4e563abbbb0bb68001b8..49a5452f3d4f8b44e14c28c5ff8876ce355732f0 100644 (file)
@@ -82,10 +82,15 @@ class CRM_Logging_Differ {
         $contactIdClause = "AND (contact_id_a = %3 OR contact_id_b = %3)";
         break;
       case 'civicrm_activity':
+        $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+        $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+        $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+        $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
         $join  = "
-LEFT JOIN civicrm_activity_contact at ON at.activity_id = lt.id AND at.contact_id = %3 AND at.record_type = 'Target'
-LEFT JOIN civicrm_activity_contact aa ON aa.activity_id = lt.id AND aa.contact_id = %3 AND aa.record_type = 'Assignee'
-LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND source.contact_id = %3 AND source.record_type = 'Source' ";
+LEFT JOIN civicrm_activity_contact at ON at.activity_id = lt.id AND at.contact_id = %3 AND at.record_type_id = {$targetID}
+LEFT JOIN civicrm_activity_contact aa ON aa.activity_id = lt.id AND aa.contact_id = %3 AND aa.record_type_id = {$assigneeID}
+LEFT JOIN civicrm_activity_contact source ON source.activity_id = lt.id AND source.contact_id = %3 AND source.record_type_id = {$sourceID} ";
         $contactIdClause = "AND (at.id IS NOT NULL OR aa.id IS NOT NULL OR source.id IS NOT NULL)";
         break;
       case 'civicrm_case':
index 3c2c1b1cbd756f47bbb8a224812a9d377ba6218b..ca85513fdbbd3ff6b91cc77671fcc085fbe8b3f2 100644 (file)
@@ -348,15 +348,19 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
   }
 
   function from() {
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
     $this->_from = "
         FROM civicrm_activity {$this->_aliases['civicrm_activity']}
 
              LEFT JOIN civicrm_activity_contact  {$this->_aliases['civicrm_activity_target']}
                     ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_target']}.activity_id AND 
-                       {$this->_aliases['civicrm_activity_target']}.record_type = 'Target'
+                       {$this->_aliases['civicrm_activity_target']}.record_type_id = {$targetID}
              LEFT JOIN civicrm_activity_contact {$this->_aliases['civicrm_activity_assignment']}
                     ON {$this->_aliases['civicrm_activity']}.id = {$this->_aliases['civicrm_activity_assignment']}.activity_id AND 
-                       {$this->_aliases['civicrm_activity_assignment']}.record_type = 'Assignee' 
+                       {$this->_aliases['civicrm_activity_assignment']}.record_type_id = {$assigneeID} 
              LEFT JOIN civicrm_contact civicrm_contact_source
                     ON {$this->_aliases['civicrm_activity']}.source_contact_id = civicrm_contact_source.id
              LEFT JOIN civicrm_contact contact_civireport
index 5d414a46b9c851a9bdb0def104225dc056a082f3..14197ffe773bdfb6645a178cc748a1c9a9b0a14f 100644 (file)
@@ -313,21 +313,30 @@ class CRM_Report_Form_Campaign_SurveyDetails extends CRM_Report_Form {
 
   function from() {
     $this->_from = " FROM civicrm_contact {$this->_aliases['civicrm_contact']} {$this->_aclFrom} ";
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
 
     //get the activity table joins.
-    $this->_from .= " INNER JOIN civicrm_activity_contact civicrm_activity_target ON ( {$this->_aliases['civicrm_contact']}.id = civicrm_activity_target.contact_id AND civicrm_activity_target.record_type = 'Target') \n";
-    $this->_from .= " INNER JOIN civicrm_activity {$this->_aliases['civicrm_activity']} ON ( {$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id )\n";
-    $this->_from .= " INNER JOIN civicrm_activity_contact civicrm_activity_assignment ON ( {$this->_aliases['civicrm_activity']}.id = civicrm_activity_assignment.activity_id  AND civicrm_activity_assignment.record_type = 'Assignee' )\n";
+    $this->_from .= " INNER JOIN civicrm_activity_contact civicrm_activity_target ON 
+                      ( {$this->_aliases['civicrm_contact']}.id = civicrm_activity_target.contact_id AND civicrm_activity_target.record_type_id = {$targetID}) \n";
+    $this->_from .= " INNER JOIN civicrm_activity {$this->_aliases['civicrm_activity']} ON 
+                      ( {$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id )\n";
+    $this->_from .= " INNER 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} )\n";
 
     //get the address table.
-    $this->_from .= " LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
+    $this->_from .= " LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']} ON 
+                      {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND {$this->_aliases['civicrm_address']}.is_primary = 1\n";
 
     if ($this->_emailField) {
-      $this->_from .= "LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n";
+      $this->_from .= "LEFT JOIN civicrm_email {$this->_aliases['civicrm_email']} ON 
+                       {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND {$this->_aliases['civicrm_email']}.is_primary = 1\n";
     }
 
     if ($this->_phoneField) {
-      $this->_from .= "LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1\n";
+      $this->_from .= "LEFT JOIN civicrm_phone {$this->_aliases['civicrm_phone']} ON 
+                       {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1\n";
     }
 
     if($this->_locationBasedPhoneField){
index 427a6f925d2eb163158486430ebc21ea0f370421..36fa06bc0d08bed38bbb4e50a3c90126bb17ff17 100644 (file)
@@ -471,13 +471,17 @@ class CRM_Report_Form_Contact_Detail extends CRM_Report_Form {
       }
 
       if (CRM_Utils_Array::value('activity_civireport', $this->_selectComponent)) {
+        $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+        $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+        $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+        
         $this->_formComponent['activity_civireport'] = "FROM
                         civicrm_activity {$this->_aliases['civicrm_activity']}
                         LEFT JOIN civicrm_activity_contact civicrm_activity_target ON
                             {$this->_aliases['civicrm_activity']}.id = civicrm_activity_target.activity_id AND
-                            civicrm_activity_target.record_type = 'Target'
+                            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 = 'Assignee'                                  
+                            {$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
                         LEFT JOIN civicrm_contact {$this->_aliases['civicrm_activity_target']} ON
index 72f2cd0e2d6f26af48783a863652526396b02106..e188e461ca10c204bf0dc3b0d46ee704f06730cd 100644 (file)
@@ -373,19 +373,22 @@ AND    entity_table = 'civicrm_contact'
 
   function activity(&$contactIDs, &$additionalContacts) {
     static $_activitiesHandled = array();
-
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     $ids = implode(',', $contactIDs);
 
     $sql = "(
   SELECT     a.*
   FROM       civicrm_activity a
-  INNER JOIN civicrm_activity_contact aa ON aa.activity_id = a.id AND aa.record_type = 'Assignee'
+  INNER JOIN civicrm_activity_contact aa ON aa.activity_id = a.id AND aa.record_type_id = $assigneeID
   WHERE      aa.contact_id IN ( $ids )
     AND      ( a.activity_type_id != 3 AND a.activity_type_id != 20 )
 ) UNION (
   SELECT     a.*
   FROM       civicrm_activity a
-  INNER JOIN civicrm_activity_contact at ON at.activity_id = a.id AND at.record_type = 'Target'  
+  INNER JOIN civicrm_activity_contact at ON at.activity_id = a.id AND at.record_type_id = $targetID  
   WHERE      at.contact_id IN ( $ids )
     AND      ( a.activity_type_id != 3 AND a.activity_type_id != 20 )
 )