Merge pull request #11736 from jitendrapurohit/CRM-21815
[civicrm-core.git] / api / v3 / examples / Group / GetFields.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Group.getfields API.
50fb255d 4 *
5c49fee0 5 * Demonstrate use of getfields to interrogate api.
50fb255d 6 *
7 * @return array
8 * API result array
9 */
10function group_getfields_example() {
11 $params = array(
12 'action' => 'create',
13 );
6a488035 14
50fb255d 15 try{
a828d7b8 16 $result = civicrm_api3('Group', 'getfields', $params);
50fb255d 17 }
18 catch (CiviCRM_API3_Exception $e) {
19 // Handle error here.
20 $errorMessage = $e->getMessage();
21 $errorCode = $e->getErrorCode();
22 $errorData = $e->getExtraParams();
23 return array(
5be22f39 24 'is_error' => 1,
25 'error_message' => $errorMessage,
50fb255d 26 'error_code' => $errorCode,
27 'error_data' => $errorData,
28 );
29 }
30
31 return $result;
6a488035
TO
32}
33
fb32de45 34/**
50fb255d 35 * Function returns array of result expected from previous function.
36 *
37 * @return array
38 * API result array
6a488035 39 */
50fb255d 40function group_getfields_expectedresult() {
6a488035 41
53ca8fd7 42 $expectedResult = array(
50fb255d 43 'is_error' => 0,
44 'version' => 3,
45 'count' => 20,
46 'values' => array(
53ca8fd7 47 'id' => array(
50fb255d 48 'name' => 'id',
49 'type' => 1,
50 'title' => 'Group ID',
5be22f39 51 'description' => 'Group ID',
50fb255d 52 'required' => TRUE,
1d8ee3d6 53 'table_name' => 'civicrm_group',
54 'entity' => 'Group',
55 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 56 'api.aliases' => array(
57 '0' => 'group_id',
58 ),
59 ),
53ca8fd7 60 'name' => array(
50fb255d 61 'name' => 'name',
62 'type' => 2,
63 'title' => 'Group Name',
5be22f39 64 'description' => 'Internal name of Group.',
50fb255d 65 'maxlength' => 64,
66 'size' => 30,
1d8ee3d6 67 'table_name' => 'civicrm_group',
68 'entity' => 'Group',
69 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 70 ),
53ca8fd7 71 'title' => array(
50fb255d 72 'name' => 'title',
73 'type' => 2,
74 'title' => 'Group Title',
5be22f39 75 'description' => 'Name of Group.',
50fb255d 76 'maxlength' => 64,
77 'size' => 30,
1d8ee3d6 78 'table_name' => 'civicrm_group',
79 'entity' => 'Group',
80 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 81 'api.required' => 1,
82 ),
53ca8fd7 83 'description' => array(
50fb255d 84 'name' => 'description',
85 'type' => 32,
86 'title' => 'Group Description',
5be22f39 87 'description' => 'Optional verbose description of the group.',
50fb255d 88 'rows' => 2,
89 'cols' => 60,
1d8ee3d6 90 'table_name' => 'civicrm_group',
91 'entity' => 'Group',
92 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 93 'html' => array(
94 'type' => 'TextArea',
5be22f39 95 'rows' => 2,
96 'cols' => 60,
50fb255d 97 ),
98 ),
53ca8fd7 99 'source' => array(
50fb255d 100 'name' => 'source',
101 'type' => 2,
102 'title' => 'Group Source',
5be22f39 103 'description' => 'Module or process which created this group.',
50fb255d 104 'maxlength' => 64,
105 'size' => 30,
1d8ee3d6 106 'table_name' => 'civicrm_group',
107 'entity' => 'Group',
108 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 109 ),
53ca8fd7 110 'saved_search_id' => array(
50fb255d 111 'name' => 'saved_search_id',
112 'type' => 1,
113 'title' => 'Saved Search ID',
5be22f39 114 'description' => 'FK to saved search table.',
1d8ee3d6 115 'table_name' => 'civicrm_group',
116 'entity' => 'Group',
117 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 118 'FKClassName' => 'CRM_Contact_DAO_SavedSearch',
119 'FKApiName' => 'SavedSearch',
120 ),
53ca8fd7 121 'is_active' => array(
50fb255d 122 'name' => 'is_active',
123 'type' => 16,
124 'title' => 'Group Enabled',
5be22f39 125 'description' => 'Is this entry active?',
1d8ee3d6 126 'table_name' => 'civicrm_group',
127 'entity' => 'Group',
128 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 129 'api.default' => 1,
130 ),
53ca8fd7 131 'visibility' => array(
50fb255d 132 'name' => 'visibility',
133 'type' => 2,
134 'title' => 'Group Visibility Setting',
5be22f39 135 'description' => 'In what context(s) is this field visible.',
50fb255d 136 'maxlength' => 24,
137 'size' => 20,
138 'default' => 'User and User Admin Only',
1d8ee3d6 139 'table_name' => 'civicrm_group',
140 'entity' => 'Group',
141 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 142 'html' => array(
143 'type' => 'Select',
5be22f39 144 'maxlength' => 24,
145 'size' => 20,
50fb255d 146 ),
147 'pseudoconstant' => array(
148 'callback' => 'CRM_Core_SelectValues::groupVisibility',
149 ),
150 ),
53ca8fd7 151 'where_clause' => array(
50fb255d 152 'name' => 'where_clause',
153 'type' => 32,
154 'title' => 'Group Where Clause',
5be22f39 155 'description' => 'the sql where clause if a saved search acl',
1d8ee3d6 156 'table_name' => 'civicrm_group',
157 'entity' => 'Group',
158 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 159 ),
53ca8fd7 160 'select_tables' => array(
50fb255d 161 'name' => 'select_tables',
162 'type' => 32,
163 'title' => 'Tables For Select Clause',
5be22f39 164 'description' => 'the tables to be included in a select data',
1d8ee3d6 165 'table_name' => 'civicrm_group',
166 'entity' => 'Group',
167 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 168 ),
53ca8fd7 169 'where_tables' => array(
50fb255d 170 'name' => 'where_tables',
171 'type' => 32,
172 'title' => 'Tables For Where Clause',
5be22f39 173 'description' => 'the tables to be included in the count statement',
1d8ee3d6 174 'table_name' => 'civicrm_group',
175 'entity' => 'Group',
176 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 177 ),
53ca8fd7 178 'group_type' => array(
50fb255d 179 'name' => 'group_type',
180 'type' => 2,
181 'title' => 'Group Type',
5be22f39 182 'description' => 'FK to group type',
50fb255d 183 'maxlength' => 128,
184 'size' => 45,
1d8ee3d6 185 'table_name' => 'civicrm_group',
186 'entity' => 'Group',
187 'bao' => 'CRM_Contact_BAO_Group',
5be22f39 188 'pseudoconstant' => array(
189 'optionGroupName' => 'group_type',
190 'optionEditPath' => 'civicrm/admin/options/group_type',
191 ),
50fb255d 192 ),
53ca8fd7 193 'cache_date' => array(
50fb255d 194 'name' => 'cache_date',
5be22f39 195 'type' => 256,
50fb255d 196 'title' => 'Group Cache Date',
5be22f39 197 'description' => 'Date when we created the cache for a smart group',
198 'required' => '',
1d8ee3d6 199 'table_name' => 'civicrm_group',
200 'entity' => 'Group',
201 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 202 ),
53ca8fd7 203 'refresh_date' => array(
50fb255d 204 'name' => 'refresh_date',
5be22f39 205 'type' => 256,
50fb255d 206 'title' => 'Next Group Refresh Time',
5be22f39 207 'description' => 'Date and time when we need to refresh the cache next.',
208 'required' => '',
1d8ee3d6 209 'table_name' => 'civicrm_group',
210 'entity' => 'Group',
211 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 212 ),
53ca8fd7 213 'parents' => array(
50fb255d 214 'name' => 'parents',
215 'type' => 32,
216 'title' => 'Group Parents',
5be22f39 217 'description' => 'IDs of the parent(s)',
1d8ee3d6 218 'table_name' => 'civicrm_group',
219 'entity' => 'Group',
220 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 221 ),
53ca8fd7 222 'children' => array(
50fb255d 223 'name' => 'children',
224 'type' => 32,
225 'title' => 'Group Children',
5be22f39 226 'description' => 'IDs of the child(ren)',
1d8ee3d6 227 'table_name' => 'civicrm_group',
228 'entity' => 'Group',
229 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 230 ),
53ca8fd7 231 'is_hidden' => array(
50fb255d 232 'name' => 'is_hidden',
233 'type' => 16,
234 'title' => 'Group is Hidden',
5be22f39 235 'description' => 'Is this group hidden?',
1d8ee3d6 236 'table_name' => 'civicrm_group',
237 'entity' => 'Group',
238 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 239 ),
53ca8fd7 240 'is_reserved' => array(
50fb255d 241 'name' => 'is_reserved',
242 'type' => 16,
243 'title' => 'Group is Reserved',
1d8ee3d6 244 'table_name' => 'civicrm_group',
245 'entity' => 'Group',
246 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 247 ),
53ca8fd7 248 'created_id' => array(
50fb255d 249 'name' => 'created_id',
250 'type' => 1,
251 'title' => 'Group Created By',
5be22f39 252 'description' => 'FK to contact table.',
1d8ee3d6 253 'table_name' => 'civicrm_group',
254 'entity' => 'Group',
255 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 256 'FKClassName' => 'CRM_Contact_DAO_Contact',
257 'FKApiName' => 'Contact',
258 ),
89bf81b4 259 'modified_id' => array(
50fb255d 260 'name' => 'modified_id',
261 'type' => 1,
262 'title' => 'Group Modified By',
5be22f39 263 'description' => 'FK to contact table.',
1d8ee3d6 264 'table_name' => 'civicrm_group',
265 'entity' => 'Group',
266 'bao' => 'CRM_Contact_BAO_Group',
50fb255d 267 'FKClassName' => 'CRM_Contact_DAO_Contact',
268 'FKApiName' => 'Contact',
269 ),
6a488035 270 ),
50fb255d 271 );
6a488035 272
fb32de45 273 return $expectedResult;
6a488035
TO
274}
275
a828d7b8 276/*
50fb255d 277* This example has been generated from the API test suite.
a828d7b8
CW
278* The test that created it is called "testgetfields"
279* and can be found at:
69d79249 280* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GroupTest.php
6a488035
TO
281*
282* You can see the outcome of the API tests at
69d79249 283* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
284*
285* To Learn about the API read
69d79249 286* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 287*
69d79249 288* Browse the api on your own site with the api explorer
41d4d31f 289* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
290*
291* Read more about testing here
292* http://wiki.civicrm.org/confluence/display/CRM/Testing
293*
294* API Standards documentation:
295* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 296*/