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