Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the Activity.create API. |
50fb255d | 4 | * |
5c49fee0 | 5 | * Demonstrates create with Contact Reference Custom Field. |
50fb255d | 6 | * |
7 | * @return array | |
8 | * API result array | |
9 | */ | |
10 | function activity_create_example() { | |
11 | $params = array( | |
12 | 'source_contact_id' => 1, | |
13 | 'activity_type_id' => '51', | |
14 | 'subject' => 'test activity type id', | |
15 | 'activity_date_time' => '2011-06-02 14:36:13', | |
16 | 'status_id' => 2, | |
17 | 'priority_id' => 1, | |
18 | 'duration' => 120, | |
e3aa0dd1 | 19 | 'location' => 'Pennsylvania', |
50fb255d | 20 | 'details' => 'a test activity', |
21 | 'custom_2' => '1', | |
22 | ); | |
6a488035 | 23 | |
50fb255d | 24 | try{ |
a828d7b8 | 25 | $result = civicrm_api3('Activity', 'create', $params); |
50fb255d | 26 | } |
27 | catch (CiviCRM_API3_Exception $e) { | |
28 | // Handle error here. | |
29 | $errorMessage = $e->getMessage(); | |
30 | $errorCode = $e->getErrorCode(); | |
31 | $errorData = $e->getExtraParams(); | |
32 | return array( | |
33 | 'error' => $errorMessage, | |
34 | 'error_code' => $errorCode, | |
35 | 'error_data' => $errorData, | |
36 | ); | |
37 | } | |
38 | ||
39 | return $result; | |
6a488035 TO |
40 | } |
41 | ||
fb32de45 | 42 | /** |
50fb255d | 43 | * Function returns array of result expected from previous function. |
44 | * | |
45 | * @return array | |
46 | * API result array | |
6a488035 | 47 | */ |
50fb255d | 48 | function activity_create_expectedresult() { |
6a488035 | 49 | |
feb2a730 | 50 | $expectedResult = array( |
50fb255d | 51 | 'is_error' => 0, |
52 | 'version' => 3, | |
53 | 'count' => 1, | |
54 | 'id' => 1, | |
55 | 'values' => array( | |
feb2a730 | 56 | '1' => array( |
50fb255d | 57 | 'id' => '1', |
58 | 'source_record_id' => '', | |
59 | 'activity_type_id' => '51', | |
60 | 'subject' => 'test activity type id', | |
61 | 'activity_date_time' => '20110602143613', | |
62 | 'duration' => '120', | |
e3aa0dd1 | 63 | 'location' => 'Pennsylvania', |
50fb255d | 64 | 'phone_id' => '', |
65 | 'phone_number' => '', | |
66 | 'details' => 'a test activity', | |
67 | 'status_id' => '2', | |
68 | 'priority_id' => '1', | |
69 | 'parent_id' => '', | |
70 | 'is_test' => '', | |
71 | 'medium_id' => '', | |
72 | 'is_auto' => '', | |
73 | 'relationship_id' => '', | |
74 | 'is_current_revision' => '', | |
75 | 'original_id' => '', | |
76 | 'result' => '', | |
77 | 'is_deleted' => '', | |
78 | 'campaign_id' => '', | |
79 | 'engagement_level' => '', | |
80 | 'weight' => '', | |
81 | ), | |
6a488035 | 82 | ), |
50fb255d | 83 | ); |
6a488035 | 84 | |
fb32de45 | 85 | return $expectedResult; |
6a488035 TO |
86 | } |
87 | ||
a828d7b8 | 88 | /* |
50fb255d | 89 | * This example has been generated from the API test suite. |
a828d7b8 CW |
90 | * The test that created it is called "testActivityCreateCustomContactRefField" |
91 | * and can be found at: | |
69d79249 | 92 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php |
6a488035 TO |
93 | * |
94 | * You can see the outcome of the API tests at | |
69d79249 | 95 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
96 | * |
97 | * To Learn about the API read | |
69d79249 | 98 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 99 | * |
69d79249 | 100 | * Browse the api on your own site with the api explorer |
41d4d31f | 101 | * http://MYSITE.ORG/path/to/civicrm/api |
6a488035 TO |
102 | * |
103 | * Read more about testing here | |
104 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
105 | * | |
106 | * API Standards documentation: | |
107 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 108 | */ |