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+$/',
51 'api.aliases' => array(),
54 'api.required' => '1',
55 'title' => 'Last Name',
58 'entity' => 'contact',
59 'name' => 'last_name',
64 'where' => 'civicrm_contact.last_name',
65 'headerPattern' => '/^last|(l(ast\s)?name)$/i',
66 'dataPattern' => '/^\w+(\s\w+)?+$/',
68 'api.aliases' => array(),
70 'email-primary' => array(
76 'api.aliases' => array(
77 '0' => 'email-Primary',
84 'where' => 'civicrm_email.email',
85 'headerPattern' => '/e.?mail/i',
86 '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]$/',
101 'where' => 'civicrm_phone.phone',
102 'headerPattern' => '/phone/i',
103 'dataPattern' => '/^[\d\(\)\-\.\s]+$/',
105 'api.aliases' => array(),
107 'country-1' => array(
108 'api.required' => '1',
109 'title' => 'Country',
112 'entity' => 'address',
113 'name' => 'country_id',
115 'FKClassName' => 'CRM_Core_DAO_Country',
116 'pseudoconstant' => array(
117 'table' => 'civicrm_country',
119 'labelColumn' => 'name',
120 'nameColumn' => 'iso_code',
122 'api.aliases' => array(),
124 'state_province-1' => array(
125 'api.required' => '1',
129 'entity' => 'address',
130 'name' => 'state_province_id',
132 'FKClassName' => 'CRM_Core_DAO_StateProvince',
133 'pseudoconstant' => array(
134 'table' => 'civicrm_state_province',
136 'labelColumn' => 'name',
138 'api.aliases' => array(),
140 'postal_code-1' => array(
142 'title' => 'Postal Code',
145 'entity' => 'address',
146 'name' => 'postal_code',
151 'where' => 'civicrm_address.postal_code',
152 'headerPattern' => '/postal|zip/i',
153 'dataPattern' => '/\d?\d{4}(-\d{4})?/',
155 'api.aliases' => array(),
158 'api.required' => '1',
159 'title' => 'first_name',
162 'entity' => 'contact',
163 'label' => '_addCustomFieldToProfile',
164 'groupTitle' => '_addCustomFie',
165 'data_type' => 'String',
166 'html_type' => 'Text',
167 'default_value' => 'defaultValue',
169 'options_per_line' => '',
170 'custom_group_id' => '1',
171 'extends' => 'Contact',
172 'is_search_range' => 0,
173 'extends_entity_column_value' => '',
174 'extends_entity_column_id' => '',
177 'option_group_id' => '',
180 'name' => 'custom_1',
182 'api.aliases' => array(),
184 'profile_id' => array(
185 'api.required' => true,
190 return $expectedResult;
195 * This example has been generated from the API test suite. The test that created it is called
197 * testGetFields and can be found in
198 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ProfileTest.php
200 * You can see the outcome of the API tests at
201 * http://tests.dev.civicrm.org/trunk/results-api_v3
203 * To Learn about the API read
204 * http://book.civicrm.org/developer/current/techniques/api/
206 * and review the wiki at
207 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
209 * Read more about testing here
210 * http://wiki.civicrm.org/confluence/display/CRM/Testing
212 * API Standards documentation:
213 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards