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