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