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