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