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