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