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