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