Merge pull request #11736 from jitendrapurohit/CRM-21815
[civicrm-core.git] / api / v3 / examples / Contact / NestedReplaceEmail.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Contact.get API.
4 *
5 * Demonstrates use of Replace in a nested API call.
6 *
7 * @return array
8 * API result array
9 */
10 function contact_get_example() {
11 $params = array(
12 'id' => 10,
13 'api.email.replace' => array(
14 'values' => array(
15 '0' => array(
16 'location_type_id' => 20,
17 'email' => '1-1@example.com',
18 'is_primary' => 1,
19 ),
20 '1' => array(
21 'location_type_id' => 20,
22 'email' => '1-2@example.com',
23 'is_primary' => 0,
24 ),
25 '2' => array(
26 'location_type_id' => 20,
27 'email' => '1-3@example.com',
28 'is_primary' => 0,
29 ),
30 '3' => array(
31 'location_type_id' => 21,
32 'email' => '2-1@example.com',
33 'is_primary' => 0,
34 ),
35 '4' => array(
36 'location_type_id' => 21,
37 'email' => '2-2@example.com',
38 'is_primary' => 0,
39 ),
40 ),
41 ),
42 );
43
44 try{
45 $result = civicrm_api3('Contact', 'get', $params);
46 }
47 catch (CiviCRM_API3_Exception $e) {
48 // Handle error here.
49 $errorMessage = $e->getMessage();
50 $errorCode = $e->getErrorCode();
51 $errorData = $e->getExtraParams();
52 return array(
53 'is_error' => 1,
54 'error_message' => $errorMessage,
55 'error_code' => $errorCode,
56 'error_data' => $errorData,
57 );
58 }
59
60 return $result;
61 }
62
63 /**
64 * Function returns array of result expected from previous function.
65 *
66 * @return array
67 * API result array
68 */
69 function contact_get_expectedresult() {
70
71 $expectedResult = array(
72 'is_error' => 0,
73 'version' => 3,
74 'count' => 1,
75 'id' => 10,
76 'values' => array(
77 '10' => array(
78 'contact_id' => '10',
79 'contact_type' => 'Organization',
80 'contact_sub_type' => '',
81 'sort_name' => 'Unit Test Organization',
82 'display_name' => 'Unit Test Organization',
83 'do_not_email' => 0,
84 'do_not_phone' => 0,
85 'do_not_mail' => 0,
86 'do_not_sms' => 0,
87 'do_not_trade' => 0,
88 'is_opt_out' => 0,
89 'legal_identifier' => '',
90 'external_identifier' => '',
91 'nick_name' => '',
92 'legal_name' => '',
93 'image_URL' => '',
94 'preferred_communication_method' => '',
95 'preferred_language' => 'en_US',
96 'preferred_mail_format' => 'Both',
97 'first_name' => '',
98 'middle_name' => '',
99 'last_name' => '',
100 'prefix_id' => '',
101 'suffix_id' => '',
102 'formal_title' => '',
103 'communication_style_id' => '',
104 'job_title' => '',
105 'gender_id' => '',
106 'birth_date' => '',
107 'is_deceased' => 0,
108 'deceased_date' => '',
109 'household_name' => '',
110 'organization_name' => 'Unit Test Organization',
111 'sic_code' => '',
112 'contact_is_deleted' => 0,
113 'current_employer' => '',
114 'address_id' => '',
115 'street_address' => '',
116 'supplemental_address_1' => '',
117 'supplemental_address_2' => '',
118 'supplemental_address_3' => '',
119 'city' => '',
120 'postal_code_suffix' => '',
121 'postal_code' => '',
122 'geo_code_1' => '',
123 'geo_code_2' => '',
124 'state_province_id' => '',
125 'country_id' => '',
126 'phone_id' => '',
127 'phone_type_id' => '',
128 'phone' => '',
129 'email_id' => '',
130 'email' => '',
131 'on_hold' => '',
132 'im_id' => '',
133 'provider_id' => '',
134 'im' => '',
135 'worldregion_id' => '',
136 'world_region' => '',
137 'individual_prefix' => '',
138 'individual_suffix' => '',
139 'communication_style' => '',
140 'gender' => '',
141 'state_province_name' => '',
142 'state_province' => '',
143 'country' => '',
144 'id' => '10',
145 'api.email.replace' => array(
146 'is_error' => 0,
147 'version' => 3,
148 'count' => 5,
149 'values' => array(
150 '0' => array(
151 'id' => '18',
152 'contact_id' => '10',
153 'location_type_id' => '20',
154 'email' => '1-1@example.com',
155 'is_primary' => '1',
156 'is_billing' => '',
157 'on_hold' => '',
158 'is_bulkmail' => '',
159 'hold_date' => '',
160 'reset_date' => '',
161 'signature_text' => '',
162 'signature_html' => '',
163 ),
164 '1' => array(
165 'id' => '19',
166 'contact_id' => '10',
167 'location_type_id' => '20',
168 'email' => '1-2@example.com',
169 'is_primary' => 0,
170 'is_billing' => '',
171 'on_hold' => '',
172 'is_bulkmail' => '',
173 'hold_date' => '',
174 'reset_date' => '',
175 'signature_text' => '',
176 'signature_html' => '',
177 ),
178 '2' => array(
179 'id' => '20',
180 'contact_id' => '10',
181 'location_type_id' => '20',
182 'email' => '1-3@example.com',
183 'is_primary' => 0,
184 'is_billing' => '',
185 'on_hold' => '',
186 'is_bulkmail' => '',
187 'hold_date' => '',
188 'reset_date' => '',
189 'signature_text' => '',
190 'signature_html' => '',
191 ),
192 '3' => array(
193 'id' => '21',
194 'contact_id' => '10',
195 'location_type_id' => '21',
196 'email' => '2-1@example.com',
197 'is_primary' => 0,
198 'is_billing' => '',
199 'on_hold' => '',
200 'is_bulkmail' => '',
201 'hold_date' => '',
202 'reset_date' => '',
203 'signature_text' => '',
204 'signature_html' => '',
205 ),
206 '4' => array(
207 'id' => '22',
208 'contact_id' => '10',
209 'location_type_id' => '21',
210 'email' => '2-2@example.com',
211 'is_primary' => 0,
212 'is_billing' => '',
213 'on_hold' => '',
214 'is_bulkmail' => '',
215 'hold_date' => '',
216 'reset_date' => '',
217 'signature_text' => '',
218 'signature_html' => '',
219 ),
220 ),
221 ),
222 ),
223 ),
224 );
225
226 return $expectedResult;
227 }
228
229 /*
230 * This example has been generated from the API test suite.
231 * The test that created it is called "testReplaceEmailsInChain"
232 * and can be found at:
233 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/EmailTest.php
234 *
235 * You can see the outcome of the API tests at
236 * https://test.civicrm.org/job/CiviCRM-master-git/
237 *
238 * To Learn about the API read
239 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
240 *
241 * Browse the api on your own site with the api explorer
242 * http://MYSITE.ORG/path/to/civicrm/api
243 *
244 * Read more about testing here
245 * http://wiki.civicrm.org/confluence/display/CRM/Testing
246 *
247 * API Standards documentation:
248 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
249 */