Merge pull request #1274 from davecivicrm/CRM-13117
[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_mail_format' => 'Both',
83 'first_name' => '',
84 'middle_name' => '',
85 'last_name' => '',
86 'job_title' => '',
87 'birth_date' => '',
88 'is_deceased' => 0,
89 'deceased_date' => '',
90 'household_name' => '',
91 'organization_name' => 'Unit Test Organization',
92 'sic_code' => '',
93 'contact_is_deleted' => 0,
94 'current_employer' => '',
95 'address_id' => '',
96 'street_address' => '',
97 'supplemental_address_1' => '',
98 'supplemental_address_2' => '',
99 'city' => '',
100 'postal_code_suffix' => '',
101 'postal_code' => '',
102 'geo_code_1' => '',
103 'geo_code_2' => '',
104 'state_province_id' => '',
105 'state_province_name' => '',
106 'state_province' => '',
107 'country_id' => '',
108 'country' => '',
109 'phone_id' => '',
110 'phone_type_id' => '',
111 'phone' => '',
112 'email_id' => '',
113 'email' => '',
114 'on_hold' => '',
115 'im_id' => '',
116 'provider_id' => '',
117 'im' => '',
118 'worldregion_id' => '',
119 'world_region' => '',
120 'id' => '10',
121 'api.email.replace' => array(
122 'is_error' => 0,
123 'version' => 3,
124 'count' => 5,
125 'values' => array(
126 '0' => array(
127 'id' => '18',
128 'contact_id' => '10',
129 'location_type_id' => '20',
130 'email' => '1-1@example.com',
131 'is_primary' => '1',
132 'is_billing' => '',
133 'on_hold' => '',
134 'is_bulkmail' => '',
135 'hold_date' => '',
136 'reset_date' => '',
137 'signature_text' => '',
138 'signature_html' => '',
139 ),
140 '1' => array(
141 'id' => '19',
142 'contact_id' => '10',
143 'location_type_id' => '20',
144 'email' => '1-2@example.com',
145 'is_primary' => 0,
146 'is_billing' => '',
147 'on_hold' => '',
148 'is_bulkmail' => '',
149 'hold_date' => '',
150 'reset_date' => '',
151 'signature_text' => '',
152 'signature_html' => '',
153 ),
154 '2' => array(
155 'id' => '20',
156 'contact_id' => '10',
157 'location_type_id' => '20',
158 'email' => '1-3@example.com',
159 'is_primary' => 0,
160 'is_billing' => '',
161 'on_hold' => '',
162 'is_bulkmail' => '',
163 'hold_date' => '',
164 'reset_date' => '',
165 'signature_text' => '',
166 'signature_html' => '',
167 ),
168 '3' => array(
169 'id' => '21',
170 'contact_id' => '10',
171 'location_type_id' => '21',
172 'email' => '2-1@example.com',
173 'is_primary' => 0,
174 'is_billing' => '',
175 'on_hold' => '',
176 'is_bulkmail' => '',
177 'hold_date' => '',
178 'reset_date' => '',
179 'signature_text' => '',
180 'signature_html' => '',
181 ),
182 '4' => array(
183 'id' => '22',
184 'contact_id' => '10',
185 'location_type_id' => '21',
186 'email' => '2-2@example.com',
187 'is_primary' => 0,
188 'is_billing' => '',
189 'on_hold' => '',
190 'is_bulkmail' => '',
191 'hold_date' => '',
192 'reset_date' => '',
193 'signature_text' => '',
194 'signature_html' => '',
195 ),
196 ),
197 ),
198 ),
199 ),
200 );
201
202 return $expectedResult;
203 }
204
205
206 /*
207 * This example has been generated from the API test suite. The test that created it is called
208 *
209 * testReplaceEmailsInChain and can be found in
210 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/EmailTest.php
211 *
212 * You can see the outcome of the API tests at
213 * http://tests.dev.civicrm.org/trunk/results-api_v3
214 *
215 * To Learn about the API read
216 * http://book.civicrm.org/developer/current/techniques/api/
217 *
218 * and review the wiki at
219 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
220 *
221 * Read more about testing here
222 * http://wiki.civicrm.org/confluence/display/CRM/Testing
223 *
224 * API Standards documentation:
225 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
226 */