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