From: yashodha Date: Mon, 22 Apr 2013 00:38:11 +0000 (+0530) Subject: clean up(CRM-12274) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=034500d496fb8cf6b9ece94530a4cdf2c246c3d3;p=civicrm-core.git clean up(CRM-12274) --- diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 93a7e2e1db..52b8ec88cb 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -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; diff --git a/CRM/Activity/BAO/ActivityContact.php b/CRM/Activity/BAO/ActivityContact.php index fb89c84af2..a82d8e1ce5 100644 --- a/CRM/Activity/BAO/ActivityContact.php +++ b/CRM/Activity/BAO/ActivityContact.php @@ -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; + } + } diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index bb88b592d1..f921a08c80 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -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) { diff --git a/CRM/Activity/Form/Task/PickOption.php b/CRM/Activity/Form/Task/PickOption.php index b80b85883d..73a9ffbd7d 100644 --- a/CRM/Activity/Form/Task/PickOption.php +++ b/CRM/Activity/Form/Task/PickOption.php @@ -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); } } diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 0d33cbef8d..ce0bc025f5 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -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 = '' . $dao->reporter . ''; } $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)) { diff --git a/CRM/Case/Form/Activity.php b/CRM/Case/Form/Activity.php index 393e3acd79..4889b72f05 100644 --- a/CRM/Case/Form/Activity.php +++ b/CRM/Case/Form/Activity.php @@ -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. diff --git a/CRM/Case/Form/ActivityView.php b/CRM/Case/Form/ActivityView.php index 0861cbc4fe..e425ac405e 100644 --- a/CRM/Case/Form/ActivityView.php +++ b/CRM/Case/Form/ActivityView.php @@ -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]; } diff --git a/CRM/Case/XMLProcessor/Report.php b/CRM/Case/XMLProcessor/Report.php index cfa5697e33..50bdb6f6d6 100644 --- a/CRM/Case/XMLProcessor/Report.php +++ b/CRM/Case/XMLProcessor/Report.php @@ -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 diff --git a/CRM/Contact/Form/Task/SMSCommon.php b/CRM/Contact/Form/Task/SMSCommon.php index d21c14495f..16e96c542e 100644 --- a/CRM/Contact/Form/Task/SMSCommon.php +++ b/CRM/Contact/Form/Task/SMSCommon.php @@ -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++; diff --git a/CRM/Friend/BAO/Friend.php b/CRM/Friend/BAO/Friend.php index 5aba88fe1c..0bd64a8065 100644 --- a/CRM/Friend/BAO/Friend.php +++ b/CRM/Friend/BAO/Friend.php @@ -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); } }