Merge pull request #5216 from atif-shaikh/CRM-15792
[civicrm-core.git] / api / v3 / examples / Group / GetFields.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Group.getfields API.
4 *
5 * Demonstrate use of getfields to interrogate api.
6 *
7 * @return array
8 * API result array
9 */
10 function group_getfields_example() {
11 $params = array(
12 'action' => 'create',
13 );
14
15 try{
16 $result = civicrm_api3('Group', 'getfields', $params);
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(
24 'error' => $errorMessage,
25 'error_code' => $errorCode,
26 'error_data' => $errorData,
27 );
28 }
29
30 return $result;
31 }
32
33 /**
34 * Function returns array of result expected from previous function.
35 *
36 * @return array
37 * API result array
38 */
39 function group_getfields_expectedresult() {
40
41 $expectedResult = array(
42 'is_error' => 0,
43 'version' => 3,
44 'count' => 20,
45 'values' => array(
46 'id' => array(
47 'name' => 'id',
48 'type' => 1,
49 'title' => 'Group ID',
50 'required' => TRUE,
51 'api.aliases' => array(
52 '0' => 'group_id',
53 ),
54 ),
55 'name' => array(
56 'name' => 'name',
57 'type' => 2,
58 'title' => 'Group Name',
59 'maxlength' => 64,
60 'size' => 30,
61 ),
62 'title' => array(
63 'name' => 'title',
64 'type' => 2,
65 'title' => 'Group Title',
66 'maxlength' => 64,
67 'size' => 30,
68 'api.required' => 1,
69 ),
70 'description' => array(
71 'name' => 'description',
72 'type' => 32,
73 'title' => 'Group Description',
74 'rows' => 2,
75 'cols' => 60,
76 'html' => array(
77 'type' => 'TextArea',
78 ),
79 ),
80 'source' => array(
81 'name' => 'source',
82 'type' => 2,
83 'title' => 'Group Source',
84 'maxlength' => 64,
85 'size' => 30,
86 ),
87 'saved_search_id' => array(
88 'name' => 'saved_search_id',
89 'type' => 1,
90 'title' => 'Saved Search ID',
91 'FKClassName' => 'CRM_Contact_DAO_SavedSearch',
92 'FKApiName' => 'SavedSearch',
93 ),
94 'is_active' => array(
95 'name' => 'is_active',
96 'type' => 16,
97 'title' => 'Group Enabled',
98 'api.default' => 1,
99 ),
100 'visibility' => array(
101 'name' => 'visibility',
102 'type' => 2,
103 'title' => 'Group Visibility Setting',
104 'maxlength' => 24,
105 'size' => 20,
106 'default' => 'User and User Admin Only',
107 'html' => array(
108 'type' => 'Select',
109 ),
110 'pseudoconstant' => array(
111 'callback' => 'CRM_Core_SelectValues::groupVisibility',
112 ),
113 ),
114 'where_clause' => array(
115 'name' => 'where_clause',
116 'type' => 32,
117 'title' => 'Group Where Clause',
118 ),
119 'select_tables' => array(
120 'name' => 'select_tables',
121 'type' => 32,
122 'title' => 'Tables For Select Clause',
123 ),
124 'where_tables' => array(
125 'name' => 'where_tables',
126 'type' => 32,
127 'title' => 'Tables For Where Clause',
128 ),
129 'group_type' => array(
130 'name' => 'group_type',
131 'type' => 2,
132 'title' => 'Group Type',
133 'maxlength' => 128,
134 'size' => 45,
135 ),
136 'cache_date' => array(
137 'name' => 'cache_date',
138 'type' => 12,
139 'title' => 'Group Cache Date',
140 ),
141 'refresh_date' => array(
142 'name' => 'refresh_date',
143 'type' => 12,
144 'title' => 'Next Group Refresh Time',
145 ),
146 'parents' => array(
147 'name' => 'parents',
148 'type' => 32,
149 'title' => 'Group Parents',
150 ),
151 'children' => array(
152 'name' => 'children',
153 'type' => 32,
154 'title' => 'Group Children',
155 ),
156 'is_hidden' => array(
157 'name' => 'is_hidden',
158 'type' => 16,
159 'title' => 'Group is Hidden',
160 ),
161 'is_reserved' => array(
162 'name' => 'is_reserved',
163 'type' => 16,
164 'title' => 'Group is Reserved',
165 ),
166 'created_id' => array(
167 'name' => 'created_id',
168 'type' => 1,
169 'title' => 'Group Created By',
170 'FKClassName' => 'CRM_Contact_DAO_Contact',
171 'FKApiName' => 'Contact',
172 ),
173 'modified_id' => array(
174 'name' => 'modified_id',
175 'type' => 1,
176 'title' => 'Group Modified By',
177 'FKClassName' => 'CRM_Contact_DAO_Contact',
178 'FKApiName' => 'Contact',
179 ),
180 ),
181 );
182
183 return $expectedResult;
184 }
185
186 /*
187 * This example has been generated from the API test suite.
188 * The test that created it is called "testgetfields"
189 * and can be found at:
190 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GroupTest.php
191 *
192 * You can see the outcome of the API tests at
193 * https://test.civicrm.org/job/CiviCRM-master-git/
194 *
195 * To Learn about the API read
196 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
197 *
198 * Browse the api on your own site with the api explorer
199 * http://MYSITE.ORG/path/to/civicrm/api
200 *
201 * Read more about testing here
202 * http://wiki.civicrm.org/confluence/display/CRM/Testing
203 *
204 * API Standards documentation:
205 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
206 */