Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
3 | * Test Generated example of using contact get API. | |
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{ |
23 | $result = civicrm_api3('contact', 'get', $params); | |
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( | |
31 | 'error' => $errorMessage, | |
32 | 'error_code' => $errorCode, | |
33 | 'error_data' => $errorData, | |
34 | ); | |
35 | } | |
6a488035 | 36 | |
50fb255d | 37 | return $result; |
6a488035 TO |
38 | } |
39 | ||
fb32de45 | 40 | /** |
50fb255d | 41 | * Function returns array of result expected from previous function. |
42 | * | |
43 | * @return array | |
44 | * API result array | |
6a488035 | 45 | */ |
50fb255d | 46 | function contact_get_expectedresult() { |
6a488035 | 47 | |
edb0d67a | 48 | $expectedResult = array( |
50fb255d | 49 | 'is_error' => 0, |
50 | 'version' => 3, | |
51 | 'count' => 1, | |
52 | 'id' => 1, | |
53 | 'values' => array( | |
edb0d67a | 54 | '1' => array( |
50fb255d | 55 | 'contact_id' => '1', |
56 | 'contact_type' => 'Individual', | |
57 | 'contact_sub_type' => '', | |
58 | 'sort_name' => 'xyz3, abc3', | |
59 | 'display_name' => 'abc3 xyz3', | |
60 | 'do_not_email' => 0, | |
61 | 'do_not_phone' => 0, | |
62 | 'do_not_mail' => 0, | |
63 | 'do_not_sms' => 0, | |
64 | 'do_not_trade' => 0, | |
65 | 'is_opt_out' => 0, | |
66 | 'legal_identifier' => '', | |
67 | 'external_identifier' => '', | |
68 | 'nick_name' => '', | |
69 | 'legal_name' => '', | |
70 | 'image_URL' => '', | |
71 | 'preferred_communication_method' => '', | |
72 | 'preferred_language' => 'en_US', | |
73 | 'preferred_mail_format' => 'Both', | |
74 | 'first_name' => 'abc3', | |
75 | 'middle_name' => '', | |
76 | 'last_name' => 'xyz3', | |
77 | 'prefix_id' => '', | |
78 | 'suffix_id' => '', | |
79 | 'formal_title' => '', | |
80 | 'communication_style_id' => '', | |
81 | 'job_title' => '', | |
82 | 'gender_id' => '', | |
83 | 'birth_date' => '', | |
84 | 'is_deceased' => 0, | |
85 | 'deceased_date' => '', | |
86 | 'household_name' => '', | |
87 | 'organization_name' => '', | |
88 | 'sic_code' => '', | |
89 | 'contact_is_deleted' => 0, | |
90 | 'current_employer' => '', | |
91 | 'address_id' => '2', | |
92 | 'street_address' => '1 my road', | |
93 | 'supplemental_address_1' => '', | |
94 | 'supplemental_address_2' => '', | |
95 | 'city' => '', | |
96 | 'postal_code_suffix' => '', | |
97 | 'postal_code' => '', | |
98 | 'geo_code_1' => '', | |
99 | 'geo_code_2' => '', | |
100 | 'state_province_id' => '', | |
101 | 'country_id' => '', | |
102 | 'phone_id' => '', | |
103 | 'phone_type_id' => '', | |
104 | 'phone' => '', | |
105 | 'email_id' => '1', | |
106 | 'email' => 'man3@yahoo.com', | |
107 | 'on_hold' => 0, | |
108 | 'im_id' => '', | |
109 | 'provider_id' => '', | |
110 | 'im' => '', | |
111 | 'worldregion_id' => '', | |
112 | 'world_region' => '', | |
113 | 'individual_prefix' => '', | |
114 | 'individual_suffix' => '', | |
115 | 'communication_style' => '', | |
116 | 'gender' => '', | |
117 | 'state_province_name' => '', | |
118 | 'state_province' => '', | |
119 | 'country' => '', | |
120 | 'id' => '1', | |
121 | 'api.website.get' => array( | |
122 | 'is_error' => 0, | |
123 | 'version' => 3, | |
124 | 'count' => 1, | |
125 | 'id' => 1, | |
126 | 'values' => array( | |
127 | '0' => array( | |
128 | 'id' => '1', | |
129 | 'contact_id' => '1', | |
130 | 'url' => 'http://civicrm.org', | |
6a488035 | 131 | ), |
50fb255d | 132 | ), |
133 | ), | |
134 | 'api.Contribution.get' => array( | |
135 | 'is_error' => 0, | |
136 | 'version' => 3, | |
137 | 'count' => 1, | |
138 | 'id' => 2, | |
139 | 'values' => array( | |
140 | '0' => array( | |
141 | 'contact_id' => '1', | |
142 | 'contact_type' => 'Individual', | |
143 | 'contact_sub_type' => '', | |
144 | 'sort_name' => 'xyz3, abc3', | |
145 | 'display_name' => 'abc3 xyz3', | |
146 | 'contribution_id' => '2', | |
147 | 'currency' => 'USD', | |
148 | 'receive_date' => '2011-01-01 00:00:00', | |
149 | 'non_deductible_amount' => '10.00', | |
150 | 'total_amount' => '120.00', | |
151 | 'fee_amount' => '50.00', | |
152 | 'net_amount' => '90.00', | |
153 | 'trxn_id' => '12335', | |
154 | 'invoice_id' => '67830', | |
155 | 'cancel_date' => '', | |
156 | 'cancel_reason' => '', | |
157 | 'receipt_date' => '', | |
158 | 'thankyou_date' => '', | |
159 | 'contribution_source' => 'SSF', | |
160 | 'amount_level' => '', | |
161 | 'is_test' => 0, | |
162 | 'is_pay_later' => 0, | |
163 | 'contribution_status_id' => '1', | |
164 | 'check_number' => '', | |
165 | 'contribution_campaign_id' => '', | |
166 | 'financial_type_id' => '1', | |
167 | 'financial_type' => 'Donation', | |
50fb255d | 168 | 'product_id' => '', |
169 | 'product_name' => '', | |
170 | 'sku' => '', | |
171 | 'contribution_product_id' => '', | |
172 | 'product_option' => '', | |
173 | 'fulfilled_date' => '', | |
174 | 'contribution_start_date' => '', | |
175 | 'contribution_end_date' => '', | |
176 | 'contribution_recur_id' => '', | |
177 | 'financial_account_id' => '1', | |
178 | 'accounting_code' => '4200', | |
179 | 'contribution_note' => '', | |
180 | 'contribution_batch' => '', | |
181 | 'contribution_status' => 'Completed', | |
381fa321 | 182 | 'payment_instrument' => 'Credit Card', |
183 | 'payment_instrument_id' => '1', | |
184 | 'instrument_id' => '1', | |
50fb255d | 185 | 'contribution_check_number' => '', |
186 | 'id' => '2', | |
187 | 'contribution_type_id' => '1', | |
6a488035 | 188 | ), |
50fb255d | 189 | ), |
190 | ), | |
191 | 'api.CustomValue.get' => array( | |
192 | 'is_error' => 0, | |
193 | 'version' => 3, | |
194 | 'count' => 0, | |
195 | 'values' => array(), | |
196 | ), | |
197 | 'api.Note.get' => array( | |
198 | 'is_error' => 0, | |
199 | 'version' => 3, | |
200 | 'count' => 0, | |
201 | 'values' => array(), | |
6a488035 | 202 | ), |
50fb255d | 203 | ), |
6a488035 | 204 | ), |
50fb255d | 205 | ); |
6a488035 | 206 | |
fb32de45 | 207 | return $expectedResult; |
6a488035 TO |
208 | } |
209 | ||
50fb255d | 210 | /** |
211 | * This example has been generated from the API test suite. | |
212 | * The test that created it is called | |
213 | * testGetIndividualWithChainedArrays | |
214 | * and can be found in | |
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 | */ |