Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Contact.getsingle API. |
50fb255d | 4 | * |
fb32de45 | 5 | * This demonstrates use of the 'format.single_entity_array' param. |
5c49fee0 CW |
6 | * This param causes the only contact to be returned as an array without the other levels. |
7 | * It will be ignored if there is not exactly 1 result | |
50fb255d | 8 | * |
9 | * @return array | |
10 | * API result array | |
6a488035 | 11 | */ |
50fb255d | 12 | function contact_getsingle_example() { |
13 | $params = array( | |
14 | 'id' => 17, | |
15 | ); | |
6a488035 | 16 | |
50fb255d | 17 | try{ |
a828d7b8 | 18 | $result = civicrm_api3('Contact', 'getsingle', $params); |
50fb255d | 19 | } |
20 | catch (CiviCRM_API3_Exception $e) { | |
21 | // Handle error here. | |
22 | $errorMessage = $e->getMessage(); | |
23 | $errorCode = $e->getErrorCode(); | |
24 | $errorData = $e->getExtraParams(); | |
25 | return array( | |
26 | 'error' => $errorMessage, | |
27 | 'error_code' => $errorCode, | |
28 | 'error_data' => $errorData, | |
29 | ); | |
30 | } | |
6a488035 | 31 | |
50fb255d | 32 | return $result; |
6a488035 TO |
33 | } |
34 | ||
fb32de45 | 35 | /** |
50fb255d | 36 | * Function returns array of result expected from previous function. |
37 | * | |
38 | * @return array | |
39 | * API result array | |
6a488035 | 40 | */ |
50fb255d | 41 | function contact_getsingle_expectedresult() { |
6a488035 | 42 | |
edb0d67a | 43 | $expectedResult = array( |
50fb255d | 44 | 'contact_id' => '17', |
45 | 'contact_type' => 'Individual', | |
46 | 'contact_sub_type' => '', | |
47 | 'sort_name' => '', | |
48 | 'display_name' => 'Test Contact', | |
49 | 'do_not_email' => '', | |
50 | 'do_not_phone' => '', | |
51 | 'do_not_mail' => '', | |
52 | 'do_not_sms' => '', | |
53 | 'do_not_trade' => '', | |
54 | 'is_opt_out' => 0, | |
55 | 'legal_identifier' => '', | |
56 | 'external_identifier' => '', | |
57 | 'nick_name' => '', | |
58 | 'legal_name' => '', | |
59 | 'image_URL' => '', | |
60 | 'preferred_communication_method' => '', | |
61 | 'preferred_language' => '', | |
62 | 'preferred_mail_format' => '', | |
63 | 'first_name' => 'Test', | |
64 | 'middle_name' => '', | |
65 | 'last_name' => 'Contact', | |
66 | 'prefix_id' => '', | |
67 | 'suffix_id' => '', | |
68 | 'formal_title' => '', | |
69 | 'communication_style_id' => '', | |
70 | 'job_title' => '', | |
71 | 'gender_id' => '', | |
72 | 'birth_date' => '', | |
73 | 'is_deceased' => 0, | |
74 | 'deceased_date' => '', | |
75 | 'household_name' => '', | |
76 | 'organization_name' => '', | |
77 | 'sic_code' => '', | |
78 | 'contact_is_deleted' => 0, | |
79 | 'current_employer' => '', | |
80 | 'address_id' => '', | |
81 | 'street_address' => '', | |
82 | 'supplemental_address_1' => '', | |
83 | 'supplemental_address_2' => '', | |
84 | 'city' => '', | |
85 | 'postal_code_suffix' => '', | |
86 | 'postal_code' => '', | |
87 | 'geo_code_1' => '', | |
88 | 'geo_code_2' => '', | |
89 | 'state_province_id' => '', | |
90 | 'country_id' => '', | |
91 | 'phone_id' => '', | |
92 | 'phone_type_id' => '', | |
93 | 'phone' => '', | |
94 | 'email_id' => '', | |
95 | 'email' => '', | |
96 | 'on_hold' => '', | |
97 | 'im_id' => '', | |
98 | 'provider_id' => '', | |
99 | 'im' => '', | |
100 | 'worldregion_id' => '', | |
101 | 'world_region' => '', | |
102 | 'individual_prefix' => '', | |
103 | 'individual_suffix' => '', | |
104 | 'communication_style' => '', | |
105 | 'gender' => '', | |
106 | 'state_province_name' => '', | |
107 | 'state_province' => '', | |
108 | 'country' => '', | |
109 | 'id' => '17', | |
110 | ); | |
6a488035 | 111 | |
fb32de45 | 112 | return $expectedResult; |
6a488035 TO |
113 | } |
114 | ||
a828d7b8 | 115 | /* |
50fb255d | 116 | * This example has been generated from the API test suite. |
a828d7b8 CW |
117 | * The test that created it is called "testContactGetSingleEntityArray" |
118 | * and can be found at: | |
69d79249 | 119 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php |
6a488035 TO |
120 | * |
121 | * You can see the outcome of the API tests at | |
69d79249 | 122 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
123 | * |
124 | * To Learn about the API read | |
69d79249 | 125 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 126 | * |
69d79249 | 127 | * Browse the api on your own site with the api explorer |
41d4d31f | 128 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
129 | * |
130 | * Read more about testing here | |
131 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
132 | * | |
133 | * API Standards documentation: | |
134 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 135 | */ |