Merge remote-tracking branch 'upstream/4.3' into 4.3-master-2013-10-02-11-18-44
[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_mail_format' => 'Both',
59 'first_name' => 'abc3',
60 'middle_name' => '',
61 'last_name' => 'xyz3',
62 'prefix_id' => '',
63 'suffix_id' => '',
64 'job_title' => '',
65 'gender_id' => '',
66 'birth_date' => '',
67 'is_deceased' => 0,
68 'deceased_date' => '',
69 'household_name' => '',
70 'organization_name' => '',
71 'sic_code' => '',
72 'contact_is_deleted' => 0,
73 'current_employer' => '',
74 'address_id' => '',
75 'street_address' => '',
76 'supplemental_address_1' => '',
77 'supplemental_address_2' => '',
78 'city' => '',
79 'postal_code_suffix' => '',
80 'postal_code' => '',
81 'geo_code_1' => '',
82 'geo_code_2' => '',
83 'state_province_id' => '',
84 'country_id' => '',
85 'phone_id' => '',
86 'phone_type_id' => '',
87 'phone' => '',
88 'email_id' => '1',
89 'email' => 'man3@yahoo.com',
90 'on_hold' => 0,
91 'im_id' => '',
92 'provider_id' => '',
93 'im' => '',
94 'worldregion_id' => '',
95 'world_region' => '',
96 'individual_prefix' => '',
97 'individual_suffix' => '',
98 'gender' => '',
99 'state_province_name' => '',
100 'state_province' => '',
101 'country' => '',
102 'id' => '1',
103 'api.website.getValue' => 'http://civicrm.org',
104 'api.Contribution.getCount' => 2,
105 'api.CustomValue.get' => array(
106 'is_error' => 0,
107 'version' => 3,
108 'count' => 8,
109 'values' => array(
110 '0' => array(
111 'entity_id' => '1',
112 'latest' => 'value 4',
113 'id' => '1',
114 'entity_table' => 'Contact',
115 ),
116 '1' => array(
117 'entity_table' => 'Contact',
118 ),
119 '2' => array(
120 'entity_id' => '1',
121 'latest' => 'value 3',
122 'id' => '2',
123 '1' => 'value 2',
124 'entity_table' => 'Contact',
125 '2' => 'value 3',
126 ),
127 '3' => array(
128 'entity_id' => '1',
129 'latest' => 'defaultValue',
130 'id' => '3',
131 '1' => 'warm beer',
132 '2' => 'defaultValue',
133 ),
134 '4' => array(
135 'entity_id' => '1',
136 'latest' => 'defaultValue',
137 'id' => '4',
138 '1' => 'defaultValue',
139 '2' => 'defaultValue',
140 ),
141 '5' => array(
142 'entity_id' => '1',
143 'latest' => 'defaultValue',
144 'id' => '5',
145 '1' => 'defaultValue',
146 ),
147 '6' => array(
148 'entity_id' => '1',
149 'latest' => 'vegemite',
150 'id' => '6',
151 '1' => 'vegemite',
152 ),
153 '7' => array(
154 'entity_id' => '1',
155 'latest' => 'defaultValue',
156 'id' => '7',
157 '1' => 'defaultValue',
158 ),
159 ),
160 ),
161 ),
162 ),
163 );
164
165 return $expectedResult;
166 }
167
168
169 /*
170 * This example has been generated from the API test suite. The test that created it is called
171 *
172 * testGetIndividualWithChainedArraysAndMultipleCustom and can be found in
173 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
174 *
175 * You can see the outcome of the API tests at
176 * http://tests.dev.civicrm.org/trunk/results-api_v3
177 *
178 * To Learn about the API read
179 * http://book.civicrm.org/developer/current/techniques/api/
180 *
181 * and review the wiki at
182 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
183 *
184 * Read more about testing here
185 * http://wiki.civicrm.org/confluence/display/CRM/Testing
186 *
187 * API Standards documentation:
188 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
189 */