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