Merge pull request #14894 from eileenmcnaughton/date_fisc
[civicrm-core.git] / api / v3 / examples / Profile / GetFields.ex.php
CommitLineData
9dec4e61 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Profile.getfields API.
50fb255d 4 *
5 * demonstrates retrieving profile fields passing in an id
6 *
7 * @return array
8 * API result array
9 */
10function profile_getfields_example() {
cf8f0fff 11 $params = [
50fb255d 12 'action' => 'submit',
8390b11b 13 'profile_id' => 22,
cf8f0fff 14 ];
9dec4e61 15
50fb255d 16 try{
a828d7b8 17 $result = civicrm_api3('Profile', 'getfields', $params);
50fb255d 18 }
19 catch (CiviCRM_API3_Exception $e) {
20 // Handle error here.
21 $errorMessage = $e->getMessage();
22 $errorCode = $e->getErrorCode();
23 $errorData = $e->getExtraParams();
cf8f0fff 24 return [
1d8ee3d6 25 'is_error' => 1,
26 'error_message' => $errorMessage,
50fb255d 27 'error_code' => $errorCode,
28 'error_data' => $errorData,
cf8f0fff 29 ];
50fb255d 30 }
31
32 return $result;
9dec4e61 33}
34
35/**
50fb255d 36 * Function returns array of result expected from previous function.
37 *
38 * @return array
39 * API result array
9dec4e61 40 */
50fb255d 41function profile_getfields_expectedresult() {
9dec4e61 42
cf8f0fff 43 $expectedResult = [
50fb255d 44 'is_error' => 0,
45 'version' => 3,
46 'count' => 9,
cf8f0fff
CW
47 'values' => [
48 'custom_1' => [
8390b11b 49 'id' => '1',
50fb255d 50 'label' => '_addCustomFieldToProfile',
8390b11b
SL
51 'headerPattern' => '//',
52 'title' => 'first_name',
53 'custom_field_id' => '1',
54 'groupTitle' => '_addCustomFieldToProfile',
50fb255d 55 'data_type' => 'String',
8390b11b
SL
56 'name' => 'custom_1',
57 'type' => 2,
50fb255d 58 'html_type' => 'Text',
59 'default_value' => 'defaultValue',
60 'text_length' => '',
61 'options_per_line' => '',
62 'custom_group_id' => '1',
63 'extends' => 'Contact',
64 'is_search_range' => 0,
65 'extends_entity_column_value' => '',
66 'extends_entity_column_id' => '',
67 'is_view' => 0,
68 'is_multiple' => 0,
69 'option_group_id' => '',
70 'date_format' => '',
71 'time_format' => '',
72 'is_required' => 0,
1d8ee3d6 73 'table_name' => 'civicrm_value__addcustomfie_1',
74 'column_name' => '_addcustomfieldtoprofile_1',
8390b11b
SL
75 'where' => 'civicrm_value__addcustomfie_1._addcustomfieldtoprofile_1',
76 'extends_table' => 'civicrm_contact',
77 'search_table' => 'contact_a',
50fb255d 78 'api.required' => '1',
79 'help_pre' => '',
80 'help_post' => '',
81 'entity' => 'contact',
82 'weight' => '1',
cf8f0fff
CW
83 'api.aliases' => [],
84 ],
85 'postal_code-1' => [
50fb255d 86 'name' => 'postal_code',
87 'type' => 2,
88 'title' => 'State Province',
1d8ee3d6 89 'description' => 'Store both US (zip5) AND international postal codes. App is responsible for country/region appropriate validation.',
90 'maxlength' => 64,
91 'size' => 6,
50fb255d 92 'import' => TRUE,
93 'where' => 'civicrm_address.postal_code',
94 'headerPattern' => '/postal|zip/i',
95 'dataPattern' => '/\\d?\\d{4}(-\\d{4})?/',
96 'export' => TRUE,
1d8ee3d6 97 'table_name' => 'civicrm_address',
98 'entity' => 'address',
99 'bao' => 'CRM_Core_BAO_Address',
8390b11b 100 'localizable' => 0,
cf8f0fff 101 'html' => [
1d8ee3d6 102 'type' => 'Text',
103 'maxlength' => 64,
104 'size' => 6,
cf8f0fff 105 ],
8390b11b 106 'is_core_field' => TRUE,
50fb255d 107 'api.required' => 0,
108 'help_pre' => '',
109 'help_post' => '',
50fb255d 110 'weight' => '2',
cf8f0fff
CW
111 'api.aliases' => [],
112 ],
113 'state_province-1' => [
50fb255d 114 'name' => 'state_province_id',
115 'type' => 1,
116 'title' => 'State Province',
1d8ee3d6 117 'description' => 'Which State_Province does this address belong to.',
8390b11b 118 'where' => 'civicrm_address.state_province_id',
1d8ee3d6 119 'table_name' => 'civicrm_address',
120 'entity' => 'address',
121 'bao' => 'CRM_Core_BAO_Address',
8390b11b
SL
122 'localizable' => 0,
123 'localize_context' => 'province',
50fb255d 124 'FKClassName' => 'CRM_Core_DAO_StateProvince',
cf8f0fff 125 'html' => [
1d8ee3d6 126 'type' => 'ChainSelect',
127 'size' => 6,
128 'maxlength' => 14,
cf8f0fff
CW
129 ],
130 'pseudoconstant' => [
50fb255d 131 'table' => 'civicrm_state_province',
132 'keyColumn' => 'id',
133 'labelColumn' => 'name',
cf8f0fff 134 ],
8390b11b 135 'is_core_field' => TRUE,
50fb255d 136 'FKApiName' => 'StateProvince',
137 'api.required' => '1',
138 'help_pre' => '',
139 'help_post' => '',
50fb255d 140 'weight' => '3',
cf8f0fff
CW
141 'api.aliases' => [],
142 ],
143 'country-1' => [
50fb255d 144 'name' => 'country_id',
145 'type' => 1,
146 'title' => 'Country',
1d8ee3d6 147 'description' => 'Which Country does this address belong to.',
8390b11b 148 'where' => 'civicrm_address.country_id',
1d8ee3d6 149 'table_name' => 'civicrm_address',
150 'entity' => 'address',
151 'bao' => 'CRM_Core_BAO_Address',
8390b11b
SL
152 'localizable' => 0,
153 'localize_context' => 'country',
50fb255d 154 'FKClassName' => 'CRM_Core_DAO_Country',
cf8f0fff 155 'html' => [
50fb255d 156 'type' => 'Select',
1d8ee3d6 157 'size' => 6,
158 'maxlength' => 14,
cf8f0fff
CW
159 ],
160 'pseudoconstant' => [
50fb255d 161 'table' => 'civicrm_country',
162 'keyColumn' => 'id',
163 'labelColumn' => 'name',
164 'nameColumn' => 'iso_code',
8390b11b 165 'abbrColumn' => 'iso_code',
cf8f0fff 166 ],
8390b11b 167 'is_core_field' => TRUE,
50fb255d 168 'FKApiName' => 'Country',
169 'api.required' => '1',
170 'help_pre' => '',
171 'help_post' => '',
50fb255d 172 'weight' => '4',
cf8f0fff
CW
173 'api.aliases' => [],
174 ],
175 'phone-1-1' => [
50fb255d 176 'name' => 'phone',
177 'type' => 2,
178 'title' => 'Phone',
1d8ee3d6 179 'description' => 'Complete phone number.',
50fb255d 180 'maxlength' => 32,
181 'size' => 20,
182 'import' => TRUE,
183 'where' => 'civicrm_phone.phone',
184 'headerPattern' => '/phone/i',
185 'dataPattern' => '/^[\\d\\(\\)\\-\\.\\s]+$/',
186 'export' => TRUE,
1d8ee3d6 187 'table_name' => 'civicrm_phone',
188 'entity' => 'phone',
189 'bao' => 'CRM_Core_BAO_Phone',
8390b11b 190 'localizable' => 0,
cf8f0fff 191 'html' => [
1d8ee3d6 192 'type' => 'Text',
193 'maxlength' => 32,
194 'size' => 20,
cf8f0fff 195 ],
8390b11b 196 'is_core_field' => TRUE,
50fb255d 197 'api.required' => '1',
198 'help_pre' => '',
199 'help_post' => '',
50fb255d 200 'weight' => '5',
cf8f0fff
CW
201 'api.aliases' => [],
202 ],
203 'email-primary' => [
50fb255d 204 'name' => 'email',
205 'type' => 2,
206 'title' => 'Email',
1d8ee3d6 207 'description' => 'Email address',
50fb255d 208 'maxlength' => 254,
1d8ee3d6 209 'size' => 30,
50fb255d 210 'import' => TRUE,
211 'where' => 'civicrm_email.email',
212 'headerPattern' => '/e.?mail/i',
213 'dataPattern' => '/^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$/',
214 'export' => TRUE,
215 'rule' => 'email',
1d8ee3d6 216 'table_name' => 'civicrm_email',
217 'entity' => 'email',
218 'bao' => 'CRM_Core_BAO_Email',
8390b11b 219 'localizable' => 0,
cf8f0fff 220 'html' => [
50fb255d 221 'type' => 'Text',
1d8ee3d6 222 'maxlength' => 254,
223 'size' => 30,
cf8f0fff 224 ],
8390b11b 225 'is_core_field' => TRUE,
50fb255d 226 'api.required' => '1',
227 'help_pre' => '',
228 'help_post' => '',
50fb255d 229 'weight' => '6',
cf8f0fff 230 'api.aliases' => [
50fb255d 231 '0' => 'email-Primary',
cf8f0fff
CW
232 ],
233 ],
234 'last_name' => [
50fb255d 235 'name' => 'last_name',
236 'type' => 2,
237 'title' => 'Last Name',
1d8ee3d6 238 'description' => 'Last Name.',
50fb255d 239 'maxlength' => 64,
240 'size' => 30,
241 'import' => TRUE,
242 'where' => 'civicrm_contact.last_name',
243 'headerPattern' => '/^last|(l(ast\\s)?name)$/i',
244 'dataPattern' => '/^\\w+(\\s\\w+)?+$/',
245 'export' => TRUE,
1d8ee3d6 246 'table_name' => 'civicrm_contact',
247 'entity' => 'contact',
248 'bao' => 'CRM_Contact_BAO_Contact',
8390b11b 249 'localizable' => 0,
cf8f0fff 250 'html' => [
50fb255d 251 'type' => 'Text',
1d8ee3d6 252 'maxlength' => 64,
253 'size' => 30,
cf8f0fff 254 ],
8390b11b 255 'is_core_field' => TRUE,
50fb255d 256 'api.required' => '1',
257 'help_pre' => '',
258 'help_post' => '',
50fb255d 259 'weight' => '7',
cf8f0fff
CW
260 'api.aliases' => [],
261 ],
262 'first_name' => [
50fb255d 263 'name' => 'first_name',
264 'type' => 2,
265 'title' => 'First Name',
1d8ee3d6 266 'description' => 'First Name.',
50fb255d 267 'maxlength' => 64,
268 'size' => 30,
269 'import' => TRUE,
270 'where' => 'civicrm_contact.first_name',
271 'headerPattern' => '/^first|(f(irst\\s)?name)$/i',
272 'dataPattern' => '/^\\w+$/',
273 'export' => TRUE,
1d8ee3d6 274 'table_name' => 'civicrm_contact',
275 'entity' => 'contact',
276 'bao' => 'CRM_Contact_BAO_Contact',
8390b11b 277 'localizable' => 0,
cf8f0fff 278 'html' => [
50fb255d 279 'type' => 'Text',
1d8ee3d6 280 'maxlength' => 64,
281 'size' => 30,
cf8f0fff 282 ],
8390b11b 283 'is_core_field' => TRUE,
50fb255d 284 'api.required' => '1',
285 'help_pre' => '',
286 'help_post' => '',
50fb255d 287 'weight' => '8',
cf8f0fff
CW
288 'api.aliases' => [],
289 ],
290 'profile_id' => [
50fb255d 291 'api.required' => TRUE,
292 'title' => 'Profile ID',
5c49fee0 293 'name' => 'profile_id',
cf8f0fff
CW
294 ],
295 ],
296 ];
9dec4e61 297
298 return $expectedResult;
299}
300
a828d7b8 301/*
50fb255d 302* This example has been generated from the API test suite.
a828d7b8
CW
303* The test that created it is called "testGetFields"
304* and can be found at:
69d79249 305* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php
9dec4e61 306*
307* You can see the outcome of the API tests at
8390b11b 308* https://test.civicrm.org/job/CiviCRM-Core-Matrix/
9dec4e61 309*
310* To Learn about the API read
8390b11b 311* https://docs.civicrm.org/dev/en/latest/api/
9dec4e61 312*
8390b11b
SL
313* Browse the API on your own site with the API Explorer. It is in the main
314* CiviCRM menu, under: Support > Development > API Explorer.
9dec4e61 315*
316* Read more about testing here
8390b11b 317* https://docs.civicrm.org/dev/en/latest/testing/
9dec4e61 318*
319* API Standards documentation:
8390b11b 320* https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
b259a4ab 321*/