$params['status'] = 'Added';
}
//ie. id passed in so we have to return something
- return _civicrm_api3_basic_get('CRM_Contact_BAO_GroupContact', $params);
+ return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
$status = CRM_Utils_Array::value('status', $params, 'Added');
* {@getfields GroupContact_create}
*/
function civicrm_api3_group_contact_create($params) {
-
+ // Nonstandard bao - doesn't accept ID as a param, so convert id to group_id + contact_id
+ if (!empty($params['id'])) {
+ $getParams = array('id' => $params['id']);
+ $info = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $getParams);
+ if (!empty($info['values'][$params['id']])) {
+ $params['group_id'] = $info['values'][$params['id']]['group_id'];
+ $params['contact_id'] = $info['values'][$params['id']]['contact_id'];
+ }
+ }
+ civicrm_api3_verify_mandatory($params, NULL, array('group_id', 'contact_id'));
$action = CRM_Utils_Array::value('status', $params, 'Added');
return _civicrm_api3_group_contact_common($params, $action);
}
-/**
- * Adjust Metadata for Create action
- *
- * The metadata is used for setting defaults, documentation & validation
- * @param array $params array or parameters determined by getfields
- */
-function _civicrm_api3_group_contact_create_spec(&$params) {
- $params['group_id']['api.required'] = 1;
- $params['contact_id']['api.required'] = 1;
-}
-
/**
*
* @param <type> $params
* @deprecated
*/
function civicrm_api3_group_contact_delete($params) {
- $params['status'] = 'Removed';
- return civicrm_api('GroupContact', 'Create', $params);
+ $params['status'] = CRM_Utils_Array::value('status', $params, empty($params['skip_undelete']) ? 'Removed' : 'Deleted');
+ // "Deleted" isn't a real option so skip the api wrapper to avoid pseudoconstant validation
+ return civicrm_api3_group_contact_create($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;
}