Merge pull request #2540 from eileenmcnaughton/CRM-14235
[civicrm-core.git] / api / v3 / examples / GroupContact / GetWithGroupID.php
1 <?php
2 /**
3 * Test Generated example of using group_contact get API
4 * Get all from group and display contacts *
5 */
6 function group_contact_get_example(){
7 $params = array(
8 'group_id' => 1,
9 'api.group.get' => 1,
10 'sequential' => 1,
11 );
12
13 try{
14 $result = civicrm_api3('group_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('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
22 }
23
24 return $result;
25 }
26
27 /**
28 * Function returns array of result expected from previous function
29 */
30 function group_contact_get_expectedresult(){
31
32 $expectedResult = array(
33 'is_error' => 0,
34 'version' => 3,
35 'count' => 2,
36 'values' => array(
37 '0' => array(
38 'id' => '1',
39 'group_id' => '1',
40 'contact_id' => '3',
41 'status' => 'Added',
42 'api.group.get' => array(
43 'is_error' => 0,
44 'version' => 3,
45 'count' => 1,
46 'id' => 1,
47 'values' => array(
48 '0' => array(
49 'id' => '1',
50 'name' => 'Test Group 1',
51 'title' => 'New Test Group Created',
52 'description' => 'New Test Group Created',
53 'source' => '',
54 'saved_search_id' => '',
55 'is_active' => '1',
56 'visibility' => 'Public Pages',
57 'where_clause' => ' ( `civicrm_group_contact-1`.group_id IN ( 1 ) AND `civicrm_group_contact-1`.status IN (\"Added\") ) ',
58 'select_tables' => 'a:8:{s:15:\"civicrm_contact\";i:1;s:15:\"civicrm_address\";i:1;s:15:\"civicrm_country\";i:1;s:13:\"civicrm_email\";i:1;s:13:\"civicrm_phone\";i:1;s:10:\"civicrm_im\";i:1;s:19:\"civicrm_worldregion\";i:1;s:25:\"`civicrm_group_contact-1`\";s:165:\" LEFT JOIN civicrm_group_contact `civicrm_group_contact-1` ON ( contact_a.id = `civicrm_group_contact-1`.contact_id AND `civicrm_group_contact-1`.group_id IN ( 1 ) )\";}',
59 'where_tables' => 'a:2:{s:15:\"civicrm_contact\";i:1;s:25:\"`civicrm_group_contact-1`\";s:165:\" LEFT JOIN civicrm_group_contact `civicrm_group_contact-1` ON ( contact_a.id = `civicrm_group_contact-1`.contact_id AND `civicrm_group_contact-1`.group_id IN ( 1 ) )\";}',
60 'group_type' => array(
61 '0' => '1',
62 '1' => '2',
63 ),
64 'cache_date' => '',
65 'refresh_date' => '',
66 'parents' => '',
67 'children' => '',
68 'is_hidden' => 0,
69 'is_reserved' => 0,
70 'created_id' => '',
71 ),
72 ),
73 ),
74 ),
75 '1' => array(
76 'id' => '2',
77 'group_id' => '1',
78 'contact_id' => '1',
79 'status' => 'Added',
80 'api.group.get' => array(
81 'is_error' => 0,
82 'version' => 3,
83 'count' => 1,
84 'id' => 1,
85 'values' => array(
86 '0' => array(
87 'id' => '1',
88 'name' => 'Test Group 1',
89 'title' => 'New Test Group Created',
90 'description' => 'New Test Group Created',
91 'source' => '',
92 'saved_search_id' => '',
93 'is_active' => '1',
94 'visibility' => 'Public Pages',
95 'where_clause' => ' ( `civicrm_group_contact-1`.group_id IN ( 1 ) AND `civicrm_group_contact-1`.status IN (\"Added\") ) ',
96 'select_tables' => 'a:8:{s:15:\"civicrm_contact\";i:1;s:15:\"civicrm_address\";i:1;s:15:\"civicrm_country\";i:1;s:13:\"civicrm_email\";i:1;s:13:\"civicrm_phone\";i:1;s:10:\"civicrm_im\";i:1;s:19:\"civicrm_worldregion\";i:1;s:25:\"`civicrm_group_contact-1`\";s:165:\" LEFT JOIN civicrm_group_contact `civicrm_group_contact-1` ON ( contact_a.id = `civicrm_group_contact-1`.contact_id AND `civicrm_group_contact-1`.group_id IN ( 1 ) )\";}',
97 'where_tables' => 'a:2:{s:15:\"civicrm_contact\";i:1;s:25:\"`civicrm_group_contact-1`\";s:165:\" LEFT JOIN civicrm_group_contact `civicrm_group_contact-1` ON ( contact_a.id = `civicrm_group_contact-1`.contact_id AND `civicrm_group_contact-1`.group_id IN ( 1 ) )\";}',
98 'group_type' => array(
99 '0' => '1',
100 '1' => '2',
101 ),
102 'cache_date' => '',
103 'refresh_date' => '',
104 'parents' => '',
105 'children' => '',
106 'is_hidden' => 0,
107 'is_reserved' => 0,
108 'created_id' => '',
109 ),
110 ),
111 ),
112 ),
113 ),
114 );
115
116 return $expectedResult;
117 }
118
119
120 /*
121 * This example has been generated from the API test suite. The test that created it is called
122 *
123 * testGetGroupID and can be found in
124 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GroupContactTest.php
125 *
126 * You can see the outcome of the API tests at
127 * https://test.civicrm.org/job/CiviCRM-master-git/
128 *
129 * To Learn about the API read
130 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
131 *
132 * Browse the api on your own site with the api explorer
133 * http://MYSITE.ORG/path/to/civicrm/api/explorer
134 *
135 * Read more about testing here
136 * http://wiki.civicrm.org/confluence/display/CRM/Testing
137 *
138 * API Standards documentation:
139 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
140 */