Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2014-09-29-13-19-52
[civicrm-core.git] / api / v3 / examples / Contact / ChainTwoWebsitesSyntax2.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using contact create API
4 * demonstrates creating two websites as an array *
6a488035
TO
5 */
6function contact_create_example(){
edb0d67a 7$params = array(
6a488035
TO
8 'first_name' => 'abc3',
9 'last_name' => 'xyz3',
10 'contact_type' => 'Individual',
11 'email' => 'man3@yahoo.com',
edb0d67a 12 'api.contribution.create' => array(
6a488035
TO
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 ),
edb0d67a 25 'api.website.create' => array(
26 '0' => array(
6a488035
TO
27 'url' => 'http://civicrm.org',
28 ),
edb0d67a 29 '1' => array(
6a488035
TO
30 'url' => 'http://chained.org',
31 'website_type_id' => 2,
32 ),
33 ),
34);
35
fb32de45 36try{
37 $result = civicrm_api3('contact', 'create', $params);
38}
39catch (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}
6a488035 46
fb32de45 47return $result;
6a488035
TO
48}
49
fb32de45 50/**
6a488035
TO
51 * Function returns array of result expected from previous function
52 */
53function contact_create_expectedresult(){
54
edb0d67a 55 $expectedResult = array(
6a488035
TO
56 'is_error' => 0,
57 'version' => 3,
58 'count' => 1,
59 'id' => 1,
edb0d67a 60 'values' => array(
61 '1' => array(
6a488035
TO
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',
9f1b81e0 86 'prefix_id' => '',
87 'suffix_id' => '',
89bf81b4 88 'formal_title' => '',
89 'communication_style_id' => '',
6a488035
TO
90 'email_greeting_id' => '1',
91 'email_greeting_custom' => '',
92 'email_greeting_display' => '',
93 'postal_greeting_id' => '1',
94 'postal_greeting_custom' => '',
95 'postal_greeting_display' => '',
96 'addressee_id' => '1',
97 'addressee_custom' => '',
98 'addressee_display' => '',
99 'job_title' => '',
100 'gender_id' => '',
101 'birth_date' => '',
102 'is_deceased' => 0,
103 'deceased_date' => '',
104 'household_name' => '',
105 'primary_contact_id' => '',
106 'organization_name' => '',
107 'sic_code' => '',
108 'user_unique_id' => '',
f27f2724 109 'created_date' => '2013-07-28 08:49:19',
6a488035 110 'modified_date' => '2012-11-14 16:02:35',
edb0d67a 111 'api.contribution.create' => array(
6a488035
TO
112 'is_error' => 0,
113 'version' => 3,
114 'count' => 1,
115 'id' => 1,
edb0d67a 116 'values' => array(
117 '0' => array(
6a488035
TO
118 'id' => '1',
119 'contact_id' => '1',
120 'financial_type_id' => '1',
121 'contribution_page_id' => '',
122 'payment_instrument_id' => '1',
123 'receive_date' => '20100101000000',
124 'non_deductible_amount' => '10',
125 'total_amount' => '100',
126 'fee_amount' => '50',
127 'net_amount' => '90',
128 'trxn_id' => '12345',
129 'invoice_id' => '67890',
130 'currency' => 'USD',
131 'cancel_date' => '',
132 'cancel_reason' => '',
133 'receipt_date' => '',
134 'thankyou_date' => '',
135 'source' => 'SSF',
136 'amount_level' => '',
137 'contribution_recur_id' => '',
6a488035
TO
138 'is_test' => '',
139 'is_pay_later' => '',
140 'contribution_status_id' => '1',
6a488035 141 'address_id' => '',
9f1b81e0 142 'check_number' => '',
6a488035 143 'campaign_id' => '',
edb0d67a 144 'contribution_type_id' => '1',
6a488035
TO
145 ),
146 ),
147 ),
edb0d67a 148 'api.website.create' => array(
149 '0' => array(
6a488035
TO
150 'is_error' => 0,
151 'version' => 3,
152 'count' => 1,
153 'id' => 1,
edb0d67a 154 'values' => array(
155 '0' => array(
6a488035
TO
156 'id' => '1',
157 'contact_id' => '1',
158 'url' => 'http://civicrm.org',
159 'website_type_id' => '',
160 ),
161 ),
162 ),
edb0d67a 163 '1' => array(
6a488035
TO
164 'is_error' => 0,
165 'version' => 3,
166 'count' => 1,
167 'id' => 2,
edb0d67a 168 'values' => array(
169 '0' => array(
6a488035
TO
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
fb32de45 182 return $expectedResult;
6a488035
TO
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
69d79249 190* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
6a488035
TO
191*
192* You can see the outcome of the API tests at
69d79249 193* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
194*
195* To Learn about the API read
69d79249 196* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 197*
69d79249
E
198* Browse the api on your own site with the api explorer
199* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
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
b259a4ab 206*/