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