updated examples
[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',
53 'source' => '',
54 'saved_search_id' => '',
55 'is_active' => '1',
56 'visibility' => 'Public Pages',
b259a4ab
EM
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 ) )\";}',
53ca8fd7 60 'group_type' => array(
6a488035
TO
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 ),
53ca8fd7 75 '1' => array(
6a488035
TO
76 'id' => '2',
77 'group_id' => '1',
78 'contact_id' => '1',
79 'status' => 'Added',
53ca8fd7 80 'api.group.get' => array(
6a488035
TO
81 'is_error' => 0,
82 'version' => 3,
83 'count' => 1,
84 'id' => 1,
53ca8fd7 85 'values' => array(
86 '0' => array(
6a488035 87 'id' => '1',
b259a4ab 88 'name' => 'Test Group 1',
6a488035
TO
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',
b259a4ab
EM
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 ) )\";}',
53ca8fd7 98 'group_type' => array(
6a488035
TO
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
fb32de45 116 return $expectedResult;
6a488035
TO
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* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/GroupContactTest.php
125*
126* You can see the outcome of the API tests at
127* http://tests.dev.civicrm.org/trunk/results-api_v3
128*
129* To Learn about the API read
130* http://book.civicrm.org/developer/current/techniques/api/
131*
132* and review the wiki at
133* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
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
b259a4ab 140*/