3 * Test Generated example of using profile getfields API
4 * demonstrates retrieving profile fields passing in an id *
6 function profile_getfields_example(){
13 $result = civicrm_api3('profile', 'getfields', $params);
15 catch (CiviCRM_API3_Exception
$e) {
17 $errorMessage = $e->getMessage();
18 $errorCode = $e->getErrorCode();
19 $errorData = $e->getExtraParams();
20 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
27 * Function returns array of result expected from previous function
29 function profile_getfields_expectedresult(){
31 $expectedResult = array(
36 'first_name' => array(
37 'api.required' => '1',
38 'title' => 'First Name',
41 'entity' => 'Contact',
42 'name' => 'first_name',
47 'where' => 'civicrm_contact.first_name',
48 'headerPattern' => '/^first|(f(irst\s)?name)$/i',
49 'dataPattern' => '/^\w+$/',
53 'api.required' => '1',
54 'title' => 'Last Name',
57 'entity' => 'Contact',
58 'name' => 'last_name',
63 'where' => 'civicrm_contact.last_name',
64 'headerPattern' => '/^last|(l(ast\s)?name)$/i',
65 'dataPattern' => '/^\w+(\s\w+)?+$/',
68 'email-primary' => array(
74 'api.aliases' => array(
75 '0' => 'email-Primary',
82 'where' => 'civicrm_email.email',
83 'headerPattern' => '/e.?mail/i',
84 '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]$/',
99 'where' => 'civicrm_phone.phone',
100 'headerPattern' => '/phone/i',
101 'dataPattern' => '/^[\d\(\)\-\.\s]+$/',
104 'country-1' => array(
105 'api.required' => '1',
106 'title' => 'Country',
109 'entity' => 'Address',
110 'name' => 'country_id',
112 'FKClassName' => 'CRM_Core_DAO_Country',
113 'pseudoconstant' => array(
114 'table' => 'civicrm_country',
116 'labelColumn' => 'name',
117 'nameColumn' => 'iso_code',
120 'state_province-1' => array(
121 'api.required' => '1',
125 'entity' => 'Address',
126 'name' => 'state_province_id',
128 'FKClassName' => 'CRM_Core_DAO_StateProvince',
129 'pseudoconstant' => array(
130 'table' => 'civicrm_state_province',
132 'labelColumn' => 'name',
135 'postal_code-1' => array(
137 'title' => 'Postal Code',
140 'entity' => 'Address',
141 'name' => 'postal_code',
146 'where' => 'civicrm_address.postal_code',
147 'headerPattern' => '/postal|zip/i',
148 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
152 'api.required' => '1',
153 'title' => 'first_name',
156 'entity' => 'Contact',
157 'label' => '_addCustomFieldToProfile',
158 'groupTitle' => '_addCustomFie',
159 'data_type' => 'String',
160 'html_type' => 'Text',
161 'default_value' => 'defaultValue',
163 'options_per_line' => '',
164 'custom_group_id' => '1',
165 'extends' => 'Contact',
166 'is_search_range' => 0,
167 'extends_entity_column_value' => '',
168 'extends_entity_column_id' => '',
171 'option_group_id' => '',
174 'name' => 'custom_1',
177 'profile_id' => array(
178 'api.required' => true,
183 return $expectedResult;
188 * This example has been generated from the API test suite. The test that created it is called
190 * testGetFields and can be found in
191 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ProfileTest.php
193 * You can see the outcome of the API tests at
194 * http://tests.dev.civicrm.org/trunk/results-api_v3
196 * To Learn about the API read
197 * http://book.civicrm.org/developer/current/techniques/api/
199 * and review the wiki at
200 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
202 * Read more about testing here
203 * http://wiki.civicrm.org/confluence/display/CRM/Testing
205 * API Standards documentation:
206 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards