3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * This api exposes CiviCRM option values.
31 * Values are grouped by "OptionGroup"
33 * @package CiviCRM_APIv3
37 * Retrieve one or more option values.
39 * @param array $params
44 function civicrm_api3_option_value_get($params) {
46 if (empty($params['option_group_id']) && !empty($params['option_group_name'])) {
47 $opt = array('version' => 3, 'name' => $params['option_group_name']);
48 $optionGroup = civicrm_api('OptionGroup', 'Get', $opt);
49 if (empty($optionGroup['id'])) {
50 return civicrm_api3_create_error("option group name does not correlate to a single option group");
52 $params['option_group_id'] = $optionGroup['id'];
55 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
61 * @param array $params
63 * @throws API_Exception
67 function civicrm_api3_option_value_create($params) {
68 $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
69 if (!empty($params['id']) && !array_key_exists('option_group_id', $params)) {
70 $groupId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue',
71 $params['id'], 'option_group_id', 'id'
75 $groupId = $params['option_group_id'];
78 civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $groupId));
83 * Adjust Metadata for Create action.
85 * The metadata is used for setting defaults, documentation & validation.
87 * @param array $params
88 * Array of parameters determined by getfields.
90 function _civicrm_api3_option_value_create_spec(&$params) {
91 $params['is_active']['api.default'] = 1;
92 //continue to support component
93 $params['component_id']['api.aliases'] = array('component');
94 // $params['name']['api.aliases'] = array('label');
95 $params['option_group_id']['api.required'] = TRUE;
99 * Deletes an existing option value.
101 * @param array $params
106 function civicrm_api3_option_value_delete($params) {
107 // We will get the option group id before deleting so we can flush pseudoconstants.
108 $optionGroupID = civicrm_api('option_value', 'getvalue', array('version' => 3, 'id' => $params['id'], 'return' => 'option_group_id'));
109 if (CRM_Core_BAO_OptionValue
::del((int) $params['id'])) {
110 civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $optionGroupID));
111 return civicrm_api3_create_success();
114 civicrm_api3_create_error('Could not delete OptionValue ' . $params['id']);