3bc4f8750f653479d43a99cce5380269e22a8a6b
[civicrm-core.git] / api / v3 / examples / Contact / GetSingleContact.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Contact.getsingle API.
4 *
5 * This demonstrates use of the 'format.single_entity_array' param.
6 * This param causes the only contact to be returned as an array without the other levels.
7 * It will be ignored if there is not exactly 1 result
8 *
9 * @return array
10 * API result array
11 */
12 function contact_getsingle_example() {
13 $params = array(
14 'id' => 17,
15 );
16
17 try{
18 $result = civicrm_api3('Contact', 'getsingle', $params);
19 }
20 catch (CiviCRM_API3_Exception $e) {
21 // Handle error here.
22 $errorMessage = $e->getMessage();
23 $errorCode = $e->getErrorCode();
24 $errorData = $e->getExtraParams();
25 return array(
26 'is_error' => 1,
27 'error_message' => $errorMessage,
28 'error_code' => $errorCode,
29 'error_data' => $errorData,
30 );
31 }
32
33 return $result;
34 }
35
36 /**
37 * Function returns array of result expected from previous function.
38 *
39 * @return array
40 * API result array
41 */
42 function contact_getsingle_expectedresult() {
43
44 $expectedResult = array(
45 'contact_id' => '17',
46 'contact_type' => 'Individual',
47 'contact_sub_type' => '',
48 'sort_name' => '',
49 'display_name' => 'Test Contact',
50 'do_not_email' => '',
51 'do_not_phone' => '',
52 'do_not_mail' => '',
53 'do_not_sms' => '',
54 'do_not_trade' => '',
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' => '',
63 'preferred_mail_format' => '',
64 'first_name' => 'Test',
65 'middle_name' => '',
66 'last_name' => 'Contact',
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' => '',
82 'street_address' => '',
83 'supplemental_address_1' => '',
84 'supplemental_address_2' => '',
85 'supplemental_address_3' => '',
86 'city' => '',
87 'postal_code_suffix' => '',
88 'postal_code' => '',
89 'geo_code_1' => '',
90 'geo_code_2' => '',
91 'state_province_id' => '',
92 'country_id' => '',
93 'phone_id' => '',
94 'phone_type_id' => '',
95 'phone' => '',
96 'email_id' => '',
97 'email' => '',
98 'on_hold' => '',
99 'im_id' => '',
100 'provider_id' => '',
101 'im' => '',
102 'worldregion_id' => '',
103 'world_region' => '',
104 'languages' => '',
105 'individual_prefix' => '',
106 'individual_suffix' => '',
107 'communication_style' => '',
108 'gender' => '',
109 'state_province_name' => '',
110 'state_province' => '',
111 'country' => '',
112 'id' => '17',
113 );
114
115 return $expectedResult;
116 }
117
118 /*
119 * This example has been generated from the API test suite.
120 * The test that created it is called "testContactGetSingleEntityArray"
121 * and can be found at:
122 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
123 *
124 * You can see the outcome of the API tests at
125 * https://test.civicrm.org/job/CiviCRM-master-git/
126 *
127 * To Learn about the API read
128 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
129 *
130 * Browse the api on your own site with the api explorer
131 * http://MYSITE.ORG/path/to/civicrm/api
132 *
133 * Read more about testing here
134 * http://wiki.civicrm.org/confluence/display/CRM/Testing
135 *
136 * API Standards documentation:
137 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
138 */