update examples"
[civicrm-core.git] / api / v3 / examples / Contact / ChainTwoWebsitesSyntax2.php
1 <?php
2 /**
3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6 */
7
8 /**
9 * Test Generated example of using contact create API.
10 *
11 * demonstrates creating two websites as an array
12 *
13 * @return array
14 * API result array
15 */
16 function contact_create_example() {
17 $params = array(
18 'first_name' => 'abc3',
19 'last_name' => 'xyz3',
20 'contact_type' => 'Individual',
21 'email' => 'man3@yahoo.com',
22 'api.contribution.create' => array(
23 'receive_date' => '2010-01-01',
24 'total_amount' => '100',
25 'financial_type_id' => 1,
26 'payment_instrument_id' => 1,
27 'non_deductible_amount' => '10',
28 'fee_amount' => '50',
29 'net_amount' => '90',
30 'trxn_id' => 12345,
31 'invoice_id' => 67890,
32 'source' => 'SSF',
33 'contribution_status_id' => 1,
34 ),
35 'api.website.create' => array(
36 '0' => array(
37 'url' => 'http://civicrm.org',
38 ),
39 '1' => array(
40 'url' => 'http://chained.org',
41 'website_type_id' => 2,
42 ),
43 ),
44 );
45
46 try{
47 $result = civicrm_api3('contact', 'create', $params);
48 }
49 catch (CiviCRM_API3_Exception $e) {
50 // Handle error here.
51 $errorMessage = $e->getMessage();
52 $errorCode = $e->getErrorCode();
53 $errorData = $e->getExtraParams();
54 return array(
55 'error' => $errorMessage,
56 'error_code' => $errorCode,
57 'error_data' => $errorData,
58 );
59 }
60
61 return $result;
62 }
63
64 /**
65 * Function returns array of result expected from previous function.
66 *
67 * @return array
68 * API result array
69 */
70 function contact_create_expectedresult() {
71
72 $expectedResult = array(
73 'is_error' => 0,
74 'version' => 3,
75 'count' => 1,
76 'id' => 1,
77 'values' => array(
78 '1' => array(
79 'id' => '1',
80 'contact_type' => 'Individual',
81 'contact_sub_type' => '',
82 'do_not_email' => 0,
83 'do_not_phone' => 0,
84 'do_not_mail' => 0,
85 'do_not_sms' => 0,
86 'do_not_trade' => 0,
87 'is_opt_out' => 0,
88 'legal_identifier' => '',
89 'external_identifier' => '',
90 'sort_name' => 'xyz3, abc3',
91 'display_name' => 'abc3 xyz3',
92 'nick_name' => '',
93 'legal_name' => '',
94 'image_URL' => '',
95 'preferred_communication_method' => '',
96 'preferred_language' => 'en_US',
97 'preferred_mail_format' => 'Both',
98 'hash' => '67eac7789eaee00',
99 'api_key' => '',
100 'first_name' => 'abc3',
101 'middle_name' => '',
102 'last_name' => 'xyz3',
103 'prefix_id' => '',
104 'suffix_id' => '',
105 'formal_title' => '',
106 'communication_style_id' => '',
107 'email_greeting_id' => '1',
108 'email_greeting_custom' => '',
109 'email_greeting_display' => '',
110 'postal_greeting_id' => '1',
111 'postal_greeting_custom' => '',
112 'postal_greeting_display' => '',
113 'addressee_id' => '1',
114 'addressee_custom' => '',
115 'addressee_display' => '',
116 'job_title' => '',
117 'gender_id' => '',
118 'birth_date' => '',
119 'is_deceased' => 0,
120 'deceased_date' => '',
121 'household_name' => '',
122 'primary_contact_id' => '',
123 'organization_name' => '',
124 'sic_code' => '',
125 'user_unique_id' => '',
126 'created_date' => '2013-07-28 08:49:19',
127 'modified_date' => '2012-11-14 16:02:35',
128 'api.contribution.create' => array(
129 'is_error' => 0,
130 'version' => 3,
131 'count' => 1,
132 'id' => 1,
133 'values' => array(
134 '0' => array(
135 'id' => '1',
136 'contact_id' => '1',
137 'financial_type_id' => '1',
138 'contribution_page_id' => '',
139 'payment_instrument_id' => '1',
140 'receive_date' => '20100101000000',
141 'non_deductible_amount' => '10',
142 'total_amount' => '100',
143 'fee_amount' => '50',
144 'net_amount' => '90',
145 'trxn_id' => '12345',
146 'invoice_id' => '67890',
147 'currency' => 'USD',
148 'cancel_date' => '',
149 'cancel_reason' => '',
150 'receipt_date' => '',
151 'thankyou_date' => '',
152 'source' => 'SSF',
153 'amount_level' => '',
154 'contribution_recur_id' => '',
155 'is_test' => '',
156 'is_pay_later' => '',
157 'contribution_status_id' => '1',
158 'address_id' => '',
159 'check_number' => '',
160 'campaign_id' => '',
161 'creditnote_id' => '',
162 'tax_amount' => '',
163 'contribution_type_id' => '1',
164 ),
165 ),
166 ),
167 'api.website.create' => array(
168 '0' => array(
169 'is_error' => 0,
170 'version' => 3,
171 'count' => 1,
172 'id' => 1,
173 'values' => array(
174 '0' => array(
175 'id' => '1',
176 'contact_id' => '1',
177 'url' => 'http://civicrm.org',
178 'website_type_id' => '',
179 ),
180 ),
181 ),
182 '1' => array(
183 'is_error' => 0,
184 'version' => 3,
185 'count' => 1,
186 'id' => 2,
187 'values' => array(
188 '0' => array(
189 'id' => '2',
190 'contact_id' => '1',
191 'url' => 'http://chained.org',
192 'website_type_id' => '2',
193 ),
194 ),
195 ),
196 ),
197 ),
198 ),
199 );
200
201 return $expectedResult;
202 }
203
204 /**
205 * This example has been generated from the API test suite.
206 * The test that created it is called
207 * testCreateIndividualWithContributionChainedArrays
208 * and can be found in
209 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
210 *
211 * You can see the outcome of the API tests at
212 * https://test.civicrm.org/job/CiviCRM-master-git/
213 *
214 * To Learn about the API read
215 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
216 *
217 * Browse the api on your own site with the api explorer
218 * http://MYSITE.ORG/path/to/civicrm/api/explorer
219 *
220 * Read more about testing here
221 * http://wiki.civicrm.org/confluence/display/CRM/Testing
222 *
223 * API Standards documentation:
224 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
225 */