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