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