Merge remote-tracking branch 'upstream/4.4' into 4.4-4.5-2014-09-29-14-51-22
[civicrm-core.git] / api / v3 / examples / Contact / APIChainedArrayMultipleCustom.php
CommitLineData
6a488035 1<?php
fb32de45 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 *
6a488035
TO
5 */
6function contact_get_example(){
edb0d67a 7$params = array(
6a488035 8 'id' => 1,
edb0d67a 9 'api.website.getValue' => array(
6a488035
TO
10 'return' => 'url',
11 ),
12 'api.Contribution.getCount' => array(),
13 'api.CustomValue.get' => 1,
14);
15
fb32de45 16try{
17 $result = civicrm_api3('contact', 'get', $params);
18}
19catch (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}
6a488035 26
fb32de45 27return $result;
6a488035
TO
28}
29
fb32de45 30/**
6a488035
TO
31 * Function returns array of result expected from previous function
32 */
33function contact_get_expectedresult(){
34
edb0d67a 35 $expectedResult = array(
6a488035
TO
36 'is_error' => 0,
37 'version' => 3,
38 'count' => 1,
39 'id' => 1,
edb0d67a 40 'values' => array(
41 '1' => array(
6a488035
TO
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' => '',
b259a4ab
EM
58 'preferred_communication_method' => '',
59 'preferred_language' => 'en_US',
6a488035
TO
60 'preferred_mail_format' => 'Both',
61 'first_name' => 'abc3',
62 'middle_name' => '',
63 'last_name' => 'xyz3',
6ecbca5b 64 'prefix_id' => '',
65 'suffix_id' => '',
89bf81b4 66 'formal_title' => '',
67 'communication_style_id' => '',
6a488035 68 'job_title' => '',
6ecbca5b 69 'gender_id' => '',
6a488035
TO
70 'birth_date' => '',
71 'is_deceased' => 0,
72 'deceased_date' => '',
73 'household_name' => '',
74 'organization_name' => '',
75 'sic_code' => '',
76 'contact_is_deleted' => 0,
6a488035 77 'current_employer' => '',
69d79249
E
78 'address_id' => '2',
79 'street_address' => '1 my road',
6a488035
TO
80 'supplemental_address_1' => '',
81 'supplemental_address_2' => '',
82 'city' => '',
83 'postal_code_suffix' => '',
84 'postal_code' => '',
85 'geo_code_1' => '',
86 'geo_code_2' => '',
87 'state_province_id' => '',
6a488035 88 'country_id' => '',
6a488035
TO
89 'phone_id' => '',
90 'phone_type_id' => '',
91 'phone' => '',
92 'email_id' => '1',
93 'email' => 'man3@yahoo.com',
94 'on_hold' => 0,
95 'im_id' => '',
96 'provider_id' => '',
97 'im' => '',
98 'worldregion_id' => '',
99 'world_region' => '',
6ecbca5b 100 'individual_prefix' => '',
101 'individual_suffix' => '',
89bf81b4 102 'communication_style' => '',
6ecbca5b 103 'gender' => '',
9f1b81e0 104 'state_province_name' => '',
105 'state_province' => '',
106 'country' => '',
6a488035
TO
107 'id' => '1',
108 'api.website.getValue' => 'http://civicrm.org',
109 'api.Contribution.getCount' => 2,
edb0d67a 110 'api.CustomValue.get' => array(
6a488035
TO
111 'is_error' => 0,
112 'version' => 3,
fb32de45 113 'count' => 8,
edb0d67a 114 'values' => array(
115 '0' => array(
6a488035
TO
116 'entity_id' => '1',
117 'latest' => 'value 4',
fb32de45 118 'id' => '1',
119 'entity_table' => 'Contact',
6a488035 120 ),
edb0d67a 121 '1' => array(
6a488035
TO
122 'entity_table' => 'Contact',
123 ),
edb0d67a 124 '2' => array(
6a488035
TO
125 'entity_id' => '1',
126 'latest' => 'value 3',
fb32de45 127 'id' => '2',
6a488035 128 '1' => 'value 2',
fb32de45 129 'entity_table' => 'Contact',
6a488035
TO
130 '2' => 'value 3',
131 ),
edb0d67a 132 '3' => array(
6a488035 133 'entity_id' => '1',
b259a4ab 134 'latest' => '',
fb32de45 135 'id' => '3',
6a488035 136 '1' => 'warm beer',
b259a4ab 137 '2' => '',
6a488035 138 ),
fb32de45 139 '4' => array(
6a488035 140 'entity_id' => '1',
b259a4ab 141 'latest' => '',
fb32de45 142 'id' => '4',
b259a4ab
EM
143 '1' => '',
144 '2' => '',
6a488035 145 ),
fb32de45 146 '5' => array(
6a488035 147 'entity_id' => '1',
b422b715 148 'latest' => 'defaultValue',
fb32de45 149 'id' => '5',
b422b715 150 '1' => 'defaultValue',
6a488035 151 ),
fb32de45 152 '6' => array(
6a488035
TO
153 'entity_id' => '1',
154 'latest' => 'vegemite',
fb32de45 155 'id' => '6',
6a488035
TO
156 '1' => 'vegemite',
157 ),
fb32de45 158 '7' => array(
6a488035 159 'entity_id' => '1',
b259a4ab 160 'latest' => '',
fb32de45 161 'id' => '7',
b259a4ab 162 '1' => '',
6a488035
TO
163 ),
164 ),
165 ),
166 ),
167 ),
168);
169
fb32de45 170 return $expectedResult;
6a488035
TO
171}
172
173
174/*
175* This example has been generated from the API test suite. The test that created it is called
176*
177* testGetIndividualWithChainedArraysAndMultipleCustom and can be found in
69d79249 178* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
6a488035
TO
179*
180* You can see the outcome of the API tests at
69d79249 181* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
182*
183* To Learn about the API read
69d79249 184* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 185*
69d79249
E
186* Browse the api on your own site with the api explorer
187* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
188*
189* Read more about testing here
190* http://wiki.civicrm.org/confluence/display/CRM/Testing
191*
192* API Standards documentation:
193* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 194*/