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);
76 * Adjust Metadata for Create action
78 * The metadata is used for setting defaults, documentation & validation
79 * @param array $params array or parameters determined by getfields
81 function _civicrm_api3_group_create_spec(&$params) {
82 $params['is_active']['api.default'] = 1;
83 $params['title']['api.required'] = 1;
87 * Returns array of groups matching a set of one or more group properties
89 * @param array $params (referance) Array of one or more valid
90 * property_name=>value pairs. If $params is set
91 * as null, all groups will be returned
93 * @return array Array of matching groups
94 * @example GroupGet.php
95 * {@getfields group_get}
98 function civicrm_api3_group_get($params) {
100 $options = _civicrm_api3_get_options_from_params($params, TRUE, 'get');
101 $sort = CRM_Utils_Array
::value('sort', $options, NULL);
102 $offset = CRM_Utils_Array
::value('offset', $options);
103 $rowCount = CRM_Utils_Array
::value('limit', $options);
104 $returnProperties = CRM_Utils_Array
::value('return', $options, NULL);
105 $inputParams = CRM_Utils_Array
::value('input_params', $options, array());
106 if(is_array($returnProperties) && !empty($returnProperties)){
107 // group function takes $returnProperties in non standard format & doesn't add id
108 $returnProperties['id'] = 1;
109 $returnProperties = array_keys($returnProperties);
111 $groupObjects = CRM_Contact_BAO_Group
::getGroups($inputParams, $returnProperties, $sort, $offset, $rowCount);
112 if (empty($groupObjects)) {
113 return civicrm_api3_create_success(FALSE);
116 foreach ($groupObjects as $group) {
117 _civicrm_api3_object_to_array($group, $groups[$group->id
]);
118 _civicrm_api3_custom_data_get($groups[$group->id
], 'Group', $group->id
);
122 return civicrm_api3_create_success($groups, $params, 'group', 'create');
126 * delete an existing group
128 * This method is used to delete any existing group. id of the group
129 * to be deleted is required field in $params array
131 * @param array $params (referance) array containing id of the group
134 * @return array (referance) returns flag true if successfull, error
136 *@example GroupDelete.php
137 *{@getfields group_delete}
141 function civicrm_api3_group_delete($params) {
143 CRM_Contact_BAO_Group
::discard($params['id']);
144 return civicrm_api3_create_success(TRUE);