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