clean up(CRM-12274)
authoryashodha <yashodha.chaku@webaccess.co.in>
Mon, 22 Apr 2013 00:38:11 +0000 (06:08 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Mon, 22 Apr 2013 00:38:11 +0000 (06:08 +0530)
CRM/Activity/BAO/Activity.php
CRM/Activity/BAO/ActivityContact.php
CRM/Activity/Form/Activity.php
CRM/Activity/Form/Task/PickOption.php
CRM/Case/BAO/Case.php
CRM/Case/Form/Activity.php
CRM/Case/Form/ActivityView.php
CRM/Case/XMLProcessor/Report.php
CRM/Contact/Form/Task/SMSCommon.php
CRM/Friend/BAO/Friend.php

index 93a7e2e1dbc26802bcf5c654aca2646dc54a01a2..52b8ec88cb02353d229c1edcd25ef31902a07390 100644 (file)
@@ -91,18 +91,21 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
     $activity->copyValues($params);
 
     if ($activity->find(TRUE)) {
+      $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+      $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+      $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+      $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+
       // TODO: at some stage we'll have to deal
       // TODO: with multiple values for assignees and targets, but
       // TODO: for now, let's just fetch first row
-      $defaults['assignee_contact'] = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activity->id);
-      $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id);
-
+      $defaults['assignee_contact'] = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $assigneeID);
+      $assignee_contact_names = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID);
       $defaults['assignee_contact_value'] = implode('; ', $assignee_contact_names);
 
       if ($activity->activity_type_id != CRM_Core_OptionGroup::getValue('activity_type', 'Bulk Email', 'name')) {
-        $defaults['target_contact'] = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activity->id);
-        $target_contact_names = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id);
-
+        $defaults['target_contact'] = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $targetID);
+        $target_contact_names = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $targetID);
         $defaults['target_contact_value'] = implode('; ', $target_contact_names);
       }
       elseif (CRM_Core_Permission::check('access CiviMail') ||
@@ -118,8 +121,6 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
         $defaults['target_contact_value'] = ts('(recipients)');
       }
       
-      $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
-      $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
       $sourceContactId = self::getActivityContact($activity->id, $sourceID);
 
       if ($sourceContactId &&
@@ -202,21 +203,23 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
       //log activty delete.CRM-4525.
       $logMsg          = 'Case Activity deleted for';
       $msgs            = array();
-      $sourceContactId = CRM_Core_DAO::getFieldValue(
-        'CRM_Activity_DAO_Activity',
-        $activity->id,
-        'source_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);
+      $sourceContactId = self::getActivityContact($activity->id, $sourceID);
       if ($sourceContactId) {
         $msgs[] = " source={$sourceContactId}";
       }
+
       //get target contacts.
-      $targetContactIds = CRM_Activity_BAO_ActivityTarget::getTargetNames($activity->id);
+      $targetContactIds = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $targetID);
       if (!empty($targetContactIds)) {
         $msgs[] = " target =" . implode(',', array_keys($targetContactIds));
       }
       //get assignee contacts.
-      $assigneeContactIds = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id);
+      $assigneeContactIds = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID);
       if (!empty($assigneeContactIds)) {
         $msgs[] = " assignee =" . implode(',', array_keys($assigneeContactIds));
       }
@@ -389,19 +392,20 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
       }
       else {
         $assignmentParams['assignee_contact_id'] = $params['assignee_contact_id'];
-
+        $assignmentParams['record_type_id'] = $assigneeID;
         if (CRM_Utils_Array::value('id', $params)) {
           $assignment = new CRM_Activity_BAO_ActivityAssignment();
           $assignment->activity_id = $activityId;
+          $assignment->record_type_id = $assigneeID;
           $assignment->find(TRUE);
 
           if ($assignment->assignee_contact_id != $params['assignee_contact_id']) {
             $assignmentParams['id'] = $assignment->id;
-            $resultAssignment = CRM_Activity_BAO_ActivityAssignment::create($assignmentParams);
+            $resultAssignment = CRM_Activity_BAO_ActivityContact::create($assignmentParams);
           }
         }
         else {
-          $resultAssignment = CRM_Activity_BAO_ActivityAssignment::create($assignmentParams);
+          $resultAssignment = CRM_Activity_BAO_ActivityContact::create($assignmentParams);
         }
       }
     }
