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