id]); return civicrm_api3_create_success($values, $params, 'group', 'create', $group); } } /** * 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_create_spec(&$params) { $params['is_active']['api.default'] = 1; $params['title']['api.required'] = 1; } /** * Returns array of groups matching a set of one or more group properties * * @param array $params (referance) Array of one or more valid * property_name=>value pairs. If $params is set * as null, all groups will be returned * * @return array Array of matching groups * @example GroupGet.php * {@getfields group_get} * @access public */ function civicrm_api3_group_get($params) { $options = _civicrm_api3_get_options_from_params($params, TRUE, 'group', 'get'); $sort = CRM_Utils_Array::value('sort', $options, NULL); $offset = CRM_Utils_Array::value('offset', $options); $rowCount = CRM_Utils_Array::value('limit', $options); $returnProperties = CRM_Utils_Array::value('return', $options, NULL); $inputParams = CRM_Utils_Array::value('input_params', $options, array()); if(is_array($returnProperties) && !empty($returnProperties)){ // group function takes $returnProperties in non standard format & doesn't add id unset($returnProperties['group_id']); $returnProperties['id'] = 1; $returnProperties = array_keys($returnProperties); } if (!empty($inputParams['group_id'])) { $inputParams['id'] = $inputParams['group_id']; } $groupObjects = CRM_Contact_BAO_Group::getGroups($inputParams, $returnProperties, $sort, $offset, $rowCount); if (empty($groupObjects)) { return civicrm_api3_create_success(FALSE); } $groups = array(); foreach ($groupObjects as $group) { _civicrm_api3_object_to_array($group, $groups[$group->id]); _civicrm_api3_custom_data_get($groups[$group->id], 'Group', $group->id); } return civicrm_api3_create_success($groups, $params, 'group', 'create'); } /** * delete an existing group * * This method is used to delete any existing group. id of the group * to be deleted is required field in $params array * * @param array $params (referance) array containing id of the group * to be deleted * * @return array (referance) returns flag true if successfull, error * message otherwise *@example GroupDelete.php *{@getfields group_delete} * * @access public */ function civicrm_api3_group_delete($params) { CRM_Contact_BAO_Group::discard($params['id']); return civicrm_api3_create_success(TRUE); }