Merge pull request #5097 from PalanteJon/CRM-15917
[civicrm-core.git] / api / v3 / examples / Activity / Create.php
1 <?php
2 /**
3 * Test Generated example of using activity create API.
4 *
5 *
6 * @return array
7 * API result array
8 */
9 function activity_create_example() {
10 $params = array(
11 'source_contact_id' => 1,
12 'activity_type_id' => '51',
13 'subject' => 'test activity type id',
14 'activity_date_time' => '2011-06-02 14:36:13',
15 'status_id' => 2,
16 'priority_id' => 1,
17 'duration' => 120,
18 'location' => 'Pennsylvania',
19 'details' => 'a test activity',
20 'custom_1' => 'custom string',
21 );
22
23 try{
24 $result = civicrm_api3('activity', 'create', $params);
25 }
26 catch (CiviCRM_API3_Exception $e) {
27 // Handle error here.
28 $errorMessage = $e->getMessage();
29 $errorCode = $e->getErrorCode();
30 $errorData = $e->getExtraParams();
31 return array(
32 'error' => $errorMessage,
33 'error_code' => $errorCode,
34 'error_data' => $errorData,
35 );
36 }
37
38 return $result;
39 }
40
41 /**
42 * Function returns array of result expected from previous function.
43 *
44 * @return array
45 * API result array
46 */
47 function activity_create_expectedresult() {
48
49 $expectedResult = array(
50 'is_error' => 0,
51 'version' => 3,
52 'count' => 1,
53 'id' => 1,
54 'values' => array(
55 '1' => array(
56 'id' => '1',
57 'source_record_id' => '',
58 'activity_type_id' => '51',
59 'subject' => 'test activity type id',
60 'activity_date_time' => '20110602143613',
61 'duration' => '120',
62 'location' => 'Pennsylvania',
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' => '',
80 ),
81 ),
82 );
83
84 return $expectedResult;
85 }
86
87 /**
88 * This example has been generated from the API test suite.
89 * The test that created it is called
90 * testActivityCreateCustom
91 * and can be found in
92 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php
93 *
94 * You can see the outcome of the API tests at
95 * https://test.civicrm.org/job/CiviCRM-master-git/
96 *
97 * To Learn about the API read
98 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
99 *
100 * Browse the api on your own site with the api explorer
101 * http://MYSITE.ORG/path/to/civicrm/api
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
108 */