Consolidate handling of greeting label
[civicrm-core.git] / api / v3 / examples / Activity / GetTargetandAssignee.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Activity.create API.
50fb255d 4 *
5c49fee0 5 * Demonstrates setting & retrieving activity target & source.
50fb255d 6 *
7 * @return array
8 * API result array
9 */
a828d7b8 10function activity_create_example() {
cf8f0fff 11 $params = [
50fb255d 12 'source_contact_id' => 1,
13 'subject' => 'Make-it-Happen Meeting',
14 'activity_date_time' => '20110316',
15 'duration' => 120,
e3aa0dd1 16 'location' => 'Pennsylvania',
50fb255d 17 'details' => 'a test activity',
18 'status_id' => 1,
19 'activity_type_id' => 1,
20 'priority_id' => 1,
21 'target_contact_id' => 1,
22 'assignee_contact_id' => 1,
cf8f0fff 23 ];
6a488035 24
50fb255d 25 try{
a828d7b8 26 $result = civicrm_api3('Activity', 'create', $params);
50fb255d 27 }
28 catch (CiviCRM_API3_Exception $e) {
29 // Handle error here.
30 $errorMessage = $e->getMessage();
31 $errorCode = $e->getErrorCode();
32 $errorData = $e->getExtraParams();
cf8f0fff 33 return [
5be22f39 34 'is_error' => 1,
35 'error_message' => $errorMessage,
50fb255d 36 'error_code' => $errorCode,
37 'error_data' => $errorData,
cf8f0fff 38 ];
50fb255d 39 }
40
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 */
a828d7b8 50function activity_create_expectedresult() {
6a488035 51
cf8f0fff 52 $expectedResult = [
50fb255d 53 'is_error' => 0,
54 'version' => 3,
55 'count' => 1,
56 'id' => 1,
cf8f0fff
CW
57 'values' => [
58 '1' => [
50fb255d 59 'id' => '1',
60 'source_record_id' => '',
61 'activity_type_id' => '1',
62 'subject' => 'Make-it-Happen Meeting',
63 'activity_date_time' => '20110316000000',
64 'duration' => '120',
e3aa0dd1 65 'location' => 'Pennsylvania',
50fb255d 66 'phone_id' => '',
67 'phone_number' => '',
68 'details' => 'a test activity',
69 'status_id' => '1',
70 'priority_id' => '1',
71 'parent_id' => '',
72 'is_test' => '',
73 'medium_id' => '',
74 'is_auto' => '',
75 'relationship_id' => '',
76 'is_current_revision' => '',
77 'original_id' => '',
78 'result' => '',
79 'is_deleted' => '',
80 'campaign_id' => '',
81 'engagement_level' => '',
82 'weight' => '',
5be22f39 83 'is_star' => '',
cf8f0fff
CW
84 ],
85 ],
86 ];
6a488035 87
fb32de45 88 return $expectedResult;
6a488035
TO
89}
90
a828d7b8 91/*
50fb255d 92* This example has been generated from the API test suite.
a828d7b8
CW
93* The test that created it is called "testActivityReturnTargetAssignee"
94* and can be found at:
69d79249 95* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php
6a488035
TO
96*
97* You can see the outcome of the API tests at
69d79249 98* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
99*
100* To Learn about the API read
69d79249 101* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 102*
69d79249 103* Browse the api on your own site with the api explorer
41d4d31f 104* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
105*
106* Read more about testing here
107* http://wiki.civicrm.org/confluence/display/CRM/Testing
108*
109* API Standards documentation:
110* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 111*/