Merge pull request #5035 from TeNNoX/master
[civicrm-core.git] / api / v3 / examples / Contact / GetSingleContact.php
1 <?php
2 /**
3 * @file
4 * Test Generated API Example.
5 * See bottom of this file for more detail.
6 */
7
8 /**
9 * Test Generated example of using contact getsingle API.
10 *
11 * This demonstrates use of the 'format.single_entity_array' param.
12 /* This param causes the only contact to be returned as an array without the other levels.
13 /* it will be ignored if there is not exactly 1 result
14 *
15 * @return array
16 * API result array
17 */
18 function contact_getsingle_example() {
19 $params = array(
20 'id' => 17,
21 );
22
23 try{
24 $result = civicrm_api3('contact', 'getsingle', $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 array(
32 'error' => $errorMessage,
33 'error_code' => $errorCode,
34 'error_data' => $errorData,
35 );
36 }
37
38 return $result;
39 }
40
41 /**
42 * Function returns array of result expected from previous function.
43 *
44 * @return array
45 * API result array
46 */
47 function contact_getsingle_expectedresult() {
48
49 $expectedResult = array(
50 'contact_id' => '17',
51 'contact_type' => 'Individual',
52 'contact_sub_type' => '',
53 'sort_name' => '',
54 'display_name' => 'Test Contact',
55 'do_not_email' => '',
56 'do_not_phone' => '',
57 'do_not_mail' => '',
58 'do_not_sms' => '',
59 'do_not_trade' => '',
60 'is_opt_out' => 0,
61 'legal_identifier' => '',
62 'external_identifier' => '',
63 'nick_name' => '',
64 'legal_name' => '',
65 'image_URL' => '',
66 'preferred_communication_method' => '',
67 'preferred_language' => '',
68 'preferred_mail_format' => '',
69 'first_name' => 'Test',
70 'middle_name' => '',
71 'last_name' => 'Contact',
72 'prefix_id' => '',
73 'suffix_id' => '',
74 'formal_title' => '',
75 'communication_style_id' => '',
76 'job_title' => '',
77 'gender_id' => '',
78 'birth_date' => '',
79 'is_deceased' => 0,
80 'deceased_date' => '',
81 'household_name' => '',
82 'organization_name' => '',
83 'sic_code' => '',
84 'contact_is_deleted' => 0,
85 'current_employer' => '',
86 'address_id' => '',
87 'street_address' => '',
88 'supplemental_address_1' => '',
89 'supplemental_address_2' => '',
90 'city' => '',
91 'postal_code_suffix' => '',
92 'postal_code' => '',
93 'geo_code_1' => '',
94 'geo_code_2' => '',
95 'state_province_id' => '',
96 'country_id' => '',
97 'phone_id' => '',
98 'phone_type_id' => '',
99 'phone' => '',
100 'email_id' => '',
101 'email' => '',
102 'on_hold' => '',
103 'im_id' => '',
104 'provider_id' => '',
105 'im' => '',
106 'worldregion_id' => '',
107 'world_region' => '',
108 'individual_prefix' => '',
109 'individual_suffix' => '',
110 'communication_style' => '',
111 'gender' => '',
112 'state_province_name' => '',
113 'state_province' => '',
114 'country' => '',
115 'id' => '17',
116 );
117
118 return $expectedResult;
119 }
120
121 /**
122 * This example has been generated from the API test suite.
123 * The test that created it is called
124 * testContactGetSingle_entity_array
125 * and can be found in
126 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
127 *
128 * You can see the outcome of the API tests at
129 * https://test.civicrm.org/job/CiviCRM-master-git/
130 *
131 * To Learn about the API read
132 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
133 *
134 * Browse the api on your own site with the api explorer
135 * http://MYSITE.ORG/path/to/civicrm/api/explorer
136 *
137 * Read more about testing here
138 * http://wiki.civicrm.org/confluence/display/CRM/Testing
139 *
140 * API Standards documentation:
141 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
142 */