Merge pull request #9779 from WeMoveEU/CRM-19963
[civicrm-core.git] / api / v3 / examples / Contact / GroupFilterUsingContactAPI.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Contact.get API.
50fb255d 4 *
5c49fee0 5 * Get all from group and display contacts.
50fb255d 6 *
7 * @return array
8 * API result array
9 */
10function contact_get_example() {
11 $params = array(
bd6de801
SL
12 'group' => array(
13 'IN' => array(
d0aa0e47
SL
14 '0' => 'Test group C',
15 '1' => 'Test group D',
bd6de801 16 ),
6a488035 17 ),
50fb255d 18 );
6a488035 19
50fb255d 20 try{
a828d7b8 21 $result = civicrm_api3('Contact', 'get', $params);
50fb255d 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(
5be22f39 29 'is_error' => 1,
30 'error_message' => $errorMessage,
50fb255d 31 'error_code' => $errorCode,
32 'error_data' => $errorData,
33 );
34 }
6a488035 35
50fb255d 36 return $result;
6a488035
TO
37}
38
fb32de45 39/**
50fb255d 40 * Function returns array of result expected from previous function.
41 *
42 * @return array
43 * API result array
6a488035 44 */
50fb255d 45function contact_get_expectedresult() {
6a488035 46
edb0d67a 47 $expectedResult = array(
50fb255d 48 'is_error' => 0,
49 'version' => 3,
50 'count' => 1,
1d8ee3d6 51 'id' => 3,
50fb255d 52 'values' => array(
1d8ee3d6 53 '3' => array(
54 'contact_id' => '3',
50fb255d 55 'contact_type' => 'Individual',
56 'contact_sub_type' => '',
d0aa0e47
SL
57 'sort_name' => 'Groupmember, Test2',
58 'display_name' => 'Test2 Groupmember',
50fb255d 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',
d0aa0e47 73 'first_name' => 'Test2',
50fb255d 74 'middle_name' => '',
d0aa0e47 75 'last_name' => 'Groupmember',
50fb255d 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' => '',
1d8ee3d6 90 'address_id' => '',
91 'street_address' => '',
50fb255d 92 'supplemental_address_1' => '',
93 'supplemental_address_2' => '',
207f62c6 94 'supplemental_address_3' => '',
50fb255d 95 'city' => '',
96 'postal_code_suffix' => '',
97 'postal_code' => '',
98 'geo_code_1' => '',
99 'geo_code_2' => '',
100 'state_province_id' => '',
101 'country_id' => '',
102 'phone_id' => '',
103 'phone_type_id' => '',
104 'phone' => '',
105 'email_id' => '1',
d0aa0e47 106 'email' => 'test@example.org',
50fb255d 107 'on_hold' => 0,
108 'im_id' => '',
109 'provider_id' => '',
110 'im' => '',
111 'worldregion_id' => '',
112 'world_region' => '',
83d02301 113 'languages' => 'English (United States)',
50fb255d 114 'individual_prefix' => '',
115 'individual_suffix' => '',
116 'communication_style' => '',
117 'gender' => '',
118 'state_province_name' => '',
119 'state_province' => '',
120 'country' => '',
1d8ee3d6 121 'id' => '3',
50fb255d 122 ),
6a488035 123 ),
50fb255d 124 );
6a488035 125
fb32de45 126 return $expectedResult;
6a488035
TO
127}
128
a828d7b8 129/*
50fb255d 130* This example has been generated from the API test suite.
d0aa0e47 131* The test that created it is called "testContactGetWithGroupTitleMultipleGroups"
a828d7b8 132* and can be found at:
69d79249 133* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
6a488035
TO
134*
135* You can see the outcome of the API tests at
69d79249 136* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
137*
138* To Learn about the API read
69d79249 139* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 140*
69d79249 141* Browse the api on your own site with the api explorer
41d4d31f 142* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
143*
144* Read more about testing here
145* http://wiki.civicrm.org/confluence/display/CRM/Testing
146*
147* API Standards documentation:
148* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 149*/