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