Merge pull request #18950 from MegaphoneJon/event-44
[civicrm-core.git] / api / v3 / PriceFieldValue.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 /**
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.
18 *
19 * @package CiviCRM_APIv3
20 */
21
22 /**
23 * Create or update a PriceFieldValue.
24 *
25 * @param array $params
26 * name/value pairs to insert in new 'PriceFieldValue'
27 *
28 * @return array
29 * API result array.
30 */
31 function civicrm_api3_price_field_value_create($params) {
32 $ids = [];
33 if (!empty($params['id'])) {
34 $ids['id'] = $params['id'];
35 }
36
37 $bao = CRM_Price_BAO_PriceFieldValue::create($params, $ids);
38
39 $values = [];
40 _civicrm_api3_object_to_array($bao, $values[$bao->id]);
41 return civicrm_api3_create_success($values, $params, 'PriceFieldValue', 'create', $bao);
42
43 }
44
45 /**
46 * Adjust Metadata for Create action.
47 *
48 * The metadata is used for setting defaults, documentation & validation.
49 *
50 * @param array $params
51 * Array of parameters determined by getfields.
52 */
53 function _civicrm_api3_price_field_value_create_spec(&$params) {
54 $params['price_field_id']['api.required'] = TRUE;
55 $params['label']['api.required'] = TRUE;
56 $params['amount']['api.required'] = TRUE;
57 $params['is_active']['api.default'] = TRUE;
58 $params['financial_type_id']['api.default'] = TRUE;
59 }
60
61 /**
62 * Returns array of PriceFieldValues matching a set of one or more group properties.
63 *
64 * @param array $params
65 * Array of one or more valid property_name=>value pairs. If $params is set.
66 * as null, all price_field_values will be returned (default limit is 25)
67 *
68 * @return array
69 * API result array.
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 /**
76 * Delete an existing PriceFieldValue.
77 *
78 * This method is used to delete any existing PriceFieldValue given its id.
79 *
80 * @param array $params
81 * Array containing id of the group to be deleted.
82 *
83 * @return array
84 * API result array.
85 */
86 function civicrm_api3_price_field_value_delete($params) {
87 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
88 }