3 * Test Generated example demonstrating the Profile.getfields API.
5 * demonstrates retrieving profile fields passing in an id
10 function profile_getfields_example() {
17 $result = civicrm_api3('Profile', 'getfields', $params);
19 catch (CiviCRM_API3_Exception
$e) {
21 $errorMessage = $e->getMessage();
22 $errorCode = $e->getErrorCode();
23 $errorData = $e->getExtraParams();
26 'error_message' => $errorMessage,
27 'error_code' => $errorCode,
28 'error_data' => $errorData,
36 * Function returns array of result expected from previous function.
41 function profile_getfields_expectedresult() {
43 $expectedResult = array(
49 'label' => '_addCustomFieldToProfile',
50 'groupTitle' => '_addCustomFie',
51 'data_type' => 'String',
52 'html_type' => 'Text',
53 'default_value' => 'defaultValue',
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' => '',
63 'option_group_id' => '',
67 'table_name' => 'civicrm_value__addcustomfie_1',
68 'column_name' => '_addcustomfieldtoprofile_1',
70 'title' => 'first_name',
72 'api.required' => '1',
75 'entity' => 'contact',
77 'api.aliases' => array(),
79 'postal_code-1' => array(
80 'name' => 'postal_code',
82 'title' => 'State Province',
83 'description' => 'Store both US (zip5) AND international postal codes. App is responsible for country/region appropriate validation.',
87 'where' => 'civicrm_address.postal_code',
88 'headerPattern' => '/postal|zip/i',
89 'dataPattern' => '/\\d?\\d{4}(-\\d{4})?/',
91 'table_name' => 'civicrm_address',
92 'entity' => 'address',
93 'bao' => 'CRM_Core_BAO_Address',
103 'api.aliases' => array(),
105 'state_province-1' => array(
106 'name' => 'state_province_id',
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',
115 'type' => 'ChainSelect',
119 'pseudoconstant' => array(
120 'table' => 'civicrm_state_province',
122 'labelColumn' => 'name',
124 'FKApiName' => 'StateProvince',
125 'api.required' => '1',
129 'api.aliases' => array(),
131 'country-1' => array(
132 'name' => 'country_id',
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',
145 'pseudoconstant' => array(
146 'table' => 'civicrm_country',
148 'labelColumn' => 'name',
149 'nameColumn' => 'iso_code',
151 'FKApiName' => 'Country',
152 'api.required' => '1',
156 'api.aliases' => array(),
158 'phone-1-1' => array(
162 'description' => 'Complete phone number.',
166 'where' => 'civicrm_phone.phone',
167 'headerPattern' => '/phone/i',
168 'dataPattern' => '/^[\\d\\(\\)\\-\\.\\s]+$/',
170 'table_name' => 'civicrm_phone',
172 'bao' => 'CRM_Core_BAO_Phone',
178 'api.required' => '1',
182 'api.aliases' => array(),
184 'email-primary' => array(
188 'description' => 'Email address',
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]$/',
197 'table_name' => 'civicrm_email',
199 'bao' => 'CRM_Core_BAO_Email',
205 'api.required' => '1',
209 'api.aliases' => array(
210 '0' => 'email-Primary',
213 'last_name' => array(
214 'name' => 'last_name',
216 'title' => 'Last Name',
217 'description' => 'Last Name.',
221 'where' => 'civicrm_contact.last_name',
222 'headerPattern' => '/^last|(l(ast\\s)?name)$/i',
223 'dataPattern' => '/^\\w+(\\s\\w+)?+$/',
225 'table_name' => 'civicrm_contact',
226 'entity' => 'contact',
227 'bao' => 'CRM_Contact_BAO_Contact',
233 'api.required' => '1',
237 'api.aliases' => array(),
239 'first_name' => array(
240 'name' => 'first_name',
242 'title' => 'First Name',
243 'description' => 'First Name.',
247 'where' => 'civicrm_contact.first_name',
248 'headerPattern' => '/^first|(f(irst\\s)?name)$/i',
249 'dataPattern' => '/^\\w+$/',
251 'table_name' => 'civicrm_contact',
252 'entity' => 'contact',
253 'bao' => 'CRM_Contact_BAO_Contact',
259 'api.required' => '1',
263 'api.aliases' => array(),
265 'profile_id' => array(
266 'api.required' => TRUE,
267 'title' => 'Profile ID',
268 'name' => 'profile_id',
273 return $expectedResult;
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
282 * You can see the outcome of the API tests at
283 * https://test.civicrm.org/job/CiviCRM-master-git/
285 * To Learn about the API read
286 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
288 * Browse the api on your own site with the api explorer
289 * http://MYSITE.ORG/path/to/civicrm/api
291 * Read more about testing here
292 * http://wiki.civicrm.org/confluence/display/CRM/Testing
294 * API Standards documentation:
295 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards