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