Merge pull request #22968 from civicrm/5.48
[civicrm-core.git] / api / v3 / OptionGroup.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 * This api exposes CiviCRM option groups.
14 *
15 * OptionGroups are containers for option values.
16 *
17 * @package CiviCRM_APIv3
18 */
19
20 /**
21 * Get option groups.
22 *
23 * @param array $params
24 *
25 * @return array
26 */
27 function civicrm_api3_option_group_get($params) {
28 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
29 }
30
31 /**
32 * Create/update option group.
33 *
34 * @param array $params
35 * Array per getfields metadata.
36 *
37 * @return array
38 */
39 function civicrm_api3_option_group_create($params) {
40 // Use deprecated BAO method in APIv3 for legacy support. APIv4 uses new writeRecords method.
41 $bao = CRM_Core_BAO_OptionGroup::add($params);
42 civicrm_api('option_value', 'getfields', ['version' => 3, 'cache_clear' => 1]);
43 $values = [];
44 _civicrm_api3_object_to_array($bao, $values[$bao->id]);
45 return civicrm_api3_create_success($values, $params, 'OptionGroup', 'create', $bao);
46 }
47
48 /**
49 * Adjust Metadata for Create action.
50 *
51 * The metadata is used for setting defaults, documentation & validation.
52 *
53 * @param array $params
54 * Array of parameters determined by getfields.
55 */
56 function _civicrm_api3_option_group_create_spec(&$params) {
57 $params['name']['api.unique'] = 1;
58 $params['is_active']['api.default'] = TRUE;
59 }
60
61 /**
62 * Delete an existing Option Group.
63 *
64 * This method is used to delete any existing OptionGroup given its id.
65 *
66 * @param array $params
67 * [id]
68 *
69 * @return array
70 * API Result Array
71 */
72 function civicrm_api3_option_group_delete($params) {
73 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
74 }