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