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