Merge pull request #1259 from kurund/eval-fixes
[civicrm-core.git] / api / v3 / examples / Contact / GetSingleContact.php
1 <?php
2 /**
3 * Test Generated example of using contact getsingle API
4 * This demonstrates use of the 'format.single_entity_array' param.
5 /* This param causes the only contact to be returned as an array without the other levels.
6 /* it will be ignored if there is not exactly 1 result *
7 */
8 function contact_getsingle_example(){
9 $params = array(
10 'id' => 17,
11 );
12
13 try{
14 $result = civicrm_api3('contact', 'getsingle', $params);
15 }
16 catch (CiviCRM_API3_Exception $e) {
17 // handle error here
18 $errorMessage = $e->getMessage();
19 $errorCode = $e->getErrorCode();
20 $errorData = $e->getExtraParams();
21 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
22 }
23
24 return $result;
25 }
26
27 /**
28 * Function returns array of result expected from previous function
29 */
30 function contact_getsingle_expectedresult(){
31
32 $expectedResult = array(
33 'contact_id' => '17',
34 'contact_type' => 'Individual',
35 'contact_sub_type' => '',
36 'sort_name' => '',
37 'display_name' => 'Test Contact',
38 'do_not_email' => '',
39 'do_not_phone' => '',
40 'do_not_mail' => '',
41 'do_not_sms' => '',
42 'do_not_trade' => '',
43 'is_opt_out' => 0,
44 'legal_identifier' => '',
45 'external_identifier' => '',
46 'nick_name' => '',
47 'legal_name' => '',
48 'image_URL' => '',
49 'preferred_mail_format' => '',
50 'first_name' => 'Test',
51 'middle_name' => '',
52 'last_name' => 'Contact',
53 'job_title' => '',
54 'birth_date' => '',
55 'is_deceased' => 0,
56 'deceased_date' => '',
57 'household_name' => '',
58 'organization_name' => '',
59 'sic_code' => '',
60 'contact_is_deleted' => 0,
61 'current_employer' => '',
62 'address_id' => '',
63 'street_address' => '',
64 'supplemental_address_1' => '',
65 'supplemental_address_2' => '',
66 'city' => '',
67 'postal_code_suffix' => '',
68 'postal_code' => '',
69 'geo_code_1' => '',
70 'geo_code_2' => '',
71 'state_province_id' => '',
72 'state_province_name' => '',
73 'state_province' => '',
74 'country_id' => '',
75 'country' => '',
76 'phone_id' => '',
77 'phone_type_id' => '',
78 'phone' => '',
79 'email_id' => '',
80 'email' => '',
81 'on_hold' => '',
82 'im_id' => '',
83 'provider_id' => '',
84 'im' => '',
85 'worldregion_id' => '',
86 'world_region' => '',
87 'id' => '17',
88 );
89
90 return $expectedResult;
91 }
92
93
94 /*
95 * This example has been generated from the API test suite. The test that created it is called
96 *
97 * testContactGetSingle_entity_array and can be found in
98 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
99 *
100 * You can see the outcome of the API tests at
101 * http://tests.dev.civicrm.org/trunk/results-api_v3
102 *
103 * To Learn about the API read
104 * http://book.civicrm.org/developer/current/techniques/api/
105 *
106 * and review the wiki at
107 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
108 *
109 * Read more about testing here
110 * http://wiki.civicrm.org/confluence/display/CRM/Testing
111 *
112 * API Standards documentation:
113 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
114 */