Merge branch 'rcsheets-docstring-cleanup'
[civicrm-core.git] / api / v3 / examples / Contact / GetSingleContact.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using contact getsingle API
4 * This demonstrates use of the 'format.single_entity_array' param.
6a488035 5 /* This param causes the only contact to be returned as an array without the other levels.
fb32de45 6 /* it will be ignored if there is not exactly 1 result *
6a488035
TO
7 */
8function contact_getsingle_example(){
edb0d67a 9$params = array(
6a488035
TO
10 'id' => 17,
11);
12
fb32de45 13try{
14 $result = civicrm_api3('contact', 'getsingle', $params);
15}
16catch (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}
6a488035 23
fb32de45 24return $result;
6a488035
TO
25}
26
fb32de45 27/**
6a488035
TO
28 * Function returns array of result expected from previous function
29 */
30function contact_getsingle_expectedresult(){
31
edb0d67a 32 $expectedResult = array(
6a488035
TO
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' => '',
b259a4ab
EM
49 'preferred_communication_method' => '',
50 'preferred_language' => '',
6a488035
TO
51 'preferred_mail_format' => '',
52 'first_name' => 'Test',
53 'middle_name' => '',
54 'last_name' => 'Contact',
6ecbca5b 55 'prefix_id' => '',
56 'suffix_id' => '',
6a488035 57 'job_title' => '',
6ecbca5b 58 'gender_id' => '',
6a488035
TO
59 'birth_date' => '',
60 'is_deceased' => 0,
61 'deceased_date' => '',
62 'household_name' => '',
63 'organization_name' => '',
64 'sic_code' => '',
65 'contact_is_deleted' => 0,
6a488035
TO
66 'current_employer' => '',
67 'address_id' => '',
68 'street_address' => '',
69 'supplemental_address_1' => '',
70 'supplemental_address_2' => '',
71 'city' => '',
72 'postal_code_suffix' => '',
73 'postal_code' => '',
74 'geo_code_1' => '',
75 'geo_code_2' => '',
76 'state_province_id' => '',
6a488035 77 'country_id' => '',
6a488035
TO
78 'phone_id' => '',
79 'phone_type_id' => '',
80 'phone' => '',
81 'email_id' => '',
82 'email' => '',
83 'on_hold' => '',
84 'im_id' => '',
85 'provider_id' => '',
86 'im' => '',
87 'worldregion_id' => '',
88 'world_region' => '',
6ecbca5b 89 'individual_prefix' => '',
90 'individual_suffix' => '',
91 'gender' => '',
9f1b81e0 92 'state_province_name' => '',
93 'state_province' => '',
94 'country' => '',
6a488035
TO
95 'id' => '17',
96);
97
fb32de45 98 return $expectedResult;
6a488035
TO
99}
100
101
102/*
103* This example has been generated from the API test suite. The test that created it is called
104*
105* testContactGetSingle_entity_array and can be found in
69d79249 106* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
6a488035
TO
107*
108* You can see the outcome of the API tests at
69d79249 109* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
110*
111* To Learn about the API read
69d79249 112* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 113*
69d79249
E
114* Browse the api on your own site with the api explorer
115* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
116*
117* Read more about testing here
118* http://wiki.civicrm.org/confluence/display/CRM/Testing
119*
120* API Standards documentation:
121* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 122*/