@@ -444,19 +448,20 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
       }
       else {
         $targetParams['target_contact_id'] = $params['target_contact_id'];
-
+        $targetParams['record_type_id'] = $targetID;
         if (CRM_Utils_Array::value('id', $params)) {
-          $target = new CRM_Activity_BAO_ActivityTarget();
+          $target = new CRM_Activity_BAO_ActivityContact();
           $target->activity_id = $activityId;
+          $target->record_type_id = $targetID;
           $target->find(TRUE);
 
           if ($target->target_contact_id != $params['target_contact_id']) {
             $targetParams['id'] = $target->id;
-            $resultTarget = CRM_Activity_BAO_ActivityTarget::create($targetParams);
+            $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams);
           }
         }
         else {
-          $resultTarget = CRM_Activity_BAO_ActivityTarget::create($targetParams);
+          $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams);
         }
       }
     }
@@ -2295,10 +2300,13 @@ INNER JOIN  civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n
       $permission = CRM_Core_Permission::EDIT;
     }
 
+    $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);
+
     //check for source contact.
     if (!$componentId || $allow) {
-      $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
-      $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
       $sourceContactId = self::getActivityContact($activity->id, $sourceID);
       $allow = CRM_Contact_BAO_Contact_Permission::allow($sourceContactId, $permission);
     }
@@ -2316,7 +2324,7 @@ INNER JOIN  civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n
       if (!$allow) {
         $allow = TRUE;
         //get the target contacts.
-        $targetContacts = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activity->id);
+        $targetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $targetID);
         foreach ($targetContacts as $cnt => $contactId) {
           if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) {
             $allow = FALSE;
@@ -2326,7 +2334,7 @@ INNER JOIN  civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n
 
         //get the assignee contacts.
         if ($allow) {
-          $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activity->id);
+          $assigneeContacts = CRM_Activity_BAO_Contact::retrieveContactIdsByActivityId($activity->id, $assigneeID);
           foreach ($assigneeContacts as $cnt => $contactId) {
             if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) {
               $allow = FALSE;
index fb89c84af2418f61f957573cf33a4248f032c988..a82d8e1ce5638a1366ae2559d459f56bcd85dc3a 100644 (file)
@@ -103,4 +103,40 @@ AND        contact_a.is_deleted = 0
     return $alsoIDs ? array($names, $ids) : $names;
   }
 
+  /**
+   * function to retrieve id of target contact by activity_id 
+   *
+   * @param int    $id  ID of the activity
+   *
+   * @return mixed
+   *
+   * @access public
+   *
+   */
+  static function retrieveContactIdsByActivityId($activityID, $recordTypeID) {
+    $activityContact = array();
+    if (!CRM_Utils_Rule::positiveInteger($activityID) ||
+        !CRM_Utils_Rule::positiveInteger($recordTypeID)) {
+      return $activityContact;
+    }
+
+    $sql = "                                                                                                                                                                                             SELECT     contact_id
+FROM       civicrm_activity_contact
+INNER JOIN civicrm_contact ON contact_id = civicrm_contact.id
+WHERE      activity_id = %1
+AND        record_type_id = %2 
+AND        civicrm_contact.is_deleted = 0 
+";
+    $params = array(
+      1 => array($activityID, 'Integer'),
+      2 => array($recordTypeID, 'Integer')
+    );
+
+    $dao = CRM_Core_DAO::executeQuery($sql, $params);
+    while ($dao->fetch()) {
+      $activityContact[] = $dao->contact_id;
+    }
+    return $activityContact;
+  }
+
 }
