Merge pull request #2749 from monishdeb/HR-317
[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' => '',
6a488035
TO
88 'email_greeting_id' => '1',
89 'email_greeting_custom' => '',
90 'email_greeting_display' => '',
91 'postal_greeting_id' => '1',
92 'postal_greeting_custom' => '',
93 'postal_greeting_display' => '',
94 'addressee_id' => '1',
95 'addressee_custom' => '',
96 'addressee_display' => '',
97 'job_title' => '',
98 'gender_id' => '',
99 'birth_date' => '',
100 'is_deceased' => 0,
101 'deceased_date' => '',
102 'household_name' => '',
103 'primary_contact_id' => '',
104 'organization_name' => '',
105 'sic_code' => '',
106 'user_unique_id' => '',
f27f2724 107 'created_date' => '2013-07-28 08:49:19',
6a488035 108 'modified_date' => '2012-11-14 16:02:35',
edb0d67a 109 'api.contribution.create' => array(
6a488035
TO
110 'is_error' => 0,
111 'version' => 3,
112 'count' => 1,
113 'id' => 1,
edb0d67a 114 'values' => array(
115 '0' => array(
6a488035
TO
116 'id' => '1',
117 'contact_id' => '1',
118 'financial_type_id' => '1',
119 'contribution_page_id' => '',
120 'payment_instrument_id' => '1',
121 'receive_date' => '20100101000000',
122 'non_deductible_amount' => '10',
123 'total_amount' => '100',
124 'fee_amount' => '50',
125 'net_amount' => '90',
126 'trxn_id' => '12345',
127 'invoice_id' => '67890',
128 'currency' => 'USD',
129 'cancel_date' => '',
130 'cancel_reason' => '',
131 'receipt_date' => '',
132 'thankyou_date' => '',
133 'source' => 'SSF',
134 'amount_level' => '',
135 'contribution_recur_id' => '',
136 'honor_contact_id' => '',
137 'is_test' => '',
138 'is_pay_later' => '',
139 'contribution_status_id' => '1',
140 'honor_type_id' => '',
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*/