Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | // $Id$ | |
3 | ||
4 | /* | |
5 | +--------------------------------------------------------------------+ | |
6 | | CiviCRM version 4.3 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
9 | +--------------------------------------------------------------------+ | |
10 | | This file is a part of CiviCRM. | | |
11 | | | | |
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. | | |
15 | | | | |
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. | | |
20 | | | | |
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 | +--------------------------------------------------------------------+ | |
28 | */ | |
29 | ||
30 | /** | |
31 | * File for the CiviCRM APIv3 group functions | |
32 | * | |
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 $ | |
37 | */ | |
38 | ||
39 | /** | |
40 | * Include utility functions | |
41 | */ | |
42 | require_once 'CRM/Contact/BAO/Group.php'; | |
43 | ||
44 | /** | |
45 | * create/update group | |
46 | * | |
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 | |
50 | * $params array | |
51 | * | |
52 | * @param array $params (referance) Associative array of property | |
53 | * name/value pairs to insert in new 'group' | |
54 | * | |
55 | * @return array returns id of the group created if success, | |
56 | * error message otherwise | |
57 | *@example GroupCreate.php | |
58 | *{@getfields group_create} | |
59 | * @access public | |
60 | */ | |
61 | function civicrm_api3_group_create($params) { | |
62 | ||
63 | $group = CRM_Contact_BAO_Group::create($params); | |
64 | ||
65 | if (is_null($group)) { | |
66 | return civicrm_api3_create_error('Group not created'); | |
67 | } | |
68 | else { | |
69 | $values = array(); | |
70 | _civicrm_api3_object_to_array_unique_fields($group, $values[$group->id]); | |
71 | return civicrm_api3_create_success($values, $params, 'group', 'create', $group); | |
72 | } | |
73 | } | |
74 | /* | |
75 | * Adjust Metadata for Create action | |
76 | * | |
77 | * The metadata is used for setting defaults, documentation & validation | |
78 | * @param array $params array or parameters determined by getfields | |
79 | */ | |
80 | function _civicrm_api3_group_create_spec(&$params) { | |
81 | $params['is_active']['api.default'] = 1; | |
82 | $params['title']['api.required'] = 1; | |
83 | } | |
84 | ||
85 | /** | |
86 | * Returns array of groups matching a set of one or more group properties | |
87 | * | |
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 | |
91 | * | |
92 | * @return array Array of matching groups | |
93 | * @example GroupGet.php | |
94 | * {@getfields group_get} | |
95 | * @access public | |
96 | */ | |
97 | function civicrm_api3_group_get($params) { | |
98 | ||
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); | |
109 | } | |
110 | $groupObjects = CRM_Contact_BAO_Group::getGroups($inputParams, $returnProperties, $sort, $offset, $rowCount); | |
111 | if (empty($groupObjects)) { | |
112 | return civicrm_api3_create_success(FALSE); | |
113 | } | |
114 | $groups = array(); | |
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); | |
118 | } | |
119 | ||
120 | ||
121 | return civicrm_api3_create_success($groups, $params, 'group', 'create'); | |
122 | } | |
123 | ||
124 | /** | |
125 | * delete an existing group | |
126 | * | |
127 | * This method is used to delete any existing group. id of the group | |
128 | * to be deleted is required field in $params array | |
129 | * | |
130 | * @param array $params (referance) array containing id of the group | |
131 | * to be deleted | |
132 | * | |
133 | * @return array (referance) returns flag true if successfull, error | |
134 | * message otherwise | |
135 | *@example GroupDelete.php | |
136 | *{@getfields group_delete} | |
137 | * | |
138 | * @access public | |
139 | */ | |
140 | function civicrm_api3_group_delete($params) { | |
141 | ||
142 | CRM_Contact_BAO_Group::discard($params['id']); | |
143 | return civicrm_api3_create_success(TRUE); | |
144 | } | |
145 |