Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
c28e1768 CW |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
c28e1768 | 5 | +--------------------------------------------------------------------+ |
1f4ea726 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
c28e1768 CW |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * This api exposes CiviCRM option values. | |
244bbdd8 | 30 | * |
c28e1768 CW |
31 | * Values are grouped by "OptionGroup" |
32 | * | |
33 | * @package CiviCRM_APIv3 | |
c28e1768 | 34 | */ |
6a488035 TO |
35 | |
36 | /** | |
9d32e6f7 | 37 | * Retrieve one or more option values. |
6a488035 | 38 | * |
c490a46a | 39 | * @param array $params |
6a488035 | 40 | * |
a6c01b45 | 41 | * @return array |
00f8641b | 42 | * API result array |
6a488035 TO |
43 | */ |
44 | function civicrm_api3_option_value_get($params) { | |
6a488035 TO |
45 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
46 | } | |
47 | ||
eea0a60f CW |
48 | /** |
49 | * Adjust Metadata for get 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_value_get_spec(&$params) { | |
57 | $params['option_group_id']['api.aliases'] = array('option_group_name'); | |
58 | } | |
59 | ||
6a488035 | 60 | /** |
9d32e6f7 | 61 | * Add an OptionValue. |
6a488035 | 62 | * |
c490a46a | 63 | * @param array $params |
1fd111c8 EM |
64 | * |
65 | * @throws API_Exception | |
a6c01b45 | 66 | * @return array |
00f8641b | 67 | * API result array |
6a488035 TO |
68 | */ |
69 | function civicrm_api3_option_value_create($params) { | |
c87bbced | 70 | $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
89ab5601 PJ |
71 | if (!empty($params['id']) && !array_key_exists('option_group_id', $params)) { |
72 | $groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', | |
73 | $params['id'], 'option_group_id', 'id' | |
74 | ); | |
75 | } | |
76 | else { | |
77 | $groupId = $params['option_group_id']; | |
78 | } | |
79 | ||
80 | civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $groupId)); | |
c87bbced | 81 | return $result; |
6a488035 TO |
82 | } |
83 | ||
11e09c59 | 84 | /** |
0aa0303c EM |
85 | * Adjust Metadata for Create action. |
86 | * | |
87 | * The metadata is used for setting defaults, documentation & validation. | |
6a488035 | 88 | * |
cf470720 | 89 | * @param array $params |
b081365f | 90 | * Array of parameters determined by getfields. |
6a488035 TO |
91 | */ |
92 | function _civicrm_api3_option_value_create_spec(&$params) { | |
93 | $params['is_active']['api.default'] = 1; | |
c87bbced | 94 | //continue to support component |
95 | $params['component_id']['api.aliases'] = array('component'); | |
ad0121ed | 96 | // $params['name']['api.aliases'] = array('label'); |
c87bbced | 97 | $params['option_group_id']['api.required'] = TRUE; |
6a488035 TO |
98 | } |
99 | ||
100 | /** | |
9d32e6f7 | 101 | * Deletes an existing option value. |
6a488035 | 102 | * |
cf470720 | 103 | * @param array $params |
8089541a | 104 | * @return array API result array |
8089541a | 105 | * @throws API_Exception |
6a488035 TO |
106 | */ |
107 | function civicrm_api3_option_value_delete($params) { | |
9d32e6f7 | 108 | // We will get the option group id before deleting so we can flush pseudoconstants. |
6a488035 | 109 | $optionGroupID = civicrm_api('option_value', 'getvalue', array('version' => 3, 'id' => $params['id'], 'return' => 'option_group_id')); |
a60c0bc8 SL |
110 | $result = CRM_Core_BAO_OptionValue::del($params['id']); |
111 | if ($result) { | |
6a488035 TO |
112 | civicrm_api('option_value', 'getfields', array('version' => 3, 'cache_clear' => 1, 'option_group_id' => $optionGroupID)); |
113 | return civicrm_api3_create_success(); | |
114 | } | |
92e4c2a5 | 115 | else { |
a60c0bc8 | 116 | throw new API_Exception('Could not delete OptionValue ' . $params['id']); |
6a488035 TO |
117 | } |
118 | } |