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