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