| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example demonstrating the Activity.getfields API. |
| 4 | * |
| 5 | * @return array |
| 6 | * API result array |
| 7 | */ |
| 8 | function activity_getfields_example() { |
| 9 | $params = array( |
| 10 | 'action' => 'create', |
| 11 | ); |
| 12 | |
| 13 | try{ |
| 14 | $result = civicrm_api3('Activity', 'getfields', $params); |
| 15 | } |
| 16 | catch (CiviCRM_API3_Exception $e) { |
| 17 | // Handle error here. |
| 18 | $errorMessage = $e->getMessage(); |
| 19 | $errorCode = $e->getErrorCode(); |
| 20 | $errorData = $e->getExtraParams(); |
| 21 | return array( |
| 22 | 'error' => $errorMessage, |
| 23 | 'error_code' => $errorCode, |
| 24 | 'error_data' => $errorData, |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | return $result; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Function returns array of result expected from previous function. |
| 33 | * |
| 34 | * @return array |
| 35 | * API result array |
| 36 | */ |
| 37 | function activity_getfields_expectedresult() { |
| 38 | |
| 39 | $expectedResult = array( |
| 40 | 'is_error' => 0, |
| 41 | 'version' => 3, |
| 42 | 'count' => 27, |
| 43 | 'values' => array( |
| 44 | 'source_record_id' => array( |
| 45 | 'name' => 'source_record_id', |
| 46 | 'type' => 1, |
| 47 | 'title' => 'Source Record', |
| 48 | ), |
| 49 | 'activity_type_id' => array( |
| 50 | 'name' => 'activity_type_id', |
| 51 | 'type' => 1, |
| 52 | 'title' => 'Activity Type ID', |
| 53 | 'required' => TRUE, |
| 54 | 'import' => TRUE, |
| 55 | 'where' => 'civicrm_activity.activity_type_id', |
| 56 | 'headerPattern' => '/(activity.)?type(.id$)/i', |
| 57 | 'export' => TRUE, |
| 58 | 'default' => '1', |
| 59 | 'html' => array( |
| 60 | 'type' => 'Select', |
| 61 | ), |
| 62 | 'pseudoconstant' => array( |
| 63 | 'optionGroupName' => 'activity_type', |
| 64 | ), |
| 65 | ), |
| 66 | 'activity_date_time' => array( |
| 67 | 'name' => 'activity_date_time', |
| 68 | 'type' => 12, |
| 69 | 'title' => 'Activity Date', |
| 70 | 'import' => TRUE, |
| 71 | 'where' => 'civicrm_activity.activity_date_time', |
| 72 | 'headerPattern' => '/(activity.)?date(.time$)?/i', |
| 73 | 'export' => TRUE, |
| 74 | 'html' => array( |
| 75 | 'type' => 'Select Date', |
| 76 | ), |
| 77 | ), |
| 78 | 'phone_id' => array( |
| 79 | 'name' => 'phone_id', |
| 80 | 'type' => 1, |
| 81 | 'title' => 'Phone (called) ID', |
| 82 | 'FKClassName' => 'CRM_Core_DAO_Phone', |
| 83 | 'html' => array( |
| 84 | 'type' => 'Autocomplete-Select', |
| 85 | ), |
| 86 | 'FKApiName' => 'Phone', |
| 87 | ), |
| 88 | 'phone_number' => array( |
| 89 | 'name' => 'phone_number', |
| 90 | 'type' => 2, |
| 91 | 'title' => 'Phone (called) Number', |
| 92 | 'maxlength' => 64, |
| 93 | 'size' => 30, |
| 94 | 'html' => array( |
| 95 | 'type' => 'Text', |
| 96 | ), |
| 97 | ), |
| 98 | 'priority_id' => array( |
| 99 | 'name' => 'priority_id', |
| 100 | 'type' => 1, |
| 101 | 'title' => 'Priority', |
| 102 | 'html' => array( |
| 103 | 'type' => 'Select', |
| 104 | ), |
| 105 | 'pseudoconstant' => array( |
| 106 | 'optionGroupName' => 'priority', |
| 107 | ), |
| 108 | ), |
| 109 | 'parent_id' => array( |
| 110 | 'name' => 'parent_id', |
| 111 | 'type' => 1, |
| 112 | 'title' => 'Parent Activity Id', |
| 113 | 'FKClassName' => 'CRM_Activity_DAO_Activity', |
| 114 | 'FKApiName' => 'Activity', |
| 115 | ), |
| 116 | 'is_auto' => array( |
| 117 | 'name' => 'is_auto', |
| 118 | 'type' => 16, |
| 119 | 'title' => 'Auto', |
| 120 | ), |
| 121 | 'relationship_id' => array( |
| 122 | 'name' => 'relationship_id', |
| 123 | 'type' => 1, |
| 124 | 'title' => 'Relationship Id', |
| 125 | 'default' => 'NULL', |
| 126 | 'FKClassName' => 'CRM_Contact_DAO_Relationship', |
| 127 | 'FKApiName' => 'Relationship', |
| 128 | ), |
| 129 | 'is_current_revision' => array( |
| 130 | 'name' => 'is_current_revision', |
| 131 | 'type' => 16, |
| 132 | 'title' => 'Is this activity a current revision in versioning chain?', |
| 133 | 'import' => TRUE, |
| 134 | 'where' => 'civicrm_activity.is_current_revision', |
| 135 | 'headerPattern' => '/(is.)?(current.)?(revision|version(ing)?)/i', |
| 136 | 'export' => TRUE, |
| 137 | 'default' => '1', |
| 138 | 'html' => array( |
| 139 | 'type' => 'CheckBox', |
| 140 | ), |
| 141 | ), |
| 142 | 'original_id' => array( |
| 143 | 'name' => 'original_id', |
| 144 | 'type' => 1, |
| 145 | 'title' => 'Original Activity ID ', |
| 146 | 'FKClassName' => 'CRM_Activity_DAO_Activity', |
| 147 | 'FKApiName' => 'Activity', |
| 148 | ), |
| 149 | 'weight' => array( |
| 150 | 'name' => 'weight', |
| 151 | 'type' => 1, |
| 152 | 'title' => 'Order', |
| 153 | 'html' => array( |
| 154 | 'type' => 'Text', |
| 155 | ), |
| 156 | ), |
| 157 | 'id' => array( |
| 158 | 'name' => 'id', |
| 159 | 'type' => 1, |
| 160 | 'title' => 'Activity ID', |
| 161 | 'required' => TRUE, |
| 162 | 'import' => TRUE, |
| 163 | 'where' => 'civicrm_activity.id', |
| 164 | 'export' => TRUE, |
| 165 | 'uniqueName' => 'activity_id', |
| 166 | 'api.aliases' => array( |
| 167 | '0' => 'activity_id', |
| 168 | ), |
| 169 | ), |
| 170 | 'subject' => array( |
| 171 | 'name' => 'subject', |
| 172 | 'type' => 2, |
| 173 | 'title' => 'Subject', |
| 174 | 'maxlength' => 255, |
| 175 | 'size' => 45, |
| 176 | 'import' => TRUE, |
| 177 | 'where' => 'civicrm_activity.subject', |
| 178 | 'headerPattern' => '/(activity.)?subject/i', |
| 179 | 'export' => TRUE, |
| 180 | 'html' => array( |
| 181 | 'type' => 'Text', |
| 182 | ), |
| 183 | 'uniqueName' => 'activity_subject', |
| 184 | ), |
| 185 | 'duration' => array( |
| 186 | 'name' => 'duration', |
| 187 | 'type' => 1, |
| 188 | 'title' => 'Duration', |
| 189 | 'import' => TRUE, |
| 190 | 'where' => 'civicrm_activity.duration', |
| 191 | 'headerPattern' => '/(activity.)?duration(s)?$/i', |
| 192 | 'export' => TRUE, |
| 193 | 'html' => array( |
| 194 | 'type' => 'Text', |
| 195 | ), |
| 196 | 'uniqueName' => 'activity_duration', |
| 197 | ), |
| 198 | 'location' => array( |
| 199 | 'name' => 'location', |
| 200 | 'type' => 2, |
| 201 | 'title' => 'Location', |
| 202 | 'maxlength' => 255, |
| 203 | 'size' => 45, |
| 204 | 'import' => TRUE, |
| 205 | 'where' => 'civicrm_activity.location', |
| 206 | 'headerPattern' => '/(activity.)?location$/i', |
| 207 | 'export' => TRUE, |
| 208 | 'html' => array( |
| 209 | 'type' => 'Text', |
| 210 | ), |
| 211 | 'uniqueName' => 'activity_location', |
| 212 | ), |
| 213 | 'details' => array( |
| 214 | 'name' => 'details', |
| 215 | 'type' => 32, |
| 216 | 'title' => 'Details', |
| 217 | 'rows' => 8, |
| 218 | 'cols' => 60, |
| 219 | 'import' => TRUE, |
| 220 | 'where' => 'civicrm_activity.details', |
| 221 | 'headerPattern' => '/(activity.)?detail(s)?$/i', |
| 222 | 'export' => TRUE, |
| 223 | 'html' => array( |
| 224 | 'type' => 'RichTextEditor', |
| 225 | ), |
| 226 | 'uniqueName' => 'activity_details', |
| 227 | ), |
| 228 | 'status_id' => array( |
| 229 | 'name' => 'status_id', |
| 230 | 'type' => 1, |
| 231 | 'title' => 'Activity Status', |
| 232 | 'import' => TRUE, |
| 233 | 'where' => 'civicrm_activity.status_id', |
| 234 | 'headerPattern' => '/(activity.)?status(.label$)?/i', |
| 235 | 'html' => array( |
| 236 | 'type' => 'Select', |
| 237 | ), |
| 238 | 'pseudoconstant' => array( |
| 239 | 'optionGroupName' => 'activity_status', |
| 240 | ), |
| 241 | 'uniqueName' => 'activity_status_id', |
| 242 | 'api.aliases' => array( |
| 243 | '0' => 'activity_status', |
| 244 | ), |
| 245 | ), |
| 246 | 'is_test' => array( |
| 247 | 'name' => 'is_test', |
| 248 | 'type' => 16, |
| 249 | 'title' => 'Test', |
| 250 | 'import' => TRUE, |
| 251 | 'where' => 'civicrm_activity.is_test', |
| 252 | 'headerPattern' => '/(is.)?test(.activity)?/i', |
| 253 | 'export' => TRUE, |
| 254 | 'html' => array( |
| 255 | 'type' => 'Select', |
| 256 | ), |
| 257 | 'uniqueName' => 'activity_is_test', |
| 258 | ), |
| 259 | 'medium_id' => array( |
| 260 | 'name' => 'medium_id', |
| 261 | 'type' => 1, |
| 262 | 'title' => 'Activity Medium', |
| 263 | 'default' => 'NULL', |
| 264 | 'html' => array( |
| 265 | 'type' => 'Select', |
| 266 | ), |
| 267 | 'pseudoconstant' => array( |
| 268 | 'optionGroupName' => 'encounter_medium', |
| 269 | ), |
| 270 | 'uniqueName' => 'activity_medium_id', |
| 271 | ), |
| 272 | 'result' => array( |
| 273 | 'name' => 'result', |
| 274 | 'type' => 2, |
| 275 | 'title' => 'Result', |
| 276 | 'maxlength' => 255, |
| 277 | 'size' => 45, |
| 278 | 'html' => array( |
| 279 | 'type' => 'Text', |
| 280 | ), |
| 281 | 'uniqueName' => 'activity_result', |
| 282 | ), |
| 283 | 'is_deleted' => array( |
| 284 | 'name' => 'is_deleted', |
| 285 | 'type' => 16, |
| 286 | 'title' => 'Activity is in the Trash', |
| 287 | 'import' => TRUE, |
| 288 | 'where' => 'civicrm_activity.is_deleted', |
| 289 | 'headerPattern' => '/(activity.)?(trash|deleted)/i', |
| 290 | 'export' => TRUE, |
| 291 | 'html' => array( |
| 292 | 'type' => 'Text', |
| 293 | ), |
| 294 | 'uniqueName' => 'activity_is_deleted', |
| 295 | ), |
| 296 | 'campaign_id' => array( |
| 297 | 'name' => 'campaign_id', |
| 298 | 'type' => 1, |
| 299 | 'title' => 'Campaign', |
| 300 | 'import' => TRUE, |
| 301 | 'where' => 'civicrm_activity.campaign_id', |
| 302 | 'export' => TRUE, |
| 303 | 'FKClassName' => 'CRM_Campaign_DAO_Campaign', |
| 304 | 'html' => array( |
| 305 | 'type' => 'CheckBox', |
| 306 | ), |
| 307 | 'pseudoconstant' => array( |
| 308 | 'table' => 'civicrm_campaign', |
| 309 | 'keyColumn' => 'id', |
| 310 | 'labelColumn' => 'title', |
| 311 | ), |
| 312 | 'uniqueName' => 'activity_campaign_id', |
| 313 | 'FKApiName' => 'Campaign', |
| 314 | ), |
| 315 | 'engagement_level' => array( |
| 316 | 'name' => 'engagement_level', |
| 317 | 'type' => 1, |
| 318 | 'title' => 'Engagement Index', |
| 319 | 'import' => TRUE, |
| 320 | 'where' => 'civicrm_activity.engagement_level', |
| 321 | 'export' => TRUE, |
| 322 | 'html' => array( |
| 323 | 'type' => 'Select', |
| 324 | ), |
| 325 | 'pseudoconstant' => array( |
| 326 | 'optionGroupName' => 'engagement_index', |
| 327 | ), |
| 328 | 'uniqueName' => 'activity_engagement_level', |
| 329 | ), |
| 330 | 'source_contact_id' => array( |
| 331 | 'name' => 'source_contact_id', |
| 332 | 'title' => 'Activity Source Contact', |
| 333 | 'type' => 1, |
| 334 | 'FKClassName' => 'CRM_Activity_DAO_ActivityContact', |
| 335 | 'api.default' => 'user_contact_id', |
| 336 | ), |
| 337 | 'assignee_contact_id' => array( |
| 338 | 'name' => 'assignee_id', |
| 339 | 'title' => 'assigned to', |
| 340 | 'type' => 1, |
| 341 | 'FKClassName' => 'CRM_Activity_DAO_ActivityContact', |
| 342 | ), |
| 343 | 'target_contact_id' => array( |
| 344 | 'name' => 'target_id', |
| 345 | 'title' => 'Activity Target', |
| 346 | 'type' => 1, |
| 347 | 'FKClassName' => 'CRM_Activity_DAO_ActivityContact', |
| 348 | ), |
| 349 | ), |
| 350 | ); |
| 351 | |
| 352 | return $expectedResult; |
| 353 | } |
| 354 | |
| 355 | /* |
| 356 | * This example has been generated from the API test suite. |
| 357 | * The test that created it is called "testGetFields" |
| 358 | * and can be found at: |
| 359 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php |
| 360 | * |
| 361 | * You can see the outcome of the API tests at |
| 362 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
| 363 | * |
| 364 | * To Learn about the API read |
| 365 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
| 366 | * |
| 367 | * Browse the api on your own site with the api explorer |
| 368 | * http://MYSITE.ORG/path/to/civicrm/api |
| 369 | * |
| 370 | * Read more about testing here |
| 371 | * http://wiki.civicrm.org/confluence/display/CRM/Testing |
| 372 | * |
| 373 | * API Standards documentation: |
| 374 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards |
| 375 | */ |