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