CRM-12697
authoryashodha <yashodha.chaku@webaccess.co.in>
Wed, 29 May 2013 06:21:10 +0000 (11:51 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Wed, 29 May 2013 09:32:00 +0000 (15:02 +0530)
CRM/Activity/Form/Task.php
CRM/Activity/Form/Task/Batch.php

index dbe9b619423abf4ecddd5065c1a9bc74e4207772..7673b06f8ad234875095df9c551f7a4eb72d0e8d 100644 (file)
@@ -151,14 +151,18 @@ class CRM_Activity_Form_Task extends CRM_Core_Form {
    */
   public function setContactIDs() {
     $IDs = implode(',', $this->_activityHolderIds);
+
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
     $query = "
-SELECT source_contact_id
-  FROM civicrm_activity
- WHERE id IN ( $IDs )
-";
+SELECT contact_id
+FROM   civicrm_activity_contact
+WHERE  activity_id IN ( $IDs ) AND
+       record_type_id = {$sourceID}";
+
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
-      $contactIDs[] = $dao->source_contact_id;
+      $contactIDs[] = $dao->contact_id;
     }
     $this->_contactIds = $contactIDs;
   }
index 6a41ef7963497f04595594c0e1ae935739f122ac..37d95262d0894295beecf3721e5e0ad41d315fef 100755 (executable)
@@ -257,10 +257,14 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
         }
 
         $query = "
-SELECT activity_type_id , source_contact_id
-FROM   civicrm_activity
-WHERE  id = %1";
-        $params = array(1 => array($key, 'Integer'));
+SELECT a.activity_type_id, ac.contact_id
+FROM   civicrm_activity a
+JOIN   civicrm_activity_contact ac ON ( ac.activity_id = a.id
+AND    ac.record_type_id = %2 )
+WHERE  a.id = %1 ";
+        $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+        $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+        $params = array(1 => array($key, 'Integer'), 2 => array($sourceID, 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($query, $params);
         $dao->fetch();
 
@@ -268,7 +272,7 @@ WHERE  id = %1";
         $value['activity_type_id'] = $dao->activity_type_id;
 
         // Get Conatct ID
-        $value['source_contact_id'] = $dao->source_contact_id;
+        $value['source_contact_id'] = $dao->contact_id;
 
         // make call use API 3
         $value['version'] = 3;