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