Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the GroupContact.get API. |
50fb255d | 4 | * |
5c49fee0 | 5 | * Get all from group and display contacts. |
50fb255d | 6 | * |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function group_contact_get_example() { | |
11 | $params = array( | |
12 | 'group_id' => 3, | |
13 | 'api.group.get' => 1, | |
14 | 'sequential' => 1, | |
15 | ); | |
16 | ||
17 | try{ | |
a828d7b8 | 18 | $result = civicrm_api3('GroupContact', 'get', $params); |
50fb255d | 19 | } |
20 | catch (CiviCRM_API3_Exception $e) { | |
21 | // Handle error here. | |
22 | $errorMessage = $e->getMessage(); | |
23 | $errorCode = $e->getErrorCode(); | |
24 | $errorData = $e->getExtraParams(); | |
25 | return array( | |
26 | 'error' => $errorMessage, | |
27 | 'error_code' => $errorCode, | |
28 | 'error_data' => $errorData, | |
29 | ); | |
30 | } | |
6a488035 | 31 | |
50fb255d | 32 | return $result; |
6a488035 TO |
33 | } |
34 | ||
fb32de45 | 35 | /** |
50fb255d | 36 | * Function returns array of result expected from previous function. |
37 | * | |
38 | * @return array | |
39 | * API result array | |
6a488035 | 40 | */ |
50fb255d | 41 | function group_contact_get_expectedresult() { |
6a488035 | 42 | |
53ca8fd7 | 43 | $expectedResult = array( |
50fb255d | 44 | 'is_error' => 0, |
45 | 'version' => 3, | |
46 | 'count' => 1, | |
47 | 'id' => 2, | |
48 | 'values' => array( | |
53ca8fd7 | 49 | '0' => array( |
50fb255d | 50 | 'id' => '2', |
51 | 'group_id' => '3', | |
52 | 'contact_id' => '4', | |
53 | 'status' => 'Added', | |
54 | 'api.group.get' => array( | |
55 | 'is_error' => 0, | |
56 | 'version' => 3, | |
57 | 'count' => 1, | |
58 | 'id' => 3, | |
59 | 'values' => array( | |
60 | '0' => array( | |
61 | 'id' => '3', | |
62 | 'name' => 'Test Group 1', | |
63 | 'title' => 'New Test Group Created', | |
64 | 'description' => 'New Test Group Created', | |
65 | 'is_active' => '1', | |
66 | 'visibility' => 'Public Pages', | |
67 | 'where_clause' => ' ( `civicrm_group_contact-3`.group_id IN ( 3 ) AND `civicrm_group_contact-3`.status IN (\"Added\") ) ', | |
68 | '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-3`\";s:165:\" LEFT JOIN civicrm_group_contact `civicrm_group_contact-3` ON ( contact_a.id = `civicrm_group_contact-3`.contact_id AND `civicrm_group_contact-3`.group_id IN ( 3 ) )\";}', | |
69 | 'where_tables' => 'a:2:{s:15:\"civicrm_contact\";i:1;s:25:\"`civicrm_group_contact-3`\";s:165:\" LEFT JOIN civicrm_group_contact `civicrm_group_contact-3` ON ( contact_a.id = `civicrm_group_contact-3`.contact_id AND `civicrm_group_contact-3`.group_id IN ( 3 ) )\";}', | |
70 | 'group_type' => array( | |
71 | '0' => '1', | |
72 | '1' => '2', | |
73 | ), | |
74 | 'is_hidden' => 0, | |
75 | 'is_reserved' => 0, | |
6a488035 | 76 | ), |
50fb255d | 77 | ), |
6a488035 | 78 | ), |
50fb255d | 79 | ), |
6a488035 | 80 | ), |
50fb255d | 81 | ); |
6a488035 | 82 | |
fb32de45 | 83 | return $expectedResult; |
6a488035 TO |
84 | } |
85 | ||
a828d7b8 | 86 | /* |
50fb255d | 87 | * This example has been generated from the API test suite. |
a828d7b8 CW |
88 | * The test that created it is called "testGetGroupID" |
89 | * and can be found at: | |
69d79249 | 90 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/GroupContactTest.php |
6a488035 TO |
91 | * |
92 | * You can see the outcome of the API tests at | |
69d79249 | 93 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
94 | * |
95 | * To Learn about the API read | |
69d79249 | 96 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 97 | * |
69d79249 | 98 | * Browse the api on your own site with the api explorer |
41d4d31f | 99 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
100 | * |
101 | * Read more about testing here | |
102 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
103 | * | |
104 | * API Standards documentation: | |
105 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 106 | */ |