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