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