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