Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
3 | * Test Generated example of using membership get API. | |
4 | * | |
5 | * Demonstrates use of 'filter' active_only' param | |
6 | * | |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function membership_get_example() { | |
11 | $params = array( | |
12 | 'contact_id' => 44, | |
13 | 'filters' => array( | |
6a488035 TO |
14 | 'is_current' => 1, |
15 | ), | |
50fb255d | 16 | ); |
6a488035 | 17 | |
50fb255d | 18 | try{ |
19 | $result = civicrm_api3('membership', 'get', $params); | |
20 | } | |
21 | catch (CiviCRM_API3_Exception $e) { | |
22 | // Handle error here. | |
23 | $errorMessage = $e->getMessage(); | |
24 | $errorCode = $e->getErrorCode(); | |
25 | $errorData = $e->getExtraParams(); | |
26 | return array( | |
27 | 'error' => $errorMessage, | |
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 membership_get_expectedresult() { |
6a488035 | 43 | |
53ca8fd7 | 44 | $expectedResult = array( |
50fb255d | 45 | 'is_error' => 0, |
46 | 'version' => 3, | |
47 | 'count' => 1, | |
48 | 'id' => 1, | |
49 | 'values' => array( | |
53ca8fd7 | 50 | '1' => array( |
50fb255d | 51 | 'id' => '1', |
52 | 'contact_id' => '44', | |
53 | 'membership_type_id' => '27', | |
54 | 'join_date' => '2009-01-21', | |
55 | 'start_date' => '2013-07-29 00:00:00', | |
56 | 'end_date' => '2013-08-04 00:00:00', | |
57 | 'source' => 'Payment', | |
58 | 'status_id' => '21', | |
59 | 'is_override' => '1', | |
60 | 'is_test' => 0, | |
61 | 'is_pay_later' => 0, | |
62 | 'membership_name' => 'General', | |
63 | 'relationship_name' => 'Child of', | |
64 | ), | |
6a488035 | 65 | ), |
50fb255d | 66 | ); |
6a488035 | 67 | |
fb32de45 | 68 | return $expectedResult; |
6a488035 TO |
69 | } |
70 | ||
50fb255d | 71 | /** |
72 | * This example has been generated from the API test suite. | |
73 | * The test that created it is called | |
74 | * testGetOnlyActive | |
75 | * and can be found in | |
69d79249 | 76 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/MembershipTest.php |
6a488035 TO |
77 | * |
78 | * You can see the outcome of the API tests at | |
69d79249 | 79 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
80 | * |
81 | * To Learn about the API read | |
69d79249 | 82 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 83 | * |
69d79249 | 84 | * Browse the api on your own site with the api explorer |
41d4d31f | 85 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
86 | * |
87 | * Read more about testing here | |
88 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
89 | * | |
90 | * API Standards documentation: | |
91 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 92 | */ |