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