index bb88b592d12ed4fb1dd667c955ed8cc4f86eb5d1..f921a08c80d48f9d905934239c1910d6debef973 100644 (file)
@@ -1078,13 +1078,15 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
    */
   protected function processActivity(&$params) {
     $activityAssigned = array();
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     // format assignee params
     if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
       //skip those assignee contacts which are already assigned
       //while sending a copy.CRM-4509.
       $activityAssigned = array_flip($params['assignee_contact_id']);
       if ($this->_activityId) {
-        $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId);
+        $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($this->_activityId, $assigneeID);
         $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts);
       }
     }
@@ -1139,7 +1141,8 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
       )
     ) {
       $mailToContacts = array();
-      $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE);
+      //FIX ME : add more parameters to 'getNames' function
+      $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID, TRUE, FALSE);
 
       //build an associative array with unique email addresses.
       foreach ($activityAssigned as $id => $dnc) {
index b80b85883d854027460f9fc0c393e4d759bcada0..73a9ffbd7d42c44f86f2b3eacec676053c1b0639 100644 (file)
@@ -149,17 +149,21 @@ class CRM_Activity_Form_Task_PickOption extends CRM_Activity_Form_Task {
     $this->controller->resetPage('Email');
     $params = $this->exportValues();
     $this->_contacts = array();
+    
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); 
     //get assignee contacts
     if (!empty($params['assigned_to'])) {
       foreach ($this->_activityHolderIds as $key => $id) {
-        $ids = array_keys(CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($id));
+        $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $assigneeID));
         $this->_contacts = array_merge($this->_contacts, $ids);
       }
     }
     //get target contacts
     if (!empty($params['with_contact'])) {
       foreach ($this->_activityHolderIds as $key => $id) {
-        $ids = array_keys(CRM_Activity_BAO_ActivityTarget::getTargetNames($id));
+        $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID));
         $this->_contacts = array_merge($this->_contacts, $ids);
       }
     }
index 0d33cbef8d0e2a558b764c12257afe774990bd5f..ce0bc025f5f6c71b6b8989dca76792b1bc871de5 100644 (file)
@@ -976,6 +976,7 @@ SELECT case_status.label AS case_status, status_id, case_type.label AS case_type
 
     $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
     $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $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.
@@ -1029,7 +1030,6 @@ SELECT case_status.label AS case_status, status_id, case_type.label AS case_type
       $where .= " AND ca.is_deleted = 0";
     }
 
-
     if (CRM_Utils_Array::value('activity_type_id', $params)) {
       $where .= " AND ca.activity_type_id = " . CRM_Utils_Type::escape($params['activity_type_id'], 'Integer');
     }
@@ -1180,8 +1180,7 @@ SELECT case_status.label AS case_status, status_id, case_type.label AS case_type
         $reporterName = '<a href="' . $contactViewUrl . $dao->reporter_id . '">' . $dao->reporter . '</a>';
       }
       $values[$dao->id]['reporter'] = $reporterName;
-
-      $targetNames = CRM_Activity_BAO_ActivityTarget::getTargetNames($dao->id);
+      $targetNames = CRM_Activity_BAO_ActivityContact::getNames($dao->id, $targetID);
       $targetContactUrls = $withContacts = array();
       foreach ($targetNames as $targetId => $targetName) {
         if (!in_array($targetId, $clientIds)) {
index 393e3acd79fee0a4128ef1cdd5e5ed059feecd29..4889b72f051bad670040b5e13ea9d14ff3c7401e 100644 (file)
@@ -605,7 +605,7 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
       //while sending a copy.CRM-4509.
       $activityAssigned = array_flip($params['assignee_contact_id']);
       $activityId       = isset($this->_activityId) ? $this->_activityId : $activity->id;
-      $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityId);
+      $assigneeContacts = CRM_Activity_BAO_ActivityContact::getNames($activityId, $assigneeID);
       $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts);
 
       foreach ($params['assignee_contact_id'] as $key => $id) {
@@ -628,7 +628,8 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
     //CRM-5695
     //check for notification settings for assignee contacts
     $selectedContacts = array('contact_check');
-
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
     if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
         'activity_assignee_notification'
       )) {
@@ -641,7 +642,7 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
           $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s).");
         }
         else {
-          $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE);
+          $this->_relatedContacts = CRM_Activity_BAO_ActivityContact::getNames($activity->id, $assigneeID, TRUE, FALSE);
           $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s).");
         }
         //build an associative array with unique email addresses.
