5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
31 * File for the CiviCRM APIv3 group functions
33 * @package CiviCRM_APIv3
34 * @subpackage API_Group
35 * @copyright CiviCRM LLC (c) 2004-2013
36 * @version $Id: Group.php 30171 2010-10-14 09:11:27Z mover $
40 * Include utility functions
42 require_once 'CRM/Contact/BAO/Group.php';
47 * This API is used to create new group or update any of the existing
48 * In case of updating existing group, id of that particular grop must
49 * be in $params array. Either id or name is required field in the
52 * @param array $params (referance) Associative array of property
53 * name/value pairs to insert in new 'group'
55 * @return array returns id of the group created if success,
56 * error message otherwise
57 *@example GroupCreate.php
58 *{@getfields group_create}
61 function civicrm_api3_group_create($params) {
63 $group = CRM_Contact_BAO_Group
::create($params);
65 if (is_null($group)) {
66 return civicrm_api3_create_error('Group not created');
70 _civicrm_api3_object_to_array_unique_fields($group, $values[$group->id
]);
71 return civicrm_api3_create_success($values, $params, 'group', 'create', $group);
75 * Adjust Metadata for Create action
77 * The metadata is used for setting defaults, documentation & validation
78 * @param array $params array or parameters determined by getfields
80 function _civicrm_api3_group_create_spec(&$params) {
81 $params['is_active']['api.default'] = 1;
82 $params['title']['api.required'] = 1;
86 * Returns array of groups matching a set of one or more group properties
88 * @param array $params (referance) Array of one or more valid
89 * property_name=>value pairs. If $params is set
90 * as null, all groups will be returned
92 * @return array Array of matching groups
93 * @example GroupGet.php
94 * {@getfields group_get}
97 function civicrm_api3_group_get($params) {
99 $options = _civicrm_api3_get_options_from_params($params, TRUE, 'get');
100 $sort = CRM_Utils_Array
::value('sort', $options, NULL);
101 $offset = CRM_Utils_Array
::value('offset', $options);
102 $rowCount = CRM_Utils_Array
::value('limit', $options);
103 $returnProperties = CRM_Utils_Array
::value('return', $options, NULL);
104 $inputParams = CRM_Utils_Array
::value('input_params', $options, array());
105 if(is_array($returnProperties) && !empty($returnProperties)){
106 // group function takes $returnProperties in non standard format & doesn't add id
107 $returnProperties['id'] = 1;
108 $returnProperties = array_keys($returnProperties);
110 $groupObjects = CRM_Contact_BAO_Group
::getGroups($inputParams, $returnProperties, $sort, $offset, $rowCount);
111 if (empty($groupObjects)) {
112 return civicrm_api3_create_success(FALSE);
115 foreach ($groupObjects as $group) {
116 _civicrm_api3_object_to_array($group, $groups[$group->id
]);
117 _civicrm_api3_custom_data_get($groups[$group->id
], 'Group', $group->id
);
121 return civicrm_api3_create_success($groups, $params, 'group', 'create');
125 * delete an existing group
127 * This method is used to delete any existing group. id of the group
128 * to be deleted is required field in $params array
130 * @param array $params (referance) array containing id of the group
133 * @return array (referance) returns flag true if successfull, error
135 *@example GroupDelete.php
136 *{@getfields group_delete}
140 function civicrm_api3_group_delete($params) {
142 CRM_Contact_BAO_Group
::discard($params['id']);
143 return civicrm_api3_create_success(TRUE);