Merge pull request #16392 from jaapjansma/dev_1522_tests
[civicrm-core.git] / api / v3 / ActivityType.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * The ActivityType api is deprecated. Please use the OptionValue api instead.
14 *
15 * @deprecated
16 *
17 * @package CiviCRM_APIv3
18 */
19
20 /**
21 * Notification of deprecated function.
22 *
23 * @deprecated api notice
24 * @return string
25 * to indicate this entire api entity is deprecated
26 */
27 function _civicrm_api3_activity_type_deprecation() {
28 return 'The ActivityType api is deprecated. Please use the OptionValue api instead.';
29 }
30
31 /**
32 * Retrieve activity types.
33 *
34 * @param array $params
35 *
36 * @return array
37 * activity types keyed by id
38 * @deprecated - use the getoptions action instead
39 */
40 function civicrm_api3_activity_type_get($params) {
41
42 $activityTypes = CRM_Core_OptionGroup::values('activity_type');
43 return civicrm_api3_create_success($activityTypes, $params, 'activity_type', 'get');
44 }
45
46 /**
47 * Create activity type.
48 *
49 * @param array $params
50 *
51 * @return array
52 * created / updated activity type
53 *
54 * @deprecated use the OptionValue api instead
55 */
56 function civicrm_api3_activity_type_create($params) {
57
58 $action = 1;
59
60 if ($optionValueID = CRM_Utils_Array::value('option_value_id', $params)) {
61 $action = 2;
62 }
63
64 $activityObject = CRM_Core_OptionValue::addOptionValue($params, 'activity_type', $action, $optionValueID);
65 $activityType = [];
66 _civicrm_api3_object_to_array($activityObject, $activityType[$activityObject->id]);
67 return civicrm_api3_create_success($activityType, $params, 'activity_type', 'create');
68 }
69
70 /**
71 * Adjust Metadata for Create action.
72 *
73 * The metadata is used for setting defaults, documentation & validation.
74 *
75 * @param array $params
76 * Array of parameters determined by getfields.
77 */
78 function _civicrm_api3_activity_type_create_spec(&$params) {
79 $params['label'] = [
80 'api.required' => 1,
81 'title' => 'Label',
82 'type' => CRM_Utils_Type::T_STRING,
83 ];
84 $params['weight'] = [
85 'api.required' => 1,
86 'title' => 'Weight',
87 'type' => CRM_Utils_Type::T_STRING,
88 ];
89 }
90
91 /**
92 * Delete ActivityType.
93 *
94 * @param array $params
95 * Array including id of activity_type to delete.
96 * @return array API result array
97 * @throws API_Exception
98 * @deprecated use OptionValue api
99 */
100 function civicrm_api3_activity_type_delete($params) {
101 $result = CRM_Core_BAO_OptionValue::del($params['id']);
102 if ($result) {
103 return civicrm_api3_create_success(TRUE, $params);
104 }
105 throw new API_Exception("Failure to delete activity type id {$params['id']}");
106 }