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