dev/core#1833 Change default value of participant_listing_id to NULL from 0
[civicrm-core.git] / api / v3 / PriceSet.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 Sets.
15 *
16 * PriceSets contain PriceFields (which have their own api).
17 * Use chaining to create a PriceSet and associated PriceFields in one api call.
18 *
19 * @package CiviCRM_APIv3
20 */
21
22 /**
23 * Create or update a PriceSet.
24 *
25 * @param array $params
26 * name/value pairs to insert in new 'PriceSet'
27 *
28 * @return array
29 * api result array
30 */
31 function civicrm_api3_price_set_create($params) {
32 $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'PriceSet');
33 // Handle price_set_entity
34 if (!empty($result['id']) && !empty($params['entity_table']) && !empty($params['entity_id'])) {
35 $entityId = $params['entity_id'];
36 if (!is_array($params['entity_id'])) {
37 $entityId = explode(',', $entityId);
38 }
39 foreach ($entityId as $eid) {
40 $eid = (int) trim($eid);
41 if ($eid) {
42 CRM_Price_BAO_PriceSet::addTo($params['entity_table'], $eid, $result['id']);
43 }
44 }
45 }
46 return $result;
47 }
48
49 /**
50 * Adjust Metadata for Create action.
51 *
52 * The metadata is used for setting defaults, documentation & validation.
53 *
54 * @param array $params
55 * Array of parameters determined by getfields.
56 */
57 function _civicrm_api3_price_set_create_spec(&$params) {
58 $params['title']['api.required'] = TRUE;
59 }
60
61 /**
62 * Returns array of price_sets 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_sets will be returned (default limit is 25)
67 *
68 * @return array
69 * Array of matching price_sets
70 */
71 function civicrm_api3_price_set_get($params) {
72 // hack to make getcount work. - not sure the best approach here
73 // as creating an alternate getcount function also feels a bit hacky
74 if (isset($params['options']) && isset($params['options']['is_count'])) {
75 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
76 }
77 $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
78 // Fetch associated entities if the return has not been previously limited.
79 if (!isset($params['return'])) {
80 foreach ($result as &$item) {
81 $item['entity'] = CRM_Price_BAO_PriceSet::getUsedBy($item['id'], 'entity');
82 }
83 }
84 return civicrm_api3_create_success($result, $params);
85 }
86
87 /**
88 * Delete an existing PriceSet.
89 *
90 * This method is used to delete any existing PriceSet given its id.
91 *
92 * @param array $params
93 * Array containing id of the group to be deleted.
94 *
95 * @return array
96 * API result array
97 */
98 function civicrm_api3_price_set_delete($params) {
99 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
100 }