Merge branch 'phpunit-ob-fix' of https://github.com/giant-rabbit/civicrm-core into...
[civicrm-core.git] / api / v3 / examples / GroupContact / GetWithGroupID.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using group_contact get API
4 * Get all from group and display contacts *
6a488035
TO
5 */
6function group_contact_get_example(){
53ca8fd7 7$params = array(
6a488035 8 'group_id' => 1,
6a488035
TO
9 'api.group.get' => 1,
10 'sequential' => 1,
11);
12
fb32de45 13try{
14 $result = civicrm_api3('group_contact', 'get', $params);
15}
16catch (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}
6a488035 23
fb32de45 24return $result;
6a488035
TO
25}
26
fb32de45 27/**
6a488035
TO
28 * Function returns array of result expected from previous function
29 */
30function group_contact_get_expectedresult(){
31
53ca8fd7 32 $expectedResult = array(
6a488035
TO
33 'is_error' => 0,
34 'version' => 3,
35 'count' => 2,
53ca8fd7 36 'values' => array(
37 '0' => array(
6a488035
TO
38 'id' => '1',
39 'group_id' => '1',
40 'contact_id' => '3',
41 'status' => 'Added',
53ca8fd7 42 'api.group.get' => array(
6a488035
TO
43 'is_error' => 0,
44 'version' => 3,
45 'count' => 1,
46 'id' => 1,
53ca8fd7 47 'values' => array(
48 '0' => array(
6a488035 49 'id' => '1',
b259a4ab 50 'name' => 'Test Group 1',
6a488035
TO
51 'title' => 'New Test Group Created',
52 'description' => 'New Test Group Created',
6a488035
TO
53 'is_active' => '1',
54 'visibility' => 'Public Pages',
b259a4ab
EM
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 ) )\";}',
53ca8fd7 58 'group_type' => array(
6a488035
TO
59 '0' => '1',
60 '1' => '2',
61 ),
6a488035
TO
62 'is_hidden' => 0,
63 'is_reserved' => 0,
6a488035
TO
64 ),
65 ),
66 ),
67 ),
53ca8fd7 68 '1' => array(
6a488035
TO
69 'id' => '2',
70 'group_id' => '1',
71 'contact_id' => '1',
72 'status' => 'Added',
53ca8fd7 73 'api.group.get' => array(
6a488035
TO
74 'is_error' => 0,
75 'version' => 3,
76 'count' => 1,
77 'id' => 1,
53ca8fd7 78 'values' => array(
79 '0' => array(
6a488035 80 'id' => '1',
b259a4ab 81 'name' => 'Test Group 1',
6a488035
TO
82 'title' => 'New Test Group Created',
83 'description' => 'New Test Group Created',
6a488035
TO
84 'is_active' => '1',
85 'visibility' => 'Public Pages',
b259a4ab
EM
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 ) )\";}',
53ca8fd7 89 'group_type' => array(
6a488035
TO
90 '0' => '1',
91 '1' => '2',
92 ),
6a488035
TO
93 'is_hidden' => 0,
94 'is_reserved' => 0,
6a488035
TO
95 ),
96 ),
97 ),
98 ),
99 ),
100);
101
fb32de45 102 return $expectedResult;
6a488035
TO
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
69d79249 110* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GroupContactTest.php
6a488035
TO
111*
112* You can see the outcome of the API tests at
69d79249 113* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
114*
115* To Learn about the API read
69d79249 116* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 117*
69d79249
E
118* Browse the api on your own site with the api explorer
119* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
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
b259a4ab 126*/