}
$event = self::add($params);
-
+ CRM_Price_BAO_PriceSet::setPriceSets($params, $event, 'event');
if (is_a($event, 'CRM_Core_Error')) {
CRM_Core_DAO::transaction('ROLLBACK');
return $event;
$optionIds[$rowCount] = $optionIds[$key];
unset($optionIds[$key]);
}
- }
+ }
}
$rowCount++;
}
// delete all the prior label values or discounts in the custom options table
// and delete a price set if one exists
+ //@todo note that this removes the reference from existing participants -
+ // even where there is not change - redress?
+ // note that a more tentative form of this is invoked by passing price_set_id as an array
+ // to event.create see CRM-14069
+ // @todo get all of this logic out of form layer (currently partially in BAO/api layer)
if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $this->_id)) {
CRM_Core_BAO_Discount::del($this->_id,'civicrm_event');
}
if ($params['is_monetary']) {
if (!empty($params['price_set_id'])) {
+ //@todo this is now being done in the event BAO if passed price_set_id as an array
+ // per notes on that fn - looking at the api converting to an array
+ // so calling via the api may cause this to be done in the api
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $params['price_set_id']);
if (!empty($params['price_field_id'])) {
$priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
$priceSetID = $priceSet->id;
- }
+ }
else {
$priceSetID = $discountPriceSets[$j-1];
$setParams = array (
return $defaults;
}
+ /**
+ * Supports event create function by setting up required price sets, not tested but expect
+ * it will work for contribution page
+ * @param array $params as passed to api/bao create fn
+ * @param CRM_Core_DAO $entity object for given entity
+ * @param string $entityName name of entity - e.g event
+ */
+ static function setPriceSets(&$params, $entity, $entityName) {
+ if(empty($params['price_set_id']) || !is_array($params['price_set_id'])) {
+ return;
+ }
+ // CRM-14069 note that we may as well start by assuming more than one.
+ // currently the form does not pass in as an array & will be skipped
+ // test is passing in as an array but I feel the api should have a metadata that allows
+ // transform of single to array - seems good for managing transitions - in which case all api
+ // calls that set price_set_id will hit this
+ // e.g in getfields 'price_set_id' => array('blah', 'bao_type' => 'array') - causing
+ // all separated values, strings, json half-separated values (in participant we hit this)
+ // to be converted to json @ api layer
+ $pse = new CRM_Price_DAO_PriceSetEntity();
+ $pse->entity_table = 'civicrm_' . $entityName;
+ $pse->entity_id = $entity->id;
+ while ($pse->fetch()) {
+ if(!in_array($pse->price_set_id, $params['price_set_id'])) {
+ // note an even more aggressive form of this deletion currently happens in event form
+ // past price sets discounts are made inaccessible by this as the discount_id is set to NULL
+ // on the participant record
+ if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_' . $entityName, $entity->id)) {
+ CRM_Core_BAO_Discount::del($this->_id,'civicrm_' . $entityName);
+ }
+ }
+ }
+ foreach ($params['price_set_id'] as $priceSetID) {
+ CRM_Price_BAO_PriceSet::addTo('civicrm_' . $entityName, $entity->id, $priceSetID);
+ //@todo - how should we do this - copied from form
+ //if (CRM_Utils_Array::value('price_field_id', $params)) {
+ // $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
+ // CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
+ //}
+ }
+ }
/**
* Get field ids of a price set
*
$copy = CRM_Event_BAO_Event::copy($params['template_id']);
$params['id'] = $copy->id;
unset($params['template_id']);
- if (empty($params['is_template'])) {
- $params['is_template'] = 0;
- }
}
_civicrm_api3_event_create_legacy_support_42($params);
-
- //format custom fields so they can be added
- $values = array();
- _civicrm_api3_custom_format_params($params, $values, 'Event');
- $params = array_merge($values, $params);
-
- $eventBAO = CRM_Event_BAO_Event::create($params);
- $event = array();
- _civicrm_api3_object_to_array($eventBAO, $event[$eventBAO->id]);
- return civicrm_api3_create_success($event, $params);
+ return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Event');
}
/**
// the return.is_full to deal with.
// NB the std dao_to_array function should only return custom if required.
$event = array();
+ $options = _civicrm_api3_get_options_from_params($params);
+
$eventDAO->find();
while ($eventDAO->fetch()) {
$event[$eventDAO->id] = array();
}
_civicrm_api3_event_get_legacy_support_42($event, $eventDAO->id);
_civicrm_api3_custom_data_get($event[$eventDAO->id], 'Event', $eventDAO->id, NULL, $eventDAO->event_type_id);
+ if(!empty($options['return'])) {
+ $event[$eventDAO->id]['price_set_id'] = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventDAO->id);
+ }
}
//end of the loop
$this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id']));
}
+ /**
+ * Test that an event with a price set can be created
+ */
+ function testCreatePaidEvent() {
+ //@todo alter API so that an integer is converted to an array
+ $priceSetParams = array('price_set_id' => (array) 1, 'is_monetary' => 1);
+ $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params[0], $priceSetParams));
+ $event = $this->callAPISuccess('Event', 'getsingle', array('id' => $result['id'], 'return' => 'price_set_id'));
+ $this->assertArrayKeyExists('price_set_id', $event);
+ }
+
function testCreateEventParamsNotArray() {
$params = NULL;
$result = $this->callAPIFailure('event', 'create', $params);