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