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