From c49a2977289a3a75c491f52afde23b5aebe1a83a Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 3 Jan 2014 14:37:50 -0800 Subject: [PATCH] CRM-14024 - Get rid of redundant fn --- CRM/Campaign/Page/Petition/Confirm.php | 9 +++-- CRM/Contact/BAO/GroupContact.php | 51 +++----------------------- CRM/Mailing/Event/BAO/Confirm.php | 5 ++- api/v3/GroupContact.php | 11 ++++-- 4 files changed, 22 insertions(+), 54 deletions(-) diff --git a/CRM/Campaign/Page/Petition/Confirm.php b/CRM/Campaign/Page/Petition/Confirm.php index b31f2b1a23..e7d8829f43 100644 --- a/CRM/Campaign/Page/Petition/Confirm.php +++ b/CRM/Campaign/Page/Petition/Confirm.php @@ -106,9 +106,12 @@ class CRM_Campaign_Page_Petition_Confirm extends CRM_Core_Page { $ce->time_stamp = date('YmdHis'); $ce->save(); - - CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, - 'Email', $ce->id + CRM_Contact_BAO_GroupContact::addContactsToGroup( + array($contact_id), + $se->group_id, + 'Email', + 'Added', + $ce->id ); $bao = new CRM_Campaign_BAO_Petition(); diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index 9d23870dd3..7797556146 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -120,15 +120,18 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { /** * Given an array of contact ids, add all the contacts to the group * - * @param array $contactIds (reference ) the array of contact ids to be added - * @param int $groupId the id of the group + * @param array $contactIds the array of contact ids to be added + * @param int $groupId the id of the group + * @param string $method + * @param string $status + * @param int $tracking * * @return array (total, added, notAdded) count of contacts added to group * @access public * @static */ static function addContactsToGroup( - &$contactIds, + $contactIds, $groupId, $method = 'Admin', $status = 'Added', @@ -466,48 +469,6 @@ SELECT * return $dao; } - /** - * Method to update the Status of Group member form 'Pending' to 'Added' - * - * @param int $contactId id of the contact - * - * @param int $groupID Id of a perticuler group - * - * @param mixed $tracking tracking information for history - * - * @return null If success - * @access public - * @static - */ - static function updateGroupMembershipStatus($contactId, $groupID, $method = 'Email', $tracking = NULL) { - if (!isset($contactId) && !isset($groupID)) { - return CRM_Core_Error::fatal("$contactId or $groupID should not empty"); - } - - $query = " -UPDATE civicrm_group_contact - SET civicrm_group_contact.status = 'Added' - WHERE civicrm_group_contact.contact_id = %1 - AND civicrm_group_contact.group_id = %2"; - $params = array( - 1 => array($contactId, 'Integer'), - 2 => array($groupID, 'Integer'), - ); - - $dao = CRM_Core_DAO::executeQuery($query, $params); - - $params = array( - 'contact_id' => $contactId, - 'group_id' => $groupID, - 'status' => 'Added', - 'method' => $method, - 'tracking' => $tracking, - ); - - CRM_Contact_BAO_SubscriptionHistory::create($params); - return NULL; - } - /** * Method to get Group Id * diff --git a/CRM/Mailing/Event/BAO/Confirm.php b/CRM/Mailing/Event/BAO/Confirm.php index 427216996a..9b4ce911e7 100644 --- a/CRM/Mailing/Event/BAO/Confirm.php +++ b/CRM/Mailing/Event/BAO/Confirm.php @@ -86,10 +86,11 @@ class CRM_Mailing_Event_BAO_Confirm extends CRM_Mailing_Event_DAO_Confirm { $ce->time_stamp = date('YmdHis'); $ce->save(); - CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus( - $contact_id, + CRM_Contact_BAO_GroupContact::addContactsToGroup( + array($contact_id), $se->group_id, 'Email', + 'Added', $ce->id ); diff --git a/api/v3/GroupContact.php b/api/v3/GroupContact.php index 7223ed2c9f..85bfa54941 100644 --- a/api/v3/GroupContact.php +++ b/api/v3/GroupContact.php @@ -228,10 +228,13 @@ function civicrm_api3_group_contact_update_status($params) { civicrm_api3_verify_mandatory($params, NULL, array('contact_id', 'group_id')); - $method = CRM_Utils_Array::value('method', $params, 'API'); - $tracking = CRM_Utils_Array::value('tracking', $params); - - CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($params['contact_id'], $params['group_id'], $method, $tracking); + CRM_Contact_BAO_GroupContact::addContactsToGroup( + array($params['contact_id']), + $params['group_id'], + CRM_Utils_Array::value('method', $params, 'API'), + 'Added', + CRM_Utils_Array::value('tracking', $params) + ); return TRUE; } -- 2.25.1