Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Relationship.create API. |
50fb255d | 4 | * |
50fb255d | 5 | * @return array |
6 | * API result array | |
7 | */ | |
8 | function relationship_create_example() { | |
9 | $params = array( | |
10 | 'contact_id_a' => 31, | |
11 | 'contact_id_b' => 33, | |
12 | 'relationship_type_id' => 18, | |
13 | 'start_date' => '2010-10-30', | |
14 | 'end_date' => '2010-12-30', | |
15 | 'is_active' => 1, | |
16 | 'note' => 'note', | |
17 | ); | |
6a488035 | 18 | |
50fb255d | 19 | try{ |
a828d7b8 | 20 | $result = civicrm_api3('Relationship', 'create', $params); |
50fb255d | 21 | } |
22 | catch (CiviCRM_API3_Exception $e) { | |
23 | // Handle error here. | |
24 | $errorMessage = $e->getMessage(); | |
25 | $errorCode = $e->getErrorCode(); | |
26 | $errorData = $e->getExtraParams(); | |
27 | return array( | |
28 | 'error' => $errorMessage, | |
29 | 'error_code' => $errorCode, | |
30 | 'error_data' => $errorData, | |
31 | ); | |
32 | } | |
33 | ||
34 | return $result; | |
6a488035 TO |
35 | } |
36 | ||
fb32de45 | 37 | /** |
50fb255d | 38 | * Function returns array of result expected from previous function. |
39 | * | |
40 | * @return array | |
41 | * API result array | |
6a488035 | 42 | */ |
50fb255d | 43 | function relationship_create_expectedresult() { |
6a488035 | 44 | |
26dcc9eb | 45 | $expectedResult = array( |
50fb255d | 46 | 'is_error' => 0, |
47 | 'version' => 3, | |
48 | 'count' => 1, | |
49 | 'id' => 1, | |
50 | 'values' => array( | |
26dcc9eb | 51 | '1' => array( |
50fb255d | 52 | 'id' => '1', |
53 | 'contact_id_a' => '31', | |
54 | 'contact_id_b' => '33', | |
55 | 'relationship_type_id' => '18', | |
56 | 'start_date' => '2013-07-29 00:00:00', | |
57 | 'end_date' => '2013-08-04 00:00:00', | |
58 | 'is_active' => '1', | |
59 | 'description' => '', | |
60 | 'is_permission_a_b' => 0, | |
61 | 'is_permission_b_a' => 0, | |
62 | 'case_id' => '', | |
63 | ), | |
6a488035 | 64 | ), |
50fb255d | 65 | ); |
6a488035 | 66 | |
fb32de45 | 67 | return $expectedResult; |
6a488035 TO |
68 | } |
69 | ||
a828d7b8 | 70 | /* |
50fb255d | 71 | * This example has been generated from the API test suite. |
a828d7b8 CW |
72 | * The test that created it is called "testRelationshipCreate" |
73 | * and can be found at: | |
69d79249 | 74 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/RelationshipTest.php |
6a488035 TO |
75 | * |
76 | * You can see the outcome of the API tests at | |
69d79249 | 77 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
78 | * |
79 | * To Learn about the API read | |
69d79249 | 80 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 81 | * |
69d79249 | 82 | * Browse the api on your own site with the api explorer |
41d4d31f | 83 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
84 | * |
85 | * Read more about testing here | |
86 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
87 | * | |
88 | * API Standards documentation: | |
89 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
49f8272d | 90 | */ |