/**
* 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',
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
*
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;
}