| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example demonstrating the Contact.get API. |
| 4 | * |
| 5 | * Demonstrates use of Replace in a nested API call. |
| 6 | * |
| 7 | * @return array |
| 8 | * API result array |
| 9 | */ |
| 10 | function contact_get_example() { |
| 11 | $params = array( |
| 12 | 'id' => 10, |
| 13 | 'api.email.replace' => array( |
| 14 | 'values' => array( |
| 15 | '0' => array( |
| 16 | 'location_type_id' => 20, |
| 17 | 'email' => '1-1@example.com', |
| 18 | 'is_primary' => 1, |
| 19 | ), |
| 20 | '1' => array( |
| 21 | 'location_type_id' => 20, |
| 22 | 'email' => '1-2@example.com', |
| 23 | 'is_primary' => 0, |
| 24 | ), |
| 25 | '2' => array( |
| 26 | 'location_type_id' => 20, |
| 27 | 'email' => '1-3@example.com', |
| 28 | 'is_primary' => 0, |
| 29 | ), |
| 30 | '3' => array( |
| 31 | 'location_type_id' => 21, |
| 32 | 'email' => '2-1@example.com', |
| 33 | 'is_primary' => 0, |
| 34 | ), |
| 35 | '4' => array( |
| 36 | 'location_type_id' => 21, |
| 37 | 'email' => '2-2@example.com', |
| 38 | 'is_primary' => 0, |
| 39 | ), |
| 40 | ), |
| 41 | ), |
| 42 | ); |
| 43 | |
| 44 | try{ |
| 45 | $result = civicrm_api3('Contact', 'get', $params); |
| 46 | } |
| 47 | catch (CiviCRM_API3_Exception $e) { |
| 48 | // Handle error here. |
| 49 | $errorMessage = $e->getMessage(); |
| 50 | $errorCode = $e->getErrorCode(); |
| 51 | $errorData = $e->getExtraParams(); |
| 52 | return array( |
| 53 | 'error' => $errorMessage, |
| 54 | 'error_code' => $errorCode, |
| 55 | 'error_data' => $errorData, |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | return $result; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Function returns array of result expected from previous function. |
| 64 | * |
| 65 | * @return array |
| 66 | * API result array |
| 67 | */ |
| 68 | function contact_get_expectedresult() { |
| 69 | |
| 70 | $expectedResult = array( |
| 71 | 'is_error' => 0, |
| 72 | 'version' => 3, |
| 73 | 'count' => 1, |
| 74 | 'id' => 10, |
| 75 | 'values' => array( |
| 76 | '10' => array( |
| 77 | 'contact_id' => '10', |
| 78 | 'contact_type' => 'Organization', |
| 79 | 'contact_sub_type' => '', |
| 80 | 'sort_name' => 'Unit Test Organization', |
| 81 | 'display_name' => 'Unit Test Organization', |
| 82 | 'do_not_email' => 0, |
| 83 | 'do_not_phone' => 0, |
| 84 | 'do_not_mail' => 0, |
| 85 | 'do_not_sms' => 0, |
| 86 | 'do_not_trade' => 0, |
| 87 | 'is_opt_out' => 0, |
| 88 | 'legal_identifier' => '', |
| 89 | 'external_identifier' => '', |
| 90 | 'nick_name' => '', |
| 91 | 'legal_name' => '', |
| 92 | 'image_URL' => '', |
| 93 | 'preferred_communication_method' => '', |
| 94 | 'preferred_language' => 'en_US', |
| 95 | 'preferred_mail_format' => 'Both', |
| 96 | 'first_name' => '', |
| 97 | 'middle_name' => '', |
| 98 | 'last_name' => '', |
| 99 | 'prefix_id' => '', |
| 100 | 'suffix_id' => '', |
| 101 | 'formal_title' => '', |
| 102 | 'communication_style_id' => '', |
| 103 | 'job_title' => '', |
| 104 | 'gender_id' => '', |
| 105 | 'birth_date' => '', |
| 106 | 'is_deceased' => 0, |
| 107 | 'deceased_date' => '', |
| 108 | 'household_name' => '', |
| 109 | 'organization_name' => 'Unit Test Organization', |
| 110 | 'sic_code' => '', |
| 111 | 'contact_is_deleted' => 0, |
| 112 | 'current_employer' => '', |
| 113 | 'address_id' => '', |
| 114 | 'street_address' => '', |
| 115 | 'supplemental_address_1' => '', |
| 116 | 'supplemental_address_2' => '', |
| 117 | 'city' => '', |
| 118 | 'postal_code_suffix' => '', |
| 119 | 'postal_code' => '', |
| 120 | 'geo_code_1' => '', |
| 121 | 'geo_code_2' => '', |
| 122 | 'state_province_id' => '', |
| 123 | 'country_id' => '', |
| 124 | 'phone_id' => '', |
| 125 | 'phone_type_id' => '', |
| 126 | 'phone' => '', |
| 127 | 'email_id' => '', |
| 128 | 'email' => '', |
| 129 | 'on_hold' => '', |
| 130 | 'im_id' => '', |
| 131 | 'provider_id' => '', |
| 132 | 'im' => '', |
| 133 | 'worldregion_id' => '', |
| 134 | 'world_region' => '', |
| 135 | 'individual_prefix' => '', |
| 136 | 'individual_suffix' => '', |
| 137 | 'communication_style' => '', |
| 138 | 'gender' => '', |
| 139 | 'state_province_name' => '', |
| 140 | 'state_province' => '', |
| 141 | 'country' => '', |
| 142 | 'id' => '10', |
| 143 | 'api.email.replace' => array( |
| 144 | 'is_error' => 0, |
| 145 | 'version' => 3, |
| 146 | 'count' => 5, |
| 147 | 'values' => array( |
| 148 | '0' => array( |
| 149 | 'id' => '18', |
| 150 | 'contact_id' => '10', |
| 151 | 'location_type_id' => '20', |
| 152 | 'email' => '1-1@example.com', |
| 153 | 'is_primary' => '1', |
| 154 | 'is_billing' => '', |
| 155 | 'on_hold' => '', |
| 156 | 'is_bulkmail' => '', |
| 157 | 'hold_date' => '', |
| 158 | 'reset_date' => '', |
| 159 | 'signature_text' => '', |
| 160 | 'signature_html' => '', |
| 161 | ), |
| 162 | '1' => array( |
| 163 | 'id' => '19', |
| 164 | 'contact_id' => '10', |
| 165 | 'location_type_id' => '20', |
| 166 | 'email' => '1-2@example.com', |
| 167 | 'is_primary' => 0, |
| 168 | 'is_billing' => '', |
| 169 | 'on_hold' => '', |
| 170 | 'is_bulkmail' => '', |
| 171 | 'hold_date' => '', |
| 172 | 'reset_date' => '', |
| 173 | 'signature_text' => '', |
| 174 | 'signature_html' => '', |
| 175 | ), |
| 176 | '2' => array( |
| 177 | 'id' => '20', |
| 178 | 'contact_id' => '10', |
| 179 | 'location_type_id' => '20', |
| 180 | 'email' => '1-3@example.com', |
| 181 | 'is_primary' => 0, |
| 182 | 'is_billing' => '', |
| 183 | 'on_hold' => '', |
| 184 | 'is_bulkmail' => '', |
| 185 | 'hold_date' => '', |
| 186 | 'reset_date' => '', |
| 187 | 'signature_text' => '', |
| 188 | 'signature_html' => '', |
| 189 | ), |
| 190 | '3' => array( |
| 191 | 'id' => '21', |
| 192 | 'contact_id' => '10', |
| 193 | 'location_type_id' => '21', |
| 194 | 'email' => '2-1@example.com', |
| 195 | 'is_primary' => 0, |
| 196 | 'is_billing' => '', |
| 197 | 'on_hold' => '', |
| 198 | 'is_bulkmail' => '', |
| 199 | 'hold_date' => '', |
| 200 | 'reset_date' => '', |
| 201 | 'signature_text' => '', |
| 202 | 'signature_html' => '', |
| 203 | ), |
| 204 | '4' => array( |
| 205 | 'id' => '22', |
| 206 | 'contact_id' => '10', |
| 207 | 'location_type_id' => '21', |
| 208 | 'email' => '2-2@example.com', |
| 209 | 'is_primary' => 0, |
| 210 | 'is_billing' => '', |
| 211 | 'on_hold' => '', |
| 212 | 'is_bulkmail' => '', |
| 213 | 'hold_date' => '', |
| 214 | 'reset_date' => '', |
| 215 | 'signature_text' => '', |
| 216 | 'signature_html' => '', |
| 217 | ), |
| 218 | ), |
| 219 | ), |
| 220 | ), |
| 221 | ), |
| 222 | ); |
| 223 | |
| 224 | return $expectedResult; |
| 225 | } |
| 226 | |
| 227 | /* |
| 228 | * This example has been generated from the API test suite. |
| 229 | * The test that created it is called "testReplaceEmailsInChain" |
| 230 | * and can be found at: |
| 231 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/EmailTest.php |
| 232 | * |
| 233 | * You can see the outcome of the API tests at |
| 234 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
| 235 | * |
| 236 | * To Learn about the API read |
| 237 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
| 238 | * |
| 239 | * Browse the api on your own site with the api explorer |
| 240 | * http://MYSITE.ORG/path/to/civicrm/api |
| 241 | * |
| 242 | * Read more about testing here |
| 243 | * http://wiki.civicrm.org/confluence/display/CRM/Testing |
| 244 | * |
| 245 | * API Standards documentation: |
| 246 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards |
| 247 | */ |