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' => '', | |
58 | 'preferred_mail_format' => 'Both', | |
59 | 'first_name' => 'abc3', | |
60 | 'middle_name' => '', | |
61 | 'last_name' => 'xyz3', | |
6ecbca5b | 62 | 'prefix_id' => '', |
63 | 'suffix_id' => '', | |
6a488035 | 64 | 'job_title' => '', |
6ecbca5b | 65 | 'gender_id' => '', |
6a488035 TO |
66 | 'birth_date' => '', |
67 | 'is_deceased' => 0, | |
68 | 'deceased_date' => '', | |
69 | 'household_name' => '', | |
70 | 'organization_name' => '', | |
71 | 'sic_code' => '', | |
72 | 'contact_is_deleted' => 0, | |
6a488035 TO |
73 | 'current_employer' => '', |
74 | 'address_id' => '', | |
75 | 'street_address' => '', | |
76 | 'supplemental_address_1' => '', | |
77 | 'supplemental_address_2' => '', | |
78 | 'city' => '', | |
79 | 'postal_code_suffix' => '', | |
80 | 'postal_code' => '', | |
81 | 'geo_code_1' => '', | |
82 | 'geo_code_2' => '', | |
83 | 'state_province_id' => '', | |
6a488035 | 84 | 'country_id' => '', |
6a488035 TO |
85 | 'phone_id' => '', |
86 | 'phone_type_id' => '', | |
87 | 'phone' => '', | |
88 | 'email_id' => '1', | |
89 | 'email' => 'man3@yahoo.com', | |
90 | 'on_hold' => 0, | |
91 | 'im_id' => '', | |
92 | 'provider_id' => '', | |
93 | 'im' => '', | |
94 | 'worldregion_id' => '', | |
95 | 'world_region' => '', | |
6ecbca5b | 96 | 'individual_prefix' => '', |
97 | 'individual_suffix' => '', | |
98 | 'gender' => '', | |
9f1b81e0 | 99 | 'state_province_name' => '', |
100 | 'state_province' => '', | |
101 | 'country' => '', | |
6a488035 TO |
102 | 'id' => '1', |
103 | 'api.website.getValue' => 'http://civicrm.org', | |
104 | 'api.Contribution.getCount' => 2, | |
edb0d67a | 105 | 'api.CustomValue.get' => array( |
6a488035 TO |
106 | 'is_error' => 0, |
107 | 'version' => 3, | |
fb32de45 | 108 | 'count' => 8, |
edb0d67a | 109 | 'values' => array( |
110 | '0' => array( | |
6a488035 TO |
111 | 'entity_id' => '1', |
112 | 'latest' => 'value 4', | |
fb32de45 | 113 | 'id' => '1', |
114 | 'entity_table' => 'Contact', | |
6a488035 | 115 | ), |
edb0d67a | 116 | '1' => array( |
6a488035 TO |
117 | 'entity_table' => 'Contact', |
118 | ), | |
edb0d67a | 119 | '2' => array( |
6a488035 TO |
120 | 'entity_id' => '1', |
121 | 'latest' => 'value 3', | |
fb32de45 | 122 | 'id' => '2', |
6a488035 | 123 | '1' => 'value 2', |
fb32de45 | 124 | 'entity_table' => 'Contact', |
6a488035 TO |
125 | '2' => 'value 3', |
126 | ), | |
edb0d67a | 127 | '3' => array( |
6a488035 TO |
128 | 'entity_id' => '1', |
129 | 'latest' => '', | |
fb32de45 | 130 | 'id' => '3', |
6a488035 TO |
131 | '1' => 'warm beer', |
132 | '2' => '', | |
133 | ), | |
fb32de45 | 134 | '4' => array( |
6a488035 TO |
135 | 'entity_id' => '1', |
136 | 'latest' => '', | |
fb32de45 | 137 | 'id' => '4', |
6a488035 TO |
138 | '1' => '', |
139 | '2' => '', | |
140 | ), | |
fb32de45 | 141 | '5' => array( |
6a488035 TO |
142 | 'entity_id' => '1', |
143 | 'latest' => '', | |
fb32de45 | 144 | 'id' => '5', |
6a488035 TO |
145 | '1' => '', |
146 | ), | |
fb32de45 | 147 | '6' => array( |
6a488035 TO |
148 | 'entity_id' => '1', |
149 | 'latest' => 'vegemite', | |
fb32de45 | 150 | 'id' => '6', |
6a488035 TO |
151 | '1' => 'vegemite', |
152 | ), | |
fb32de45 | 153 | '7' => array( |
6a488035 TO |
154 | 'entity_id' => '1', |
155 | 'latest' => '', | |
fb32de45 | 156 | 'id' => '7', |
6a488035 TO |
157 | '1' => '', |
158 | ), | |
159 | ), | |
160 | ), | |
161 | ), | |
162 | ), | |
163 | ); | |
164 | ||
fb32de45 | 165 | return $expectedResult; |
6a488035 TO |
166 | } |
167 | ||
168 | ||
169 | /* | |
170 | * This example has been generated from the API test suite. The test that created it is called | |
171 | * | |
172 | * testGetIndividualWithChainedArraysAndMultipleCustom and can be found in | |
173 | * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php | |
174 | * | |
175 | * You can see the outcome of the API tests at | |
176 | * http://tests.dev.civicrm.org/trunk/results-api_v3 | |
177 | * | |
178 | * To Learn about the API read | |
179 | * http://book.civicrm.org/developer/current/techniques/api/ | |
180 | * | |
181 | * and review the wiki at | |
182 | * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs | |
183 | * | |
184 | * Read more about testing here | |
185 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
186 | * | |
187 | * API Standards documentation: | |
188 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
189 | */ |