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