Merge pull request #9648 from MegaphoneJon/CRM-19608
[civicrm-core.git] / api / v3 / examples / Contact / APIChainedArray.php
CommitLineData
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 */
11function contact_get_example() {
12 $params = array(
1d8ee3d6 13 'id' => 3,
50fb255d 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 47function contact_get_expectedresult() {
6a488035 48
edb0d67a 49 $expectedResult = array(
50fb255d 50 'is_error' => 0,
51 'version' => 3,
52 'count' => 1,
1d8ee3d6 53 'id' => 3,
50fb255d 54 'values' => array(
1d8ee3d6 55 '3' => array(
56 'contact_id' => '3',
50fb255d 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' => '',
1d8ee3d6 92 'address_id' => '',
93 'street_address' => '',
50fb255d 94 'supplemental_address_1' => '',
95 'supplemental_address_2' => '',
207f62c6 96 'supplemental_address_3' => '',
50fb255d 97 'city' => '',
98 'postal_code_suffix' => '',
99 'postal_code' => '',
100 'geo_code_1' => '',
101 'geo_code_2' => '',
102 'state_province_id' => '',
103 'country_id' => '',
104 'phone_id' => '',
105 'phone_type_id' => '',
106 'phone' => '',
107 'email_id' => '1',
108 'email' => 'man3@yahoo.com',
109 'on_hold' => 0,
110 'im_id' => '',
111 'provider_id' => '',
112 'im' => '',
113 'worldregion_id' => '',
114 'world_region' => '',
83d02301 115 'languages' => 'English (United States)',
50fb255d 116 'individual_prefix' => '',
117 'individual_suffix' => '',
118 'communication_style' => '',
119 'gender' => '',
120 'state_province_name' => '',
121 'state_province' => '',
122 'country' => '',
1d8ee3d6 123 'id' => '3',
50fb255d 124 'api.website.get' => array(
125 'is_error' => 0,
126 'version' => 3,
127 'count' => 1,
128 'id' => 1,
129 'values' => array(
130 '0' => array(
131 'id' => '1',
1d8ee3d6 132 'contact_id' => '3',
50fb255d 133 'url' => 'http://civicrm.org',
6a488035 134 ),
50fb255d 135 ),
136 ),
137 'api.Contribution.get' => array(
138 'is_error' => 0,
139 'version' => 3,
140 'count' => 1,
141 'id' => 2,
142 'values' => array(
143 '0' => array(
1d8ee3d6 144 'contact_id' => '3',
50fb255d 145 'contact_type' => 'Individual',
146 'contact_sub_type' => '',
147 'sort_name' => 'xyz3, abc3',
148 'display_name' => 'abc3 xyz3',
149 'contribution_id' => '2',
150 'currency' => 'USD',
83d02301
SL
151 'payment_instrument' => 'Credit Card',
152 'payment_instrument_id' => '1',
50fb255d 153 'receive_date' => '2011-01-01 00:00:00',
154 'non_deductible_amount' => '10.00',
155 'total_amount' => '120.00',
156 'fee_amount' => '50.00',
157 'net_amount' => '90.00',
158 'trxn_id' => '12335',
159 'invoice_id' => '67830',
160 'cancel_date' => '',
161 'cancel_reason' => '',
162 'receipt_date' => '',
163 'thankyou_date' => '',
164 'contribution_source' => 'SSF',
165 'amount_level' => '',
1d8ee3d6 166 'contribution_recur_id' => '',
50fb255d 167 'is_test' => 0,
168 'is_pay_later' => 0,
83d02301 169 'contribution_status' => 'Completed',
50fb255d 170 'contribution_status_id' => '1',
1d8ee3d6 171 'contribution_check_number' => '',
50fb255d 172 'contribution_campaign_id' => '',
173 'financial_type_id' => '1',
174 'financial_type' => 'Donation',
50fb255d 175 'product_id' => '',
176 'product_name' => '',
177 'sku' => '',
178 'contribution_product_id' => '',
179 'product_option' => '',
180 'fulfilled_date' => '',
181 'contribution_start_date' => '',
182 'contribution_end_date' => '',
50fb255d 183 'financial_account_id' => '1',
184 'accounting_code' => '4200',
1d8ee3d6 185 'campaign_id' => '',
186 'contribution_campaign_title' => '',
50fb255d 187 'contribution_note' => '',
188 'contribution_batch' => '',
1d8ee3d6 189 'check_number' => '',
83d02301 190 'instrument_id' => '1',
50fb255d 191 'id' => '2',
192 'contribution_type_id' => '1',
6a488035 193 ),
50fb255d 194 ),
195 ),
196 'api.CustomValue.get' => array(
197 'is_error' => 0,
198 'version' => 3,
199 'count' => 0,
200 'values' => array(),
201 ),
202 'api.Note.get' => array(
203 'is_error' => 0,
204 'version' => 3,
205 'count' => 0,
206 'values' => array(),
6a488035 207 ),
50fb255d 208 ),
6a488035 209 ),
50fb255d 210 );
6a488035 211
fb32de45 212 return $expectedResult;
6a488035
TO
213}
214
a828d7b8 215/*
50fb255d 216* This example has been generated from the API test suite.
a828d7b8
CW
217* The test that created it is called "testGetIndividualWithChainedArrays"
218* and can be found at:
69d79249 219* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
6a488035
TO
220*
221* You can see the outcome of the API tests at
69d79249 222* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
223*
224* To Learn about the API read
69d79249 225* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 226*
69d79249 227* Browse the api on your own site with the api explorer
41d4d31f 228* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
229*
230* Read more about testing here
231* http://wiki.civicrm.org/confluence/display/CRM/Testing
232*
233* API Standards documentation:
234* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 235*/