Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
a30c801b | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | ||
13 | /** | |
244bbdd8 CW |
14 | * This api exposes CiviCRM price field values. |
15 | * | |
16 | * PriceFields may contain zero or more PriceFieldValues. | |
17 | * Use chaining to create PriceFields and values in one api call. | |
6a488035 TO |
18 | * |
19 | * @package CiviCRM_APIv3 | |
6a488035 TO |
20 | */ |
21 | ||
22 | /** | |
244bbdd8 | 23 | * Create or update a PriceFieldValue. |
6a488035 | 24 | * |
cf470720 | 25 | * @param array $params |
244bbdd8 | 26 | * name/value pairs to insert in new 'PriceFieldValue' |
6a488035 | 27 | * |
a6c01b45 | 28 | * @return array |
1747ab99 | 29 | * API result array. |
6a488035 TO |
30 | */ |
31 | function civicrm_api3_price_field_value_create($params) { | |
cf8f0fff | 32 | $ids = []; |
9b873358 | 33 | if (!empty($params['id'])) { |
6a488035 TO |
34 | $ids['id'] = $params['id']; |
35 | } | |
36 | ||
9da8dc8c | 37 | $bao = CRM_Price_BAO_PriceFieldValue::create($params, $ids); |
6a488035 | 38 | |
cf8f0fff | 39 | $values = []; |
6a488035 | 40 | _civicrm_api3_object_to_array($bao, $values[$bao->id]); |
244bbdd8 | 41 | return civicrm_api3_create_success($values, $params, 'PriceFieldValue', 'create', $bao); |
6a488035 | 42 | |
11e09c59 TO |
43 | } |
44 | ||
45 | /** | |
0aa0303c EM |
46 | * Adjust Metadata for Create action. |
47 | * | |
48 | * The metadata is used for setting defaults, documentation & validation. | |
6a488035 | 49 | * |
cf470720 | 50 | * @param array $params |
b081365f | 51 | * Array of parameters determined by getfields. |
6a488035 TO |
52 | */ |
53 | function _civicrm_api3_price_field_value_create_spec(&$params) { | |
418e884f | 54 | $params['price_field_id']['api.required'] = TRUE; |
e825f029 | 55 | $params['label']['api.required'] = TRUE; |
aa52367c EM |
56 | $params['amount']['api.required'] = TRUE; |
57 | $params['is_active']['api.default'] = TRUE; | |
15a25cec | 58 | $params['financial_type_id']['api.default'] = TRUE; |
6a488035 TO |
59 | } |
60 | ||
61 | /** | |
244bbdd8 | 62 | * Returns array of PriceFieldValues matching a set of one or more group properties. |
6a488035 | 63 | * |
cf470720 TO |
64 | * @param array $params |
65 | * Array of one or more valid property_name=>value pairs. If $params is set. | |
16b10e64 | 66 | * as null, all price_field_values will be returned (default limit is 25) |
6a488035 | 67 | * |
a6c01b45 | 68 | * @return array |
1747ab99 | 69 | * API result array. |
6a488035 TO |
70 | */ |
71 | function civicrm_api3_price_field_value_get($params) { | |
72 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
73 | } | |
74 | ||
75 | /** | |
244bbdd8 | 76 | * Delete an existing PriceFieldValue. |
6a488035 | 77 | * |
244bbdd8 | 78 | * This method is used to delete any existing PriceFieldValue given its id. |
6a488035 | 79 | * |
cf470720 | 80 | * @param array $params |
b081365f | 81 | * Array containing id of the group to be deleted. |
6a488035 | 82 | * |
a6c01b45 | 83 | * @return array |
1747ab99 | 84 | * API result array. |
6a488035 TO |
85 | */ |
86 | function civicrm_api3_price_field_value_delete($params) { | |
87 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
88 | } |