9fb931ea1886c688ab5f29ebce73172372ab03f3
[civicrm-core.git] / api / v3 / examples / Activity / Create.php
1 <?php
2 /**
3 * Test Generated example of using 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
89 * testActivityCreateCustom
90 * and can be found in
91 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php
92 *
93 * You can see the outcome of the API tests at
94 * https://test.civicrm.org/job/CiviCRM-master-git/
95 *
96 * To Learn about the API read
97 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
98 *
99 * Browse the api on your own site with the api explorer
100 * http://MYSITE.ORG/path/to/civicrm/api
101 *
102 * Read more about testing here
103 * http://wiki.civicrm.org/confluence/display/CRM/Testing
104 *
105 * API Standards documentation:
106 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
107 */