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