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