Merge pull request #4274 from mrpaulc/CRM-14868
[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' => '',
89bf81b4 57 'formal_title' => '',
58 'communication_style_id' => '',
6a488035 59 'job_title' => '',
6ecbca5b 60 'gender_id' => '',
6a488035
TO
61 'birth_date' => '',
62 'is_deceased' => 0,
63 'deceased_date' => '',
64 'household_name' => '',
65 'organization_name' => '',
66 'sic_code' => '',
67 'contact_is_deleted' => 0,
6a488035
TO
68 'current_employer' => '',
69 'address_id' => '',
70 'street_address' => '',
71 'supplemental_address_1' => '',
72 'supplemental_address_2' => '',
73 'city' => '',
74 'postal_code_suffix' => '',
75 'postal_code' => '',
76 'geo_code_1' => '',
77 'geo_code_2' => '',
78 'state_province_id' => '',
6a488035 79 'country_id' => '',
6a488035
TO
80 'phone_id' => '',
81 'phone_type_id' => '',
82 'phone' => '',
83 'email_id' => '',
84 'email' => '',
85 'on_hold' => '',
86 'im_id' => '',
87 'provider_id' => '',
88 'im' => '',
89 'worldregion_id' => '',
90 'world_region' => '',
6ecbca5b 91 'individual_prefix' => '',
92 'individual_suffix' => '',
89bf81b4 93 'communication_style' => '',
6ecbca5b 94 'gender' => '',
9f1b81e0 95 'state_province_name' => '',
96 'state_province' => '',
97 'country' => '',
6a488035
TO
98 'id' => '17',
99);
100
fb32de45 101 return $expectedResult;
6a488035
TO
102}
103
104
105/*
106* This example has been generated from the API test suite. The test that created it is called
107*
108* testContactGetSingle_entity_array and can be found in
69d79249 109* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
6a488035
TO
110*
111* You can see the outcome of the API tests at
69d79249 112* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
113*
114* To Learn about the API read
69d79249 115* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 116*
69d79249
E
117* Browse the api on your own site with the api explorer
118* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
119*
120* Read more about testing here
121* http://wiki.civicrm.org/confluence/display/CRM/Testing
122*
123* API Standards documentation:
124* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 125*/