Merge pull request #5174 from joannechester/patch-2
[civicrm-core.git] / api / v3 / examples / Activity / ReturnAssigneeContact.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
3 * Test Generated example of using activity get API.
4 *
5c49fee0 5 * Demonstrates getting asignee_contact_id & using it to get the contact.
50fb255d 6 *
7 * @return array
8 * API result array
9 */
10function activity_get_example() {
11 $params = array(
12 'activity_id' => 1,
13 'sequential' => 1,
14 'return.assignee_contact_id' => 1,
15 'api.contact.get' => array(
6a488035
TO
16 'id' => '$value.source_contact_id',
17 ),
50fb255d 18 );
6a488035 19
50fb255d 20 try{
21 $result = civicrm_api3('activity', 'get', $params);
22 }
23 catch (CiviCRM_API3_Exception $e) {
24 // Handle error here.
25 $errorMessage = $e->getMessage();
26 $errorCode = $e->getErrorCode();
27 $errorData = $e->getExtraParams();
28 return array(
29 'error' => $errorMessage,
30 'error_code' => $errorCode,
31 'error_data' => $errorData,
32 );
33 }
6a488035 34
50fb255d 35 return $result;
6a488035
TO
36}
37
fb32de45 38/**
50fb255d 39 * Function returns array of result expected from previous function.
40 *
41 * @return array
42 * API result array
6a488035 43 */
50fb255d 44function activity_get_expectedresult() {
6a488035 45
feb2a730 46 $expectedResult = array(
50fb255d 47 'is_error' => 0,
48 'version' => 3,
49 'count' => 1,
50 'id' => 1,
51 'values' => array(
feb2a730 52 '0' => array(
50fb255d 53 'id' => '1',
54 'activity_type_id' => '51',
55 'subject' => 'test activity type id',
56 'activity_date_time' => '2011-06-02 14:36:13',
57 'duration' => '120',
e3aa0dd1 58 'location' => 'Pennsylvania',
50fb255d 59 'details' => 'a test activity',
60 'status_id' => '2',
61 'priority_id' => '1',
62 'is_test' => 0,
63 'is_auto' => 0,
64 'is_current_revision' => '1',
65 'is_deleted' => 0,
66 'assignee_contact_id' => array(
67 '0' => '3',
68 ),
69 'source_contact_id' => '1',
70 'api.contact.get' => array(
71 'is_error' => 0,
72 'version' => 3,
73 'count' => 1,
74 'id' => 1,
75 'values' => array(
76 '0' => array(
77 'contact_id' => '1',
78 'contact_type' => 'Individual',
79 'contact_sub_type' => '',
80 'sort_name' => 'Anderson, Anthony',
81 'display_name' => 'Mr. Anthony Anderson II',
82 'do_not_email' => 0,
83 'do_not_phone' => 0,
84 'do_not_mail' => 0,
85 'do_not_sms' => 0,
86 'do_not_trade' => 0,
87 'is_opt_out' => 0,
88 'legal_identifier' => '',
89 'external_identifier' => '',
90 'nick_name' => '',
91 'legal_name' => '',
92 'image_URL' => '',
93 'preferred_communication_method' => '',
94 'preferred_language' => 'en_US',
95 'preferred_mail_format' => 'Both',
96 'first_name' => 'Anthony',
97 'middle_name' => 'J.',
98 'last_name' => 'Anderson',
99 'prefix_id' => '3',
100 'suffix_id' => '3',
101 'formal_title' => '',
102 'communication_style_id' => '',
103 'job_title' => '',
104 'gender_id' => '',
105 'birth_date' => '',
106 'is_deceased' => 0,
107 'deceased_date' => '',
108 'household_name' => '',
109 'organization_name' => '',
110 'sic_code' => '',
111 'contact_is_deleted' => 0,
112 'current_employer' => '',
113 'address_id' => '',
114 'street_address' => '',
115 'supplemental_address_1' => '',
116 'supplemental_address_2' => '',
117 'city' => '',
118 'postal_code_suffix' => '',
119 'postal_code' => '',
120 'geo_code_1' => '',
121 'geo_code_2' => '',
122 'state_province_id' => '',
123 'country_id' => '',
124 'phone_id' => '',
125 'phone_type_id' => '',
126 'phone' => '',
127 'email_id' => '1',
128 'email' => 'anthony_anderson@civicrm.org',
129 'on_hold' => 0,
130 'im_id' => '',
131 'provider_id' => '',
132 'im' => '',
133 'worldregion_id' => '',
134 'world_region' => '',
135 'individual_prefix' => 'Mr.',
136 'individual_suffix' => 'II',
137 'communication_style' => '',
138 'gender' => '',
139 'state_province_name' => '',
140 'state_province' => '',
141 'country' => '',
142 'id' => '1',
6a488035 143 ),
50fb255d 144 ),
6a488035 145 ),
50fb255d 146 ),
6a488035 147 ),
50fb255d 148 );
6a488035 149
fb32de45 150 return $expectedResult;
6a488035
TO
151}
152
50fb255d 153/**
154* This example has been generated from the API test suite.
155* The test that created it is called
156* testActivityGetGoodID1
157* and can be found in
69d79249 158* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php
6a488035
TO
159*
160* You can see the outcome of the API tests at
69d79249 161* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
162*
163* To Learn about the API read
69d79249 164* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 165*
69d79249 166* Browse the api on your own site with the api explorer
41d4d31f 167* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
168*
169* Read more about testing here
170* http://wiki.civicrm.org/confluence/display/CRM/Testing
171*
172* API Standards documentation:
173* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 174*/