Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-21-08-12-12
[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 'job_title' => '',
91 'gender_id' => '',
92 'birth_date' => '',
93 'is_deceased' => 0,
94 'deceased_date' => '',
95 'household_name' => '',
96 'organization_name' => 'Unit Test Organization',
97 'sic_code' => '',
98 'contact_is_deleted' => 0,
99 'current_employer' => '',
100 'address_id' => '',
101 'street_address' => '',
102 'supplemental_address_1' => '',
103 'supplemental_address_2' => '',
104 'city' => '',
105 'postal_code_suffix' => '',
106 'postal_code' => '',
107 'geo_code_1' => '',
108 'geo_code_2' => '',
109 'state_province_id' => '',
110 'country_id' => '',
111 'phone_id' => '',
112 'phone_type_id' => '',
113 'phone' => '',
114 'email_id' => '',
115 'email' => '',
116 'on_hold' => '',
117 'im_id' => '',
118 'provider_id' => '',
119 'im' => '',
120 'worldregion_id' => '',
121 'world_region' => '',
122 'individual_prefix' => '',
123 'individual_suffix' => '',
124 'gender' => '',
125 'state_province_name' => '',
126 'state_province' => '',
127 'country' => '',
128 'id' => '10',
129 'api.email.replace' => array(
130 'is_error' => 0,
131 'version' => 3,
132 'count' => 5,
133 'values' => array(
134 '0' => array(
135 'id' => '18',
136 'contact_id' => '10',
137 'location_type_id' => '20',
138 'email' => '1-1@example.com',
139 'is_primary' => '1',
140 'is_billing' => '',
141 'on_hold' => '',
142 'is_bulkmail' => '',
143 'hold_date' => '',
144 'reset_date' => '',
145 'signature_text' => '',
146 'signature_html' => '',
147 ),
148 '1' => array(
149 'id' => '19',
150 'contact_id' => '10',
151 'location_type_id' => '20',
152 'email' => '1-2@example.com',
153 'is_primary' => 0,
154 'is_billing' => '',
155 'on_hold' => '',
156 'is_bulkmail' => '',
157 'hold_date' => '',
158 'reset_date' => '',
159 'signature_text' => '',
160 'signature_html' => '',
161 ),
162 '2' => array(
163 'id' => '20',
164 'contact_id' => '10',
165 'location_type_id' => '20',
166 'email' => '1-3@example.com',
167 'is_primary' => 0,
168 'is_billing' => '',
169 'on_hold' => '',
170 'is_bulkmail' => '',
171 'hold_date' => '',
172 'reset_date' => '',
173 'signature_text' => '',
174 'signature_html' => '',
175 ),
176 '3' => array(
177 'id' => '21',
178 'contact_id' => '10',
179 'location_type_id' => '21',
180 'email' => '2-1@example.com',
181 'is_primary' => 0,
182 'is_billing' => '',
183 'on_hold' => '',
184 'is_bulkmail' => '',
185 'hold_date' => '',
186 'reset_date' => '',
187 'signature_text' => '',
188 'signature_html' => '',
189 ),
190 '4' => array(
191 'id' => '22',
192 'contact_id' => '10',
193 'location_type_id' => '21',
194 'email' => '2-2@example.com',
195 'is_primary' => 0,
196 'is_billing' => '',
197 'on_hold' => '',
198 'is_bulkmail' => '',
199 'hold_date' => '',
200 'reset_date' => '',
201 'signature_text' => '',
202 'signature_html' => '',
203 ),
204 ),
205 ),
206 ),
207 ),
208 );
209
210 return $expectedResult;
211 }
212
213
214 /*
215 * This example has been generated from the API test suite. The test that created it is called
216 *
217 * testReplaceEmailsInChain and can be found in
218 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/EmailTest.php
219 *
220 * You can see the outcome of the API tests at
221 * https://test.civicrm.org/job/CiviCRM-master-git/
222 *
223 * To Learn about the API read
224 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
225 *
226 * Browse the api on your own site with the api explorer
227 * http://MYSITE.ORG/path/to/civicrm/api/explorer
228 *
229 * Read more about testing here
230 * http://wiki.civicrm.org/confluence/display/CRM/Testing
231 *
232 * API Standards documentation:
233 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
234 */