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