Merge pull request #9968 from fuzionnz/remove_crm_core_form_generateid
[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 'city' => '',
95 'postal_code_suffix' => '',
96 'postal_code' => '',
97 'geo_code_1' => '',
98 'geo_code_2' => '',
99 'state_province_id' => '',
100 'country_id' => '',
101 'phone_id' => '',
102 'phone_type_id' => '',
103 'phone' => '',
104 'email_id' => '1',
105 'email' => 'man3@yahoo.com',
106 'on_hold' => 0,
107 'im_id' => '',
108 'provider_id' => '',
109 'im' => '',
110 'worldregion_id' => '',
111 'world_region' => '',
112 'languages' => 'English (United States)',
113 'individual_prefix' => '',
114 'individual_suffix' => '',
115 'communication_style' => '',
116 'gender' => '',
117 'state_province_name' => '',
118 'state_province' => '',
119 'country' => '',
120 'id' => '3',
121 'api.website.getValue' => 'http://civicrm.org',
122 'api.Contribution.getCount' => 2,
123 'api.CustomValue.get' => array(
124 'is_error' => 0,
125 'version' => 3,
126 'count' => 7,
127 'values' => array(
128 '0' => array(
129 'entity_id' => '3',
130 'entity_table' => 'Contact',
131 'latest' => 'value 4',
132 'id' => '1',
133 ),
134 '1' => array(
135 'entity_id' => '3',
136 'entity_table' => 'Contact',
137 'latest' => 'value 3',
138 'id' => '2',
139 '1' => 'value 2',
140 '2' => 'value 3',
141 ),
142 '2' => array(
143 'entity_id' => '3',
144 'entity_table' => 'Contact',
145 'latest' => '',
146 'id' => '3',
147 '1' => 'warm beer',
148 '2' => '',
149 ),
150 '3' => array(
151 'entity_id' => '3',
152 'entity_table' => 'Contact',
153 'latest' => '',
154 'id' => '4',
155 '1' => '',
156 '2' => '',
157 ),
158 '4' => array(
159 'entity_id' => '3',
160 'entity_table' => 'Contact',
161 'latest' => 'defaultValue',
162 'id' => '5',
163 '1' => 'defaultValue',
164 ),
165 '5' => array(
166 'entity_id' => '3',
167 'entity_table' => 'Contact',
168 'latest' => 'vegemite',
169 'id' => '6',
170 '1' => 'vegemite',
171 ),
172 '6' => array(
173 'entity_id' => '3',
174 'entity_table' => 'Contact',
175 'latest' => '',
176 'id' => '7',
177 '1' => '',
178 ),
179 ),
180 ),
181 ),
182 ),
183 );
184
185 return $expectedResult;
186 }
187
188 /*
189 * This example has been generated from the API test suite.
190 * The test that created it is called "testGetIndividualWithChainedArraysAndMultipleCustom"
191 * and can be found at:
192 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
193 *
194 * You can see the outcome of the API tests at
195 * https://test.civicrm.org/job/CiviCRM-master-git/
196 *
197 * To Learn about the API read
198 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
199 *
200 * Browse the api on your own site with the api explorer
201 * http://MYSITE.ORG/path/to/civicrm/api
202 *
203 * Read more about testing here
204 * http://wiki.civicrm.org/confluence/display/CRM/Testing
205 *
206 * API Standards documentation:
207 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
208 */