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