Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Contact.get API. |
50fb255d | 4 | * |
5c49fee0 CW |
5 | * This demonstrates the usage of chained api functions. |
6 | * In this case no notes or custom fields have been created. | |
50fb255d | 7 | * |
8 | * @return array | |
9 | * API result array | |
10 | */ | |
11 | function contact_get_example() { | |
12 | $params = array( | |
13 | 'id' => 1, | |
14 | 'api.website.get' => array(), | |
15 | 'api.Contribution.get' => array( | |
6a488035 TO |
16 | 'total_amount' => '120.00', |
17 | ), | |
50fb255d | 18 | 'api.CustomValue.get' => 1, |
19 | 'api.Note.get' => 1, | |
20 | ); | |
6a488035 | 21 | |
50fb255d | 22 | try{ |
a828d7b8 | 23 | $result = civicrm_api3('Contact', 'get', $params); |
50fb255d | 24 | } |
25 | catch (CiviCRM_API3_Exception $e) { | |
26 | // Handle error here. | |
27 | $errorMessage = $e->getMessage(); | |
28 | $errorCode = $e->getErrorCode(); | |
29 | $errorData = $e->getExtraParams(); | |
30 | return array( | |
5be22f39 | 31 | 'is_error' => 1, |
32 | 'error_message' => $errorMessage, | |
50fb255d | 33 | 'error_code' => $errorCode, |
34 | 'error_data' => $errorData, | |
35 | ); | |
36 | } | |
6a488035 | 37 | |
50fb255d | 38 | return $result; |
6a488035 TO |
39 | } |
40 | ||
fb32de45 | 41 | /** |
50fb255d | 42 | * Function returns array of result expected from previous function. |
43 | * | |
44 | * @return array | |
45 | * API result array | |
6a488035 | 46 | */ |
50fb255d | 47 | function contact_get_expectedresult() { |
6a488035 | 48 | |
edb0d67a | 49 | $expectedResult = array( |
50fb255d | 50 | 'is_error' => 0, |
51 | 'version' => 3, | |
52 | 'count' => 1, | |
53 | 'id' => 1, | |
54 | 'values' => array( | |
edb0d67a | 55 | '1' => array( |
50fb255d | 56 | 'contact_id' => '1', |
57 | 'contact_type' => 'Individual', | |
58 | 'contact_sub_type' => '', | |
59 | 'sort_name' => 'xyz3, abc3', | |
60 | 'display_name' => 'abc3 xyz3', | |
61 | 'do_not_email' => 0, | |
62 | 'do_not_phone' => 0, | |
63 | 'do_not_mail' => 0, | |
64 | 'do_not_sms' => 0, | |
65 | 'do_not_trade' => 0, | |
66 | 'is_opt_out' => 0, | |
67 | 'legal_identifier' => '', | |
68 | 'external_identifier' => '', | |
69 | 'nick_name' => '', | |
70 | 'legal_name' => '', | |
71 | 'image_URL' => '', | |
72 | 'preferred_communication_method' => '', | |
73 | 'preferred_language' => 'en_US', | |
74 | 'preferred_mail_format' => 'Both', | |
75 | 'first_name' => 'abc3', | |
76 | 'middle_name' => '', | |
77 | 'last_name' => 'xyz3', | |
78 | 'prefix_id' => '', | |
79 | 'suffix_id' => '', | |
80 | 'formal_title' => '', | |
81 | 'communication_style_id' => '', | |
82 | 'job_title' => '', | |
83 | 'gender_id' => '', | |
84 | 'birth_date' => '', | |
85 | 'is_deceased' => 0, | |
86 | 'deceased_date' => '', | |
87 | 'household_name' => '', | |
88 | 'organization_name' => '', | |
89 | 'sic_code' => '', | |
90 | 'contact_is_deleted' => 0, | |
91 | 'current_employer' => '', | |
92 | 'address_id' => '2', | |
93 | 'street_address' => '1 my road', | |
94 | 'supplemental_address_1' => '', | |
95 | 'supplemental_address_2' => '', | |
96 | 'city' => '', | |
97 | 'postal_code_suffix' => '', | |
98 | 'postal_code' => '', | |
99 | 'geo_code_1' => '', | |
100 | 'geo_code_2' => '', | |
101 | 'state_province_id' => '', | |
102 | 'country_id' => '', | |
103 | 'phone_id' => '', | |
104 | 'phone_type_id' => '', | |
105 | 'phone' => '', | |
106 | 'email_id' => '1', | |
107 | 'email' => 'man3@yahoo.com', | |
108 | 'on_hold' => 0, | |
109 | 'im_id' => '', | |
110 | 'provider_id' => '', | |
111 | 'im' => '', | |
112 | 'worldregion_id' => '', | |
113 | 'world_region' => '', | |
114 | 'individual_prefix' => '', | |
115 | 'individual_suffix' => '', | |
116 | 'communication_style' => '', | |
117 | 'gender' => '', | |
118 | 'state_province_name' => '', | |
119 | 'state_province' => '', | |
120 | 'country' => '', | |
121 | 'id' => '1', | |
122 | 'api.website.get' => array( | |
123 | 'is_error' => 0, | |
124 | 'version' => 3, | |
125 | 'count' => 1, | |
126 | 'id' => 1, | |
127 | 'values' => array( | |
128 | '0' => array( | |
129 | 'id' => '1', | |
130 | 'contact_id' => '1', | |
131 | 'url' => 'http://civicrm.org', | |
6a488035 | 132 | ), |
50fb255d | 133 | ), |
134 | ), | |
135 | 'api.Contribution.get' => array( | |
136 | 'is_error' => 0, | |
137 | 'version' => 3, | |
138 | 'count' => 1, | |
139 | 'id' => 2, | |
140 | 'values' => array( | |
141 | '0' => array( | |
142 | 'contact_id' => '1', | |
143 | 'contact_type' => 'Individual', | |
144 | 'contact_sub_type' => '', | |
145 | 'sort_name' => 'xyz3, abc3', | |
146 | 'display_name' => 'abc3 xyz3', | |
147 | 'contribution_id' => '2', | |
148 | 'currency' => 'USD', | |
149 | 'receive_date' => '2011-01-01 00:00:00', | |
150 | 'non_deductible_amount' => '10.00', | |
151 | 'total_amount' => '120.00', | |
152 | 'fee_amount' => '50.00', | |
153 | 'net_amount' => '90.00', | |
154 | 'trxn_id' => '12335', | |
155 | 'invoice_id' => '67830', | |
156 | 'cancel_date' => '', | |
157 | 'cancel_reason' => '', | |
158 | 'receipt_date' => '', | |
159 | 'thankyou_date' => '', | |
160 | 'contribution_source' => 'SSF', | |
161 | 'amount_level' => '', | |
162 | 'is_test' => 0, | |
163 | 'is_pay_later' => 0, | |
164 | 'contribution_status_id' => '1', | |
165 | 'check_number' => '', | |
166 | 'contribution_campaign_id' => '', | |
167 | 'financial_type_id' => '1', | |
168 | 'financial_type' => 'Donation', | |
50fb255d | 169 | 'product_id' => '', |
170 | 'product_name' => '', | |
171 | 'sku' => '', | |
172 | 'contribution_product_id' => '', | |
173 | 'product_option' => '', | |
174 | 'fulfilled_date' => '', | |
175 | 'contribution_start_date' => '', | |
176 | 'contribution_end_date' => '', | |
177 | 'contribution_recur_id' => '', | |
178 | 'financial_account_id' => '1', | |
179 | 'accounting_code' => '4200', | |
180 | 'contribution_note' => '', | |
181 | 'contribution_batch' => '', | |
182 | 'contribution_status' => 'Completed', | |
381fa321 | 183 | 'payment_instrument' => 'Credit Card', |
184 | 'payment_instrument_id' => '1', | |
185 | 'instrument_id' => '1', | |
50fb255d | 186 | 'contribution_check_number' => '', |
187 | 'id' => '2', | |
188 | 'contribution_type_id' => '1', | |
6a488035 | 189 | ), |
50fb255d | 190 | ), |
191 | ), | |
192 | 'api.CustomValue.get' => array( | |
193 | 'is_error' => 0, | |
194 | 'version' => 3, | |
195 | 'count' => 0, | |
196 | 'values' => array(), | |
197 | ), | |
198 | 'api.Note.get' => array( | |
199 | 'is_error' => 0, | |
200 | 'version' => 3, | |
201 | 'count' => 0, | |
202 | 'values' => array(), | |
6a488035 | 203 | ), |
50fb255d | 204 | ), |
6a488035 | 205 | ), |
50fb255d | 206 | ); |
6a488035 | 207 | |
fb32de45 | 208 | return $expectedResult; |
6a488035 TO |
209 | } |
210 | ||
a828d7b8 | 211 | /* |
50fb255d | 212 | * This example has been generated from the API test suite. |
a828d7b8 CW |
213 | * The test that created it is called "testGetIndividualWithChainedArrays" |
214 | * and can be found at: | |
69d79249 | 215 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php |
6a488035 TO |
216 | * |
217 | * You can see the outcome of the API tests at | |
69d79249 | 218 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
219 | * |
220 | * To Learn about the API read | |
69d79249 | 221 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 222 | * |
69d79249 | 223 | * Browse the api on your own site with the api explorer |
41d4d31f | 224 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
225 | * |
226 | * Read more about testing here | |
227 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
228 | * | |
229 | * API Standards documentation: | |
230 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 231 | */ |