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