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