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