Merge pull request #1262 from eileenmcnaughton/CRM-13072-more-upgrades
[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 'email_greeting_id' => '1',
87 'email_greeting_custom' => '',
88 'email_greeting_display' => '',
89 'postal_greeting_id' => '1',
90 'postal_greeting_custom' => '',
91 'postal_greeting_display' => '',
92 'addressee_id' => '1',
93 'addressee_custom' => '',
94 'addressee_display' => '',
95 'job_title' => '',
96 'gender_id' => '',
97 'birth_date' => '',
98 'is_deceased' => 0,
99 'deceased_date' => '',
100 'household_name' => '',
101 'primary_contact_id' => '',
102 'organization_name' => '',
103 'sic_code' => '',
104 'user_unique_id' => '',
105 'created_date' => '2013-07-28 08:49:19',
106 'modified_date' => '2012-11-14 16:02:35',
107 'api.contribution.create' => array(
108 'is_error' => 0,
109 'version' => 3,
110 'count' => 1,
111 'id' => 1,
112 'values' => array(
113 '0' => array(
114 'id' => '1',
115 'contact_id' => '1',
116 'financial_type_id' => '1',
117 'contribution_page_id' => '',
118 'payment_instrument_id' => '1',
119 'receive_date' => '20100101000000',
120 'non_deductible_amount' => '10',
121 'total_amount' => '100',
122 'fee_amount' => '50',
123 'net_amount' => '90',
124 'trxn_id' => '12345',
125 'invoice_id' => '67890',
126 'currency' => 'USD',
127 'cancel_date' => '',
128 'cancel_reason' => '',
129 'receipt_date' => '',
130 'thankyou_date' => '',
131 'source' => 'SSF',
132 'amount_level' => '',
133 'contribution_recur_id' => '',
134 'honor_contact_id' => '',
135 'is_test' => '',
136 'is_pay_later' => '',
137 'contribution_status_id' => '1',
138 'honor_type_id' => '',
139 'address_id' => '',
140 'check_number' => 'null',
141 'campaign_id' => '',
142 'contribution_type_id' => '1',
143 ),
144 ),
145 ),
146 'api.website.create' => array(
147 '0' => array(
148 'is_error' => 0,
149 'version' => 3,
150 'count' => 1,
151 'id' => 1,
152 'values' => array(
153 '0' => array(
154 'id' => '1',
155 'contact_id' => '1',
156 'url' => 'http://civicrm.org',
157 'website_type_id' => '',
158 ),
159 ),
160 ),
161 '1' => array(
162 'is_error' => 0,
163 'version' => 3,
164 'count' => 1,
165 'id' => 2,
166 'values' => array(
167 '0' => array(
168 'id' => '2',
169 'contact_id' => '1',
170 'url' => 'http://chained.org',
171 'website_type_id' => '2',
172 ),
173 ),
174 ),
175 ),
176 ),
177 ),
178 );
179
180 return $expectedResult;
181 }
182
183
184 /*
185 * This example has been generated from the API test suite. The test that created it is called
186 *
187 * testCreateIndividualWithContributionChainedArrays and can be found in
188 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
189 *
190 * You can see the outcome of the API tests at
191 * http://tests.dev.civicrm.org/trunk/results-api_v3
192 *
193 * To Learn about the API read
194 * http://book.civicrm.org/developer/current/techniques/api/
195 *
196 * and review the wiki at
197 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
198 *
199 * Read more about testing here
200 * http://wiki.civicrm.org/confluence/display/CRM/Testing
201 *
202 * API Standards documentation:
203 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
204 */