Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Contact.get API. |
50fb255d | 4 | * |
5c49fee0 | 5 | * This demonstrates the usage of chained api functions with multiple custom fields. |
50fb255d | 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( | |
6a488035 TO |
14 | 'return' => 'url', |
15 | ), | |
50fb255d | 16 | 'api.Contribution.getCount' => array(), |
17 | 'api.CustomValue.get' => 1, | |
18 | ); | |
6a488035 | 19 | |
50fb255d | 20 | try{ |
a828d7b8 | 21 | $result = civicrm_api3('Contact', 'get', $params); |
50fb255d | 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 | } | |
6a488035 | 34 | |
50fb255d | 35 | return $result; |
6a488035 TO |
36 | } |
37 | ||
fb32de45 | 38 | /** |
50fb255d | 39 | * Function returns array of result expected from previous function. |
40 | * | |
41 | * @return array | |
42 | * API result array | |
6a488035 | 43 | */ |
50fb255d | 44 | function contact_get_expectedresult() { |
6a488035 | 45 | |
edb0d67a | 46 | $expectedResult = array( |
50fb255d | 47 | 'is_error' => 0, |
48 | 'version' => 3, | |
49 | 'count' => 1, | |
50 | 'id' => 1, | |
51 | 'values' => array( | |
edb0d67a | 52 | '1' => array( |
50fb255d | 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' => '', | |
6a488035 | 149 | ), |
50fb255d | 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 | ), | |
6a488035 | 176 | ), |
50fb255d | 177 | ), |
6a488035 | 178 | ), |
50fb255d | 179 | ); |
6a488035 | 180 | |
fb32de45 | 181 | return $expectedResult; |
6a488035 TO |
182 | } |
183 | ||
a828d7b8 | 184 | /* |
50fb255d | 185 | * This example has been generated from the API test suite. |
a828d7b8 CW |
186 | * The test that created it is called "testGetIndividualWithChainedArraysAndMultipleCustom" |
187 | * and can be found at: | |
69d79249 | 188 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php |
6a488035 TO |
189 | * |
190 | * You can see the outcome of the API tests at | |
69d79249 | 191 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
192 | * |
193 | * To Learn about the API read | |
69d79249 | 194 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 195 | * |
69d79249 | 196 | * Browse the api on your own site with the api explorer |
41d4d31f | 197 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
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 | |
b259a4ab | 204 | */ |