本文整理汇总了PHP中CRM_Price_BAO_PriceSet::removeFrom方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Price_BAO_PriceSet::removeFrom方法的具体用法?PHP CRM_Price_BAO_PriceSet::removeFrom怎么用?PHP CRM_Price_BAO_PriceSet::removeFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Price_BAO_PriceSet
的用法示例。
在下文中一共展示了CRM_Price_BAO_PriceSet::removeFrom方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
/**
* Process the form.
*/
public function postProcess()
{
$eventTitle = '';
$params = $this->exportValues();
$this->set('discountSection', 0);
if (!empty($_POST['_qf_Fee_submit'])) {
$this->buildAmountLabel();
$this->set('discountSection', 2);
return;
}
if (!empty($params['payment_processor'])) {
$params['payment_processor'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']);
} else {
$params['payment_processor'] = 'null';
}
$params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
$params['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $params, 0);
if ($this->_id) {
// 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');
CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
}
} else {
// if there are label / values, create custom options for them
$labels = CRM_Utils_Array::value('label', $params);
$values = CRM_Utils_Array::value('value', $params);
$default = CRM_Utils_Array::value('default', $params);
$options = array();
if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
for ($i = 1; $i < self::NUM_OPTION; $i++) {
if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
$options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
}
}
if (!empty($options)) {
$params['default_fee_id'] = NULL;
if (empty($params['price_set_id'])) {
if (empty($params['price_field_id'])) {
$setParams['title'] = $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
$eventTitle = strtolower(CRM_Utils_String::munge($eventTitle, '_', 245));
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle, 'id', 'name')) {
$setParams['name'] = $eventTitle;
} elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $this->_id, 'id', 'name')) {
$setParams['name'] = $eventTitle . '_' . $this->_id;
} else {
$timeSec = explode('.', microtime(TRUE));
$setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
}
$setParams['is_quick_config'] = 1;
$setParams['financial_type_id'] = $params['financial_type_id'];
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
$fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245));
$fieldParams['price_set_id'] = $priceSet->id;
} else {
foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
unset($params['price_field_value'][$arrayID]);
}
}
$fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
$fieldParams['option_id'] = $params['price_field_value'];
$priceSet = new CRM_Price_BAO_PriceSet();
$priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
}
}
$fieldParams['label'] = $params['fee_label'];
$fieldParams['html_type'] = 'Radio';
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id);
$fieldParams['option_label'] = $params['label'];
$fieldParams['option_amount'] = $params['value'];
$fieldParams['financial_type_id'] = $params['financial_type_id'];
foreach ($options as $value) {
$fieldParams['option_weight'][$value['weight']] = $value['weight'];
}
$fieldParams['default_option'] = $params['default'];
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
//.........这里部分代码省略.........
示例2: postProcess
//.........这里部分代码省略.........
$setParams['name'] = $pageTitle . '_' . $this->_id;
} else {
$timeSec = explode(".", microtime(TRUE));
$setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
}
$setParams['is_quick_config'] = 1;
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
$setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
$priceSetID = $priceSet->id;
$fieldParams['price_set_id'] = $priceSet->id;
} elseif ($usedPriceSetId) {
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviMember');
$setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
$setParams['id'] = $usedPriceSetId;
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
$priceSetID = $priceSet->id;
$fieldParams['price_set_id'] = $priceSet->id;
} else {
$fieldParams['id'] = CRM_Utils_Array::value('mem_price_field_id', $params);
$priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('mem_price_field_id', $params), 'price_set_id');
}
$editedFieldParams = array('price_set_id' => $priceSetID, 'name' => 'membership_amount');
$editedResults = array();
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
if (empty($editedResults['id'])) {
$fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245));
if (empty($params['mem_price_field_id'])) {
CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', 0, 1, array('price_set_id' => $priceSetID));
}
$fieldParams['weight'] = 1;
} else {
$fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults);
}
$fieldParams['label'] = !empty($params['membership_type_label']) ? $params['membership_type_label'] : ts('Membership');
$fieldParams['is_active'] = 1;
$fieldParams['html_type'] = 'Radio';
$fieldParams['is_required'] = !empty($params['is_required']) ? 1 : 0;
$fieldParams['is_display_amounts'] = !empty($params['display_min_fee']) ? 1 : 0;
$rowCount = 1;
$options = array();
if (!empty($fieldParams['id'])) {
CRM_Core_PseudoConstant::populate($options, 'CRM_Price_DAO_PriceFieldValue', TRUE, 'membership_type_id', NULL, " price_field_id = {$fieldParams['id']} ");
}
foreach ($membershipTypes as $memType => $memAutoRenew) {
if ($priceFieldID = CRM_Utils_Array::key($memType, $options)) {
$fieldParams['option_id'][$rowCount] = $priceFieldID;
unset($options[$priceFieldID]);
}
$membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
$fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
$fieldParams['option_amount'][$rowCount] = CRM_Utils_Array::value('minimum_fee', $membetype, 0);
$fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
$fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
$fieldParams['default_option'] = CRM_Utils_Array::value('membership_type_default', $params);
$fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype);
$fieldParams['membership_type_id'][$rowCount] = $memType;
// [$rowCount] = $membetype[''];
$rowCount++;
}
foreach ($options as $priceFieldID => $memType) {
CRM_Price_BAO_PriceFieldValue::setIsActive($priceFieldID, '0');
}
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
} elseif (!$priceSetID) {
$deletePriceSet = 1;
}
$params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
$params['is_active'] = CRM_Utils_Array::value('member_is_active', $params, FALSE);
if ($priceSetID) {
$params['membership_types'] = 'null';
$params['membership_type_default'] = CRM_Utils_Array::value('membership_type_default', $params, 'null');
$params['membership_types'] = serialize($membershipTypes);
$params['display_min_fee'] = CRM_Utils_Array::value('display_min_fee', $params, FALSE);
$params['is_separate_payment'] = CRM_Utils_Array::value('is_separate_payment', $params, FALSE);
}
$params['entity_table'] = 'civicrm_contribution_page';
$params['entity_id'] = $this->_id;
$dao = new CRM_Member_DAO_MembershipBlock();
$dao->copyValues($params);
$dao->save();
if ($priceSetID && $params['is_active']) {
CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $this->_id, $priceSetID);
}
if ($deletePriceSet || !CRM_Utils_Array::value('member_is_active', $params, FALSE)) {
if ($this->_memPriceSetId) {
$pFIDs = array();
$conditionParams = array('price_set_id' => $this->_memPriceSetId, 'html_type' => 'radio', 'name' => 'contribution_amount');
CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $conditionParams, $pFIDs);
if (empty($pFIDs['id'])) {
CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
CRM_Price_BAO_PriceSet::setIsQuickConfig($this->_memPriceSetId, '0');
} else {
CRM_Price_BAO_PriceField::setIsActive($params['mem_price_field_id'], '0');
}
}
}
}
parent::endPostProcess();
}
示例3: deleteContribution
/**
* Delete the indirect records associated with this contribution first.
*
* @param int $id
*
* @return mixed|null
* $results no of deleted Contribution on success, false otherwise
*/
public static function deleteContribution($id)
{
CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray);
$transaction = new CRM_Core_Transaction();
$results = NULL;
//delete activity record
$params = array('source_record_id' => $id, 'activity_type_id' => 6);
CRM_Activity_BAO_Activity::deleteActivity($params);
//delete billing address if exists for this contribution.
self::deleteAddress($id);
//update pledge and pledge payment, CRM-3961
CRM_Pledge_BAO_PledgePayment::resetPledgePayment($id);
// remove entry from civicrm_price_set_entity, CRM-5095
if (CRM_Price_BAO_PriceSet::getFor('civicrm_contribution', $id)) {
CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution', $id);
}
// cleanup line items.
$participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id');
// delete any related entity_financial_trxn, financial_trxn and financial_item records.
CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id);
if ($participantId) {
CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant');
} else {
CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution');
}
//delete note.
$note = CRM_Core_BAO_Note::getNote($id, 'civicrm_contribution');
$noteId = key($note);
if ($noteId) {
CRM_Core_BAO_Note::del($noteId, FALSE);
}
$dao = new CRM_Contribute_DAO_Contribution();
$dao->id = $id;
$results = $dao->delete();
$transaction->commit();
CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao);
// delete the recently created Contribution
$contributionRecent = array('id' => $id, 'type' => 'Contribution');
CRM_Utils_Recent::del($contributionRecent);
return $results;
}
示例4: del
/**
* Function to delete the event
*
* @param int $id event id
*
* @return mixed|null
* @access public
* @static
*
*/
static function del($id)
{
if (!$id) {
return NULL;
}
CRM_Utils_Hook::pre('delete', 'Event', $id, CRM_Core_DAO::$_nullArray);
$extends = array('event');
$groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends);
foreach ($groupTree as $values) {
$query = "DELETE FROM " . $values['table_name'] . " WHERE entity_id = " . $id;
$params = array(1 => array($values['table_name'], 'string'), 2 => array($id, 'integer'));
CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
}
// price set cleanup, CRM-5527
CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $id);
$event = new CRM_Event_DAO_Event();
$event->id = $id;
if ($event->find(TRUE)) {
$locBlockId = $event->loc_block_id;
$result = $event->delete();
if (!is_null($locBlockId)) {
self::deleteEventLocBlock($locBlockId, $id);
}
CRM_Utils_Hook::post('delete', 'Event', $id, $event);
return $result;
}
return NULL;
}
示例5: postProcess
//.........这里部分代码省略.........
$fieldParams['option_label'] = $params['label'];
$fieldParams['option_amount'] = $params['value'];
$fieldParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values);
foreach ($options as $value) {
$fieldParams['option_weight'][$value['weight']] = $value['weight'];
}
$fieldParams['default_option'] = $params['default'];
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
}
if (!empty($params['is_allow_other_amount']) && empty($params['price_field_other'])) {
$editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'other_amount');
$editedResults = array();
CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults);
if (!($priceFieldID = CRM_Utils_Array::value('id', $editedResults))) {
$fieldParams = array('name' => 'other_amount', 'label' => ts('Other Amount'), 'price_set_id' => $priceSetId, 'html_type' => 'Text', 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $this->_values), 'is_display_amounts' => 0, 'weight' => 3);
$fieldParams['option_weight'][1] = 1;
$fieldParams['option_amount'][1] = 1;
if (!$noContriAmount) {
$fieldParams['is_required'] = 1;
$fieldParams['option_label'][1] = $fieldParams['label'] = $params['amount_label'];
} else {
$fieldParams['is_required'] = 0;
$fieldParams['option_label'][1] = $fieldParams['label'] = ts('Other Amount');
}
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
} else {
if (empty($editedResults['is_active'])) {
$fieldParams = $editedResults;
if (!$noContriAmount) {
$priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
$fieldParams = array('is_required' => 1, 'label' => $params['amount_label'], 'id' => $priceFieldID);
}
$fieldParams['is_active'] = 1;
$priceField = CRM_Price_BAO_PriceField::add($fieldParams);
}
}
} elseif (empty($params['is_allow_other_amount']) && !empty($params['price_field_other'])) {
CRM_Price_BAO_PriceField::setIsActive($params['price_field_other'], '0');
} elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) {
$priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldID, 'id', 'price_field_id');
if (!$noContriAmount) {
$fieldParams = array('is_required' => 1, 'label' => $params['amount_label'], 'id' => $priceFieldID);
CRM_Price_BAO_PriceField::add($fieldParams);
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', $params['amount_label']);
} else {
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $priceFieldID, 'is_required', 0);
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldValueID, 'label', ts('Other Amount'));
}
}
}
if (!empty($params['is_pledge_active'])) {
$deletePledgeBlk = FALSE;
$pledgeBlockParams = array('entity_id' => $contributionPageID, 'entity_table' => ts('civicrm_contribution_page'));
if ($this->_pledgeBlockID) {
$pledgeBlockParams['id'] = $this->_pledgeBlockID;
}
$pledgeBlock = array('pledge_frequency_unit', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day');
foreach ($pledgeBlock as $key) {
$pledgeBlockParams[$key] = CRM_Utils_Array::value($key, $params);
}
$pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array::value('is_pledge_interval', $params, FALSE);
// create pledge block.
CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams);
}
}
} else {
if (!empty($params['price_field_id']) || !empty($params['price_field_other'])) {
$usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
if ($usedPriceSetId) {
if (!empty($params['price_field_id'])) {
CRM_Price_BAO_PriceField::setIsActive($params['price_field_id'], '0');
}
if (!empty($params['price_field_other'])) {
CRM_Price_BAO_PriceField::setIsActive($params['price_field_other'], '0');
}
} else {
$deleteAmountBlk = TRUE;
$deletePriceSet = TRUE;
}
}
}
// delete pledge block.
if ($deletePledgeBlk) {
CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($this->_pledgeBlockID);
}
// delete previous price set.
if ($deletePriceSet) {
CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $contributionPageID);
}
if ($deleteAmountBlk) {
$priceField = !empty($params['price_field_id']) ? $params['price_field_id'] : CRM_Utils_Array::value('price_field_other', $params);
if ($priceField) {
$priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $priceField, 'price_set_id');
CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
}
}
}
parent::endPostProcess();
}
示例6: setPriceSets
/**
* 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.
*/
public 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($entity->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 (!empty($params['price_field_id'])) {
// $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
// CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
//}
}
}
示例7: postProcess
/**
* Process the form when submitted
*
* @return void
* @access public
*/
public function postProcess()
{
$transaction = new CRM_Core_Transaction();
// first delete the join entries associated with this contribution page
$dao = new CRM_Core_DAO_UFJoin();
$params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id);
$dao->copyValues($params);
$dao->delete();
//next delete the membership block fields
$dao = new CRM_Member_DAO_MembershipBlock();
$dao->entity_table = 'civicrm_contribution_page';
$dao->entity_id = $this->_id;
$dao->delete();
//next delete the pcp block fields
$dao = new CRM_PCP_DAO_PCPBlock();
$dao->entity_table = 'civicrm_contribution_page';
$dao->entity_id = $this->_id;
$dao->delete();
// need to delete premiums. CRM-4586
CRM_Contribute_BAO_Premium::deletePremium($this->_id);
// price set cleanup, CRM-5527
CRM_Price_BAO_PriceSet::removeFrom('civicrm_contribution_page', $this->_id);
// finally delete the contribution page
$dao = new CRM_Contribute_DAO_ContributionPage();
$dao->id = $this->_id;
$dao->delete();
$transaction->commit();
CRM_Core_Session::setStatus(ts("The contribution page '%1' has been deleted.", array(1 => $this->_title)), ts('Deleted'), 'success');
}
示例8: postProcess
/**
* Process the form
*
* @return void
* @access public
*/
public function postProcess()
{
$eventTitle = '';
$params = $this->exportValues();
$this->set('discountSection', 0);
if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) {
$this->buildAmountLabel();
$this->set('discountSection', 2);
return;
}
if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) {
$params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor']));
} else {
$params['payment_processor'] = 'null';
}
$params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
if ($this->_id) {
// delete all the prior label values or discounts in the custom options table
// and delete a price set if one exists
if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $this->_id)) {
CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event');
}
}
if ($params['is_monetary']) {
if (CRM_Utils_Array::value('price_set_id', $params)) {
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $params['price_set_id']);
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);
}
} else {
// if there are label / values, create custom options for them
$labels = CRM_Utils_Array::value('label', $params);
$values = CRM_Utils_Array::value('value', $params);
$default = CRM_Utils_Array::value('default', $params);
$options = array();
if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
for ($i = 1; $i < self::NUM_OPTION; $i++) {
if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
$options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
}
}
if (!empty($options)) {
$params['default_fee_id'] = NULL;
if (!CRM_Utils_Array::value('price_set_id', $params)) {
if (!CRM_Utils_Array::value('price_field_id', $params)) {
$setParams['title'] = $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
$eventTitle = strtolower(CRM_Utils_String::munge($eventTitle, '_', 245));
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle, 'id', 'name')) {
$setParams['name'] = $eventTitle;
} elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $this->_id, 'id', 'name')) {
$setParams['name'] = $eventTitle . '_' . $this->_id;
} else {
$timeSec = explode('.', microtime(true));
$setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
}
$setParams['is_quick_config'] = 1;
$setParams['financial_type_id'] = $params['financial_type_id'];
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
$fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245));
$fieldParams['price_set_id'] = $priceSet->id;
} else {
foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
unset($params['price_field_value'][$arrayID]);
}
}
$fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
$fieldParams['option_id'] = $params['price_field_value'];
$priceSet = new CRM_Price_BAO_PriceSet();
$priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
}
}
$fieldParams['label'] = $params['fee_label'];
$fieldParams['html_type'] = 'Radio';
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id);
$fieldParams['option_label'] = $params['label'];
$fieldParams['option_amount'] = $params['value'];
$fieldParams['financial_type_id'] = $params['financial_type_id'];
foreach ($options as $value) {
$fieldParams['option_weight'][$value['weight']] = $value['weight'];
}
$fieldParams['default_option'] = $params['default'];
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
}
}
}
$discountPriceSets = CRM_Utils_Array::value('discount_price_set', $this->_defaultValues) ? $this->_defaultValues['discount_price_set'] : array();
$discountFieldIDs = CRM_Utils_Array::value('discount_option_id', $this->_defaultValues) ? $this->_defaultValues['discount_option_id'] : array();
if (CRM_Utils_Array::value('is_discount', $params) == 1) {
//.........这里部分代码省略.........