| 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 = [ |
| 12 | 'action' => 'submit', |
| 13 | 'profile_id' => 22, |
| 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 [ |
| 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 = [ |
| 44 | 'is_error' => 0, |
| 45 | 'version' => 3, |
| 46 | 'count' => 9, |
| 47 | 'values' => [ |
| 48 | 'custom_1' => [ |
| 49 | 'id' => '1', |
| 50 | 'label' => '_addCustomFieldToProfile', |
| 51 | 'headerPattern' => '//', |
| 52 | 'title' => 'first_name', |
| 53 | 'custom_field_id' => '1', |
| 54 | 'groupTitle' => '_addCustomFieldToProfile', |
| 55 | 'data_type' => 'String', |
| 56 | 'name' => 'custom_1', |
| 57 | 'type' => 2, |
| 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, |
| 73 | 'table_name' => 'civicrm_value__addcustomfie_1', |
| 74 | 'column_name' => '_addcustomfieldtoprofile_1', |
| 75 | 'where' => 'civicrm_value__addcustomfie_1._addcustomfieldtoprofile_1', |
| 76 | 'extends_table' => 'civicrm_contact', |
| 77 | 'search_table' => 'contact_a', |
| 78 | 'api.required' => '1', |
| 79 | 'help_pre' => '', |
| 80 | 'help_post' => '', |
| 81 | 'entity' => 'contact', |
| 82 | 'weight' => '1', |
| 83 | 'api.aliases' => [], |
| 84 | ], |
| 85 | 'postal_code-1' => [ |
| 86 | 'name' => 'postal_code', |
| 87 | 'type' => 2, |
| 88 | 'title' => 'State Province', |
| 89 | 'description' => 'Store both US (zip5) AND international postal codes. App is responsible for country/region appropriate validation.', |
| 90 | 'maxlength' => 64, |
| 91 | 'size' => 6, |
| 92 | 'import' => TRUE, |
| 93 | 'where' => 'civicrm_address.postal_code', |
| 94 | 'headerPattern' => '/postal|zip/i', |
| 95 | 'dataPattern' => '/\\d?\\d{4}(-\\d{4})?/', |
| 96 | 'export' => TRUE, |
| 97 | 'table_name' => 'civicrm_address', |
| 98 | 'entity' => 'address', |
| 99 | 'bao' => 'CRM_Core_BAO_Address', |
| 100 | 'localizable' => 0, |
| 101 | 'html' => [ |
| 102 | 'type' => 'Text', |
| 103 | 'maxlength' => 64, |
| 104 | 'size' => 6, |
| 105 | ], |
| 106 | 'is_core_field' => TRUE, |
| 107 | 'api.required' => 0, |
| 108 | 'help_pre' => '', |
| 109 | 'help_post' => '', |
| 110 | 'weight' => '2', |
| 111 | 'api.aliases' => [], |
| 112 | ], |
| 113 | 'state_province-1' => [ |
| 114 | 'name' => 'state_province_id', |
| 115 | 'type' => 1, |
| 116 | 'title' => 'State Province', |
| 117 | 'description' => 'Which State_Province does this address belong to.', |
| 118 | 'where' => 'civicrm_address.state_province_id', |
| 119 | 'table_name' => 'civicrm_address', |
| 120 | 'entity' => 'address', |
| 121 | 'bao' => 'CRM_Core_BAO_Address', |
| 122 | 'localizable' => 0, |
| 123 | 'localize_context' => 'province', |
| 124 | 'FKClassName' => 'CRM_Core_DAO_StateProvince', |
| 125 | 'html' => [ |
| 126 | 'type' => 'ChainSelect', |
| 127 | 'size' => 6, |
| 128 | 'maxlength' => 14, |
| 129 | ], |
| 130 | 'pseudoconstant' => [ |
| 131 | 'table' => 'civicrm_state_province', |
| 132 | 'keyColumn' => 'id', |
| 133 | 'labelColumn' => 'name', |
| 134 | ], |
| 135 | 'is_core_field' => TRUE, |
| 136 | 'FKApiName' => 'StateProvince', |
| 137 | 'api.required' => '1', |
| 138 | 'help_pre' => '', |
| 139 | 'help_post' => '', |
| 140 | 'weight' => '3', |
| 141 | 'api.aliases' => [], |
| 142 | ], |
| 143 | 'country-1' => [ |
| 144 | 'name' => 'country_id', |
| 145 | 'type' => 1, |
| 146 | 'title' => 'Country', |
| 147 | 'description' => 'Which Country does this address belong to.', |
| 148 | 'where' => 'civicrm_address.country_id', |
| 149 | 'table_name' => 'civicrm_address', |
| 150 | 'entity' => 'address', |
| 151 | 'bao' => 'CRM_Core_BAO_Address', |
| 152 | 'localizable' => 0, |
| 153 | 'localize_context' => 'country', |
| 154 | 'FKClassName' => 'CRM_Core_DAO_Country', |
| 155 | 'html' => [ |
| 156 | 'type' => 'Select', |
| 157 | 'size' => 6, |
| 158 | 'maxlength' => 14, |
| 159 | ], |
| 160 | 'pseudoconstant' => [ |
| 161 | 'table' => 'civicrm_country', |
| 162 | 'keyColumn' => 'id', |
| 163 | 'labelColumn' => 'name', |
| 164 | 'nameColumn' => 'iso_code', |
| 165 | 'abbrColumn' => 'iso_code', |
| 166 | ], |
| 167 | 'is_core_field' => TRUE, |
| 168 | 'FKApiName' => 'Country', |
| 169 | 'api.required' => '1', |
| 170 | 'help_pre' => '', |
| 171 | 'help_post' => '', |
| 172 | 'weight' => '4', |
| 173 | 'api.aliases' => [], |
| 174 | ], |
| 175 | 'phone-1-1' => [ |
| 176 | 'name' => 'phone', |
| 177 | 'type' => 2, |
| 178 | 'title' => 'Phone', |
| 179 | 'description' => 'Complete phone number.', |
| 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, |
| 187 | 'table_name' => 'civicrm_phone', |
| 188 | 'entity' => 'phone', |
| 189 | 'bao' => 'CRM_Core_BAO_Phone', |
| 190 | 'localizable' => 0, |
| 191 | 'html' => [ |
| 192 | 'type' => 'Text', |
| 193 | 'maxlength' => 32, |
| 194 | 'size' => 20, |
| 195 | ], |
| 196 | 'is_core_field' => TRUE, |
| 197 | 'api.required' => '1', |
| 198 | 'help_pre' => '', |
| 199 | 'help_post' => '', |
| 200 | 'weight' => '5', |
| 201 | 'api.aliases' => [], |
| 202 | ], |
| 203 | 'email-primary' => [ |
| 204 | 'name' => 'email', |
| 205 | 'type' => 2, |
| 206 | 'title' => 'Email', |
| 207 | 'description' => 'Email address', |
| 208 | 'maxlength' => 254, |
| 209 | 'size' => 30, |
| 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', |
| 216 | 'table_name' => 'civicrm_email', |
| 217 | 'entity' => 'email', |
| 218 | 'bao' => 'CRM_Core_BAO_Email', |
| 219 | 'localizable' => 0, |
| 220 | 'html' => [ |
| 221 | 'type' => 'Text', |
| 222 | 'maxlength' => 254, |
| 223 | 'size' => 30, |
| 224 | ], |
| 225 | 'is_core_field' => TRUE, |
| 226 | 'api.required' => '1', |
| 227 | 'help_pre' => '', |
| 228 | 'help_post' => '', |
| 229 | 'weight' => '6', |
| 230 | 'api.aliases' => [ |
| 231 | '0' => 'email-Primary', |
| 232 | ], |
| 233 | ], |
| 234 | 'last_name' => [ |
| 235 | 'name' => 'last_name', |
| 236 | 'type' => 2, |
| 237 | 'title' => 'Last Name', |
| 238 | 'description' => 'Last Name.', |
| 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, |
| 246 | 'table_name' => 'civicrm_contact', |
| 247 | 'entity' => 'contact', |
| 248 | 'bao' => 'CRM_Contact_BAO_Contact', |
| 249 | 'localizable' => 0, |
| 250 | 'html' => [ |
| 251 | 'type' => 'Text', |
| 252 | 'maxlength' => 64, |
| 253 | 'size' => 30, |
| 254 | ], |
| 255 | 'is_core_field' => TRUE, |
| 256 | 'api.required' => '1', |
| 257 | 'help_pre' => '', |
| 258 | 'help_post' => '', |
| 259 | 'weight' => '7', |
| 260 | 'api.aliases' => [], |
| 261 | ], |
| 262 | 'first_name' => [ |
| 263 | 'name' => 'first_name', |
| 264 | 'type' => 2, |
| 265 | 'title' => 'First Name', |
| 266 | 'description' => 'First Name.', |
| 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, |
| 274 | 'table_name' => 'civicrm_contact', |
| 275 | 'entity' => 'contact', |
| 276 | 'bao' => 'CRM_Contact_BAO_Contact', |
| 277 | 'localizable' => 0, |
| 278 | 'html' => [ |
| 279 | 'type' => 'Text', |
| 280 | 'maxlength' => 64, |
| 281 | 'size' => 30, |
| 282 | ], |
| 283 | 'is_core_field' => TRUE, |
| 284 | 'api.required' => '1', |
| 285 | 'help_pre' => '', |
| 286 | 'help_post' => '', |
| 287 | 'weight' => '8', |
| 288 | 'api.aliases' => [], |
| 289 | ], |
| 290 | 'profile_id' => [ |
| 291 | 'api.required' => TRUE, |
| 292 | 'title' => 'Profile ID', |
| 293 | 'name' => 'profile_id', |
| 294 | ], |
| 295 | ], |
| 296 | ]; |
| 297 | |
| 298 | return $expectedResult; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * This example has been generated from the API test suite. |
| 303 | * The test that created it is called "testGetFields" |
| 304 | * and can be found at: |
| 305 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php |
| 306 | * |
| 307 | * You can see the outcome of the API tests at |
| 308 | * https://test.civicrm.org/job/CiviCRM-Core-Matrix/ |
| 309 | * |
| 310 | * To Learn about the API read |
| 311 | * https://docs.civicrm.org/dev/en/latest/api/ |
| 312 | * |
| 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. |
| 315 | * |
| 316 | * Read more about testing here |
| 317 | * https://docs.civicrm.org/dev/en/latest/testing/ |
| 318 | * |
| 319 | * API Standards documentation: |
| 320 | * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/ |
| 321 | */ |