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