3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
14 * This api exposes CiviCRM Price Sets.
16 * PriceSets contain PriceFields (which have their own api).
17 * Use chaining to create a PriceSet and associated PriceFields in one api call.
19 * @package CiviCRM_APIv3
23 * Create or update a PriceSet.
25 * @param array $params
26 * name/value pairs to insert in new 'PriceSet'
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);
39 foreach ($entityId as $eid) {
40 $eid = (int) trim($eid);
42 CRM_Price_BAO_PriceSet
::addTo($params['entity_table'], $eid, $result['id']);
50 * Adjust Metadata for Create action.
52 * The metadata is used for setting defaults, documentation & validation.
54 * @param array $params
55 * Array of parameters determined by getfields.
57 function _civicrm_api3_price_set_create_spec(&$params) {
58 $params['title']['api.required'] = TRUE;
62 * Returns array of price_sets matching a set of one or more group properties.
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)
69 * Array of matching price_sets
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);
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');
84 return civicrm_api3_create_success($result, $params);
88 * Delete an existing PriceSet.
90 * This method is used to delete any existing PriceSet given its id.
92 * @param array $params
93 * Array containing id of the group to be deleted.
98 function civicrm_api3_price_set_delete($params) {
99 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);