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