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