}
/**
- * Creates / removes contacts from the groups
+ * Deprecated create function.
+ *
+ * @deprecated
*
* @param array $params
- * Name/value pairs.
- * @param int $contactId
- * Contact id.
- * @param bool $ignorePermission
- * if ignorePermission is true we are coming in via profile mean $method = 'Web'
- * @param string $method
*
- * @return CRM_Contact_BAO_GroupContact|void
+ * @return CRM_Contact_BAO_GroupContact
*/
- public static function create($params, $contactId, $ignorePermission = FALSE, $method = 'Admin') {
- if (empty($contactId)) {
- return self::add($params);
- }
-
+ public static function create(array $params) {
// @fixme create was only called from CRM_Contact_BAO_Contact::createProfileContact
- // Now it's not called from anywhere so we can remove the below code after some time
- CRM_Core_Error::deprecatedFunctionWarning('Use the GroupContact API');
-
- $contactIds = [$contactId];
- $contactGroup = [];
-
- if ($contactId) {
- $contactGroupList = CRM_Contact_BAO_GroupContact::getContactGroup($contactId, 'Added',
- NULL, FALSE, $ignorePermission
- );
- if (is_array($contactGroupList)) {
- foreach ($contactGroupList as $key) {
- $groupId = $key['group_id'];
- $contactGroup[$groupId] = $groupId;
- }
- }
- }
-
- // get the list of all the groups
- $allGroup = CRM_Contact_BAO_GroupContact::getGroupList(0, $ignorePermission);
+ // As of Aug 2020 it's not called from anywhere so we can remove the below code after some time
- // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
- if (!is_array($params)) {
- $params = [];
- }
-
- // check which values has to be add/remove contact from group
- foreach ($allGroup as $key => $varValue) {
- if (!empty($params[$key]) && !array_key_exists($key, $contactGroup)) {
- // add contact to group
- CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $key, $method);
- }
- elseif (empty($params[$key]) && array_key_exists($key, $contactGroup)) {
- // remove contact from group
- CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $key, $method);
- }
- }
+ CRM_Core_Error::deprecatedFunctionWarning('Use the GroupContact API');
+ return self::add($params);
}
/**