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