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