Merge pull request #23549 from JMAConsulting/issue_39
[civicrm-core.git] / api / v3 / OptionGroup.php
CommitLineData
6a488035 1<?php
c28e1768
CW
2/*
3 +--------------------------------------------------------------------+
a30c801b 4 | Copyright CiviCRM LLC. All rights reserved. |
c28e1768 5 | |
a30c801b
TO
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 |
c28e1768
CW
9 +--------------------------------------------------------------------+
10 */
11
12/**
13 * This api exposes CiviCRM option groups.
244bbdd8
CW
14 *
15 * OptionGroups are containers for option values.
c28e1768
CW
16 *
17 * @package CiviCRM_APIv3
c28e1768 18 */
6a488035 19
aa1b1481 20/**
61fe4988
EM
21 * Get option groups.
22 *
c490a46a 23 * @param array $params
aa1b1481
EM
24 *
25 * @return array
26 */
6a488035 27function civicrm_api3_option_group_get($params) {
6a488035
TO
28 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
29}
30
31/**
9d32e6f7 32 * Create/update option group.
6a488035 33 *
cf470720 34 * @param array $params
9d32e6f7 35 * Array per getfields metadata.
6a488035 36 *
a6c01b45 37 * @return array
6a488035
TO
38 */
39function civicrm_api3_option_group_create($params) {
ddba05d3
CW
40 // Use deprecated BAO method in APIv3 for legacy support. APIv4 uses new writeRecords method.
41 $bao = CRM_Core_BAO_OptionGroup::add($params);
cf8f0fff 42 civicrm_api('option_value', 'getfields', ['version' => 3, 'cache_clear' => 1]);
ddba05d3
CW
43 $values = [];
44 _civicrm_api3_object_to_array($bao, $values[$bao->id]);
45 return civicrm_api3_create_success($values, $params, 'OptionGroup', 'create', $bao);
6a488035
TO
46}
47
11e09c59 48/**
211e2fca
EM
49 * Adjust Metadata for Create action.
50 *
51 * The metadata is used for setting defaults, documentation & validation.
1c88e578 52 *
cf470720 53 * @param array $params
b081365f 54 * Array of parameters determined by getfields.
6a488035
TO
55 */
56function _civicrm_api3_option_group_create_spec(&$params) {
57 $params['name']['api.unique'] = 1;
801bafd7 58 $params['is_active']['api.default'] = TRUE;
6a488035 59}
4033343a 60
61/**
211e2fca 62 * Delete an existing Option Group.
4033343a 63 *
244bbdd8 64 * This method is used to delete any existing OptionGroup given its id.
4033343a 65 *
cf470720 66 * @param array $params
c28e1768 67 * [id]
4033343a 68 *
a6c01b45 69 * @return array
72b3a70c 70 * API Result Array
4033343a 71 */
72function civicrm_api3_option_group_delete($params) {
73 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
74}