Merge pull request #1625 from pradpnayak/CRM-13340
[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_mail_format' => 'Both',
62 'first_name' => 'abc3',
63 'middle_name' => '',
64 'last_name' => 'xyz3',
65 'prefix_id' => '',
66 'suffix_id' => '',
67 'job_title' => '',
68 'gender_id' => '',
69 'birth_date' => '',
70 'is_deceased' => 0,
71 'deceased_date' => '',
72 'household_name' => '',
73 'organization_name' => '',
74 'sic_code' => '',
75 'contact_is_deleted' => 0,
76 'current_employer' => '',
77 'address_id' => '',
78 'street_address' => '',
79 'supplemental_address_1' => '',
80 'supplemental_address_2' => '',
81 'city' => '',
82 'postal_code_suffix' => '',
83 'postal_code' => '',
84 'geo_code_1' => '',
85 'geo_code_2' => '',
86 'state_province_id' => '',
87 'country_id' => '',
88 'phone_id' => '',
89 'phone_type_id' => '',
90 'phone' => '',
91 'email_id' => '1',
92 'email' => 'man3@yahoo.com',
93 'on_hold' => 0,
94 'im_id' => '',
95 'provider_id' => '',
96 'im' => '',
97 'worldregion_id' => '',
98 'world_region' => '',
99 'individual_prefix' => '',
100 'individual_suffix' => '',
101 'gender' => '',
102 'state_province_name' => '',
103 'state_province' => '',
104 'country' => '',
105 'id' => '1',
106 'api.website.getValue' => 'http://civicrm.org',
107 'api.Contribution.getCount' => 2,
108 'api.CustomValue.get' => array(
109 'is_error' => 0,
110 'version' => 3,
111 'count' => 0,
112 'values' => array(),
113 ),
114 'api.Note.get' => array(
115 'is_error' => 0,
116 'version' => 3,
117 'count' => 0,
118 'values' => array(),
119 ),
120 'api.Membership.getCount' => 0,
121 ),
122 ),
123 );
124
125 return $expectedResult;
126 }
127
128
129 /*
130 * This example has been generated from the API test suite. The test that created it is called
131 *
132 * testGetIndividualWithChainedArraysFormats and can be found in
133 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
134 *
135 * You can see the outcome of the API tests at
136 * http://tests.dev.civicrm.org/trunk/results-api_v3
137 *
138 * To Learn about the API read
139 * http://book.civicrm.org/developer/current/techniques/api/
140 *
141 * and review the wiki at
142 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
143 *
144 * Read more about testing here
145 * http://wiki.civicrm.org/confluence/display/CRM/Testing
146 *
147 * API Standards documentation:
148 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
149 */