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