Merge pull request #4246 from crusonweb/CRM-15310
[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 'is_active' => '1',
54 'visibility' => 'Public Pages',
55 'where_clause' => ' ( `civicrm_group_contact-1`.group_id IN ( 1 ) AND `civicrm_group_contact-1`.status IN (\"Added\") ) ',
56 '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 ) )\";}',
57 '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 ) )\";}',
58 'group_type' => array(
59 '0' => '1',
60 '1' => '2',
61 ),
62 'is_hidden' => 0,
63 'is_reserved' => 0,
64 ),
65 ),
66 ),
67 ),
68 '1' => array(
69 'id' => '2',
70 'group_id' => '1',
71 'contact_id' => '1',
72 'status' => 'Added',
73 'api.group.get' => array(
74 'is_error' => 0,
75 'version' => 3,
76 'count' => 1,
77 'id' => 1,
78 'values' => array(
79 '0' => array(
80 'id' => '1',
81 'name' => 'Test Group 1',
82 'title' => 'New Test Group Created',
83 'description' => 'New Test Group Created',
84 'is_active' => '1',
85 'visibility' => 'Public Pages',
86 'where_clause' => ' ( `civicrm_group_contact-1`.group_id IN ( 1 ) AND `civicrm_group_contact-1`.status IN (\"Added\") ) ',
87 '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 ) )\";}',
88 '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 ) )\";}',
89 'group_type' => array(
90 '0' => '1',
91 '1' => '2',
92 ),
93 'is_hidden' => 0,
94 'is_reserved' => 0,
95 ),
96 ),
97 ),
98 ),
99 ),
100 );
101
102 return $expectedResult;
103 }
104
105
106 /*
107 * This example has been generated from the API test suite. The test that created it is called
108 *
109 * testGetGroupID and can be found in
110 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GroupContactTest.php
111 *
112 * You can see the outcome of the API tests at
113 * https://test.civicrm.org/job/CiviCRM-master-git/
114 *
115 * To Learn about the API read
116 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
117 *
118 * Browse the api on your own site with the api explorer
119 * http://MYSITE.ORG/path/to/civicrm/api/explorer
120 *
121 * Read more about testing here
122 * http://wiki.civicrm.org/confluence/display/CRM/Testing
123 *
124 * API Standards documentation:
125 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
126 */