Merge pull request #15085 from seamuslee001/update_examples
[civicrm-core.git] / api / v3 / examples / ActivityType / Create.php
1 <?php
2 /**
3 * Test Generated example demonstrating the ActivityType.create API.
4 *
5 * @deprecated
6 * The ActivityType api is deprecated. Please use the OptionValue api instead.
7 *
8 * @return array
9 * API result array
10 */
11 function activity_type_create_example() {
12 $params = [
13 'weight' => '2',
14 'label' => 'send out letters',
15 'filter' => 0,
16 'is_active' => 1,
17 'is_optgroup' => 1,
18 'is_default' => 0,
19 ];
20
21 try{
22 $result = civicrm_api3('ActivityType', 'create', $params);
23 }
24 catch (CiviCRM_API3_Exception $e) {
25 // Handle error here.
26 $errorMessage = $e->getMessage();
27 $errorCode = $e->getErrorCode();
28 $errorData = $e->getExtraParams();
29 return [
30 'is_error' => 1,
31 'error_message' => $errorMessage,
32 'error_code' => $errorCode,
33 'error_data' => $errorData,
34 ];
35 }
36
37 return $result;
38 }
39
40 /**
41 * Function returns array of result expected from previous function.
42 *
43 * @return array
44 * API result array
45 */
46 function activity_type_create_expectedresult() {
47
48 $expectedResult = [
49 'is_error' => 0,
50 'version' => 3,
51 'count' => 1,
52 'id' => 869,
53 'values' => [
54 '869' => [
55 'id' => '869',
56 'option_group_id' => '2',
57 'label' => 'send out letters',
58 'value' => '55',
59 'name' => 'send out letters',
60 'grouping' => '',
61 'filter' => 0,
62 'is_default' => 0,
63 'weight' => '2',
64 'description' => '',
65 'is_optgroup' => '1',
66 'is_reserved' => '',
67 'is_active' => '1',
68 'component_id' => '',
69 'domain_id' => '',
70 'visibility_id' => '',
71 'icon' => '',
72 'color' => '',
73 ],
74 ],
75 'deprecated' => 'The ActivityType api is deprecated. Please use the OptionValue api instead.',
76 ];
77
78 return $expectedResult;
79 }
80
81 /*
82 * This example has been generated from the API test suite.
83 * The test that created it is called "testActivityTypeCreate"
84 * and can be found at:
85 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTypeTest.php
86 *
87 * You can see the outcome of the API tests at
88 * https://test.civicrm.org/job/CiviCRM-Core-Matrix/
89 *
90 * To Learn about the API read
91 * https://docs.civicrm.org/dev/en/latest/api/
92 *
93 * Browse the API on your own site with the API Explorer. It is in the main
94 * CiviCRM menu, under: Support > Development > API Explorer.
95 *
96 * Read more about testing here
97 * https://docs.civicrm.org/dev/en/latest/testing/
98 *
99 * API Standards documentation:
100 * https://docs.civicrm.org/dev/en/latest/framework/api-architecture/
101 */