index 0861cbc4fe2313e0bea9541ece79a9dc9f306449..e425ac405eb05d6cbd5d8082dc0cffef0c744299 100644 (file)
@@ -132,7 +132,9 @@ class CRM_Case_Form_ActivityView extends CRM_Core_Form {
     //viewing activity should get diplayed in recent list.CRM-4670
     $activityTypeID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id');
 
-    $activityTargetContacts = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activityID);
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+    $activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID);
     if (!empty($activityTargetContacts)) {
       $recentContactId = $activityTargetContacts[0];
     }
index cfa5697e330b7fcb6668b4303c3a1bf00366c78b..50bdb6f6d6c48fb3593819632ea774475b0b350a 100644 (file)
@@ -313,10 +313,13 @@ WHERE      a.id = %1
       );
     }
 
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
     if (!empty($activityDAO->targetID)) {
       // Re-lookup the target ID since the DAO only has the first recipient if there are multiple.
       // Maybe not the best solution.
-      $targetNames   = CRM_Activity_BAO_ActivityTarget::getTargetNames($activityDAO->id);
+      $targetNames   = CRM_Activity_BAO_ActivityContact::getNames($activityDAO->id, $targetID);
       $processTarget = FALSE;
       $label         = ts('With Contact(s)');
       if (in_array($activityTypeInfo['name'], array(
@@ -383,9 +386,11 @@ WHERE      a.id = %1
       'value' => $this->redact($creator),
       'type' => 'String',
     );
-
+    $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+    $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
+    $source_contact_id = CRM_Activity_BAO_Activity::getActivityContact($activityDAO->id, $sourceID);
     $reporter = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
-      $activityDAO->source_contact_id,
+      $source_contact_id,
       'display_name'
     );
 
@@ -413,7 +418,7 @@ WHERE      a.id = %1
 
     if (!empty($activityDAO->assigneeID)) {
       //allow multiple assignee contacts.CRM-4503.
-      $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityDAO->id, TRUE);
+        $assignee_contact_names = CRM_Activity_BAO_ActivityContact::getNames($activityDAO->id, $assigneeID, TRUE);
 
       foreach ($assignee_contact_names as & $assignee) {
         // add Assignee to the strings to be redacted across the case session
index d21c14495f87217e90b335494439eb6e6075eaba..16e96c542e68e2b7630de38855edeade2ea77869 100644 (file)
@@ -142,8 +142,10 @@ class CRM_Contact_Form_Task_SMSCommon {
           continue;
         }
 
+        $activityContacts = CRM_Core_PseudoConstant::activityContacts('name');
+        $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
         //target contacts limit check
-        $ids = array_keys(CRM_Activity_BAO_ActivityTarget::getTargetNames($id));
+        $ids = array_keys(CRM_Activity_BAO_ActivityContact::getNames($id, $targetID));
 
         if (count($ids) > 1) {
           $extendTargetContacts++;
index 5aba88fe1c328e99f2c62c7f32b1cdc776216ed6..0bd64a8065a724c71c1e14b56d82918d531ac88e 100644 (file)
@@ -163,7 +163,7 @@ class CRM_Friend_BAO_Friend extends CRM_Friend_DAO_Friend {
       $activityContact->contact_id = $contact;
       $activityContact->find(TRUE);
       if (empty($activityContact->id)) {
-        $resultTarget = CRM_Activity_BAO_ActivityTarget::create($targetParams);
+        $resultTarget = CRM_Activity_BAO_ActivityContact::create($targetParams);
       }
     }