本文整理汇总了PHP中CRM_Price_BAO_PriceSet::create方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Price_BAO_PriceSet::create方法的具体用法?PHP CRM_Price_BAO_PriceSet::create怎么用?PHP CRM_Price_BAO_PriceSet::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Price_BAO_PriceSet
的用法示例。
在下文中一共展示了CRM_Price_BAO_PriceSet::create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _addParticipantWithPayment
/**
* helper function to record participant with paid contribution.
* @param $feeTotal
* @param $actualPaidAmt
*
* @return array
* @throws Exception
*/
public function _addParticipantWithPayment($feeTotal, $actualPaidAmt)
{
// creating price set, price field
$paramsSet['title'] = 'Price Set';
$paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set');
$paramsSet['is_active'] = FALSE;
$paramsSet['extends'] = 1;
$priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceset->id);
$priceSetId = $priceset->id;
//Checking for priceset added in the table.
$this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
$paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => $feeTotal, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => $feeTotal), 'option_name' => array('1' => $feeTotal), 'option_weight' => array('1' => 1), 'option_amount' => array('1' => 1), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1);
$ids = array();
$pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids);
//Checking for priceset added in the table.
$this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label', 'id', $paramsField['label'], 'Check DB for created pricefield');
// create participant record
$eventId = $this->_eventId;
$participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 14, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55');
$participant = $this->callAPISuccess('participant', 'create', $participantParams);
$this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
// create participant contribution with partial payment
$contributionParams = array('total_amount' => $actualPaidAmt, 'source' => 'Fall Fundraiser Dinner: Offline registration', 'currency' => 'USD', 'non_deductible_amount' => 'null', 'receipt_date' => date('Y-m-d') . " 00:00:00", 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'payment_instrument_id' => 4, 'contribution_status_id' => 1, 'receive_date' => date('Y-m-d') . " 00:00:00", 'skipLineItem' => 1, 'partial_payment_total' => $feeTotal, 'partial_amount_pay' => $actualPaidAmt);
$contribution = CRM_Contribute_BAO_Contribution::create($contributionParams);
$contributionId = $contribution->id;
$participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id']));
// add participant payment entry
$this->callAPISuccess('participant_payment', 'create', array('participant_id' => $participant['id'], 'contribution_id' => $contributionId));
// -- processing priceSet using the BAO
$lineItem = array();
$priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, FALSE);
$priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
$feeBlock = CRM_Utils_Array::value('fields', $priceSet);
$params['price_2'] = $feeTotal;
CRM_Price_BAO_PriceSet::processAmount($feeBlock, $params, $lineItem);
$lineItemVal[$priceSetId] = $lineItem;
CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $contribution, 'civicrm_participant');
return array($participant, $contribution);
}
示例2: 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);
//.........这里部分代码省略.........
示例3: testfixEventLevel
/**
* FixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method
*/
public function testfixEventLevel()
{
$paramsSet['title'] = 'Price Set';
$paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set');
$paramsSet['is_active'] = FALSE;
$paramsSet['extends'] = 1;
$priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
//Checking for priceset added in the table.
$this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
$paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => 10, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => 10), 'option_name' => array('1' => 10), 'option_weight' => array('1' => 1), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1);
$ids = array();
$pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids);
//Checking for priceset added in the table.
$this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label', 'id', $paramsField['label'], 'Check DB for created pricefield');
$eventId = $this->_eventId;
$participantParams = array('send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, 'event_id' => $eventId, 'register_date' => date('Y-m-d') . " 00:00:00", 'role_id' => 1, 'status_id' => 1, 'source' => 'Event_' . $eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55');
$participant = CRM_Event_BAO_Participant::add($participantParams);
//Checking for participant added in the table.
$this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId, 'id', 'contact_id', $participant->id, 'Check DB for created participant');
$values = array();
$ids = array();
$params = array('id' => $participant->id);
CRM_Event_BAO_Participant::getValues($params, $values, $ids);
$this->assertNotEquals(count($values), 0, 'Checking for empty array.');
CRM_Event_BAO_Participant::resolveDefaults($values[$participant->id]);
if ($values[$participant->id]['fee_level']) {
CRM_Event_BAO_Participant::fixEventLevel($values[$participant->id]['fee_level']);
}
$deletePricefield = CRM_Price_BAO_PriceField::deleteField($pricefield->id);
$this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id, 'name', 'id', 'Check DB for non-existence of Price Field.');
$deletePriceset = CRM_Price_BAO_PriceSet::deleteSet($priceset->id);
$this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', 'Check DB for non-existence of Price Set.');
Participant::delete($participant->id);
Contact::delete($this->_contactId);
Event::delete($eventId);
}
示例4: postProcess
/**
* Process the form.
*
* @return void
*/
public function postProcess()
{
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
$deletePriceSet = 0;
if ($params['membership_type']) {
// we do this in case the user has hit the forward/back button
$dao = new CRM_Member_DAO_MembershipBlock();
$dao->entity_table = 'civicrm_contribution_page';
$dao->entity_id = $this->_id;
$dao->find(TRUE);
$membershipID = $dao->id;
if ($membershipID) {
$params['id'] = $membershipID;
}
$membershipTypes = array();
if (is_array($params['membership_type'])) {
foreach ($params['membership_type'] as $k => $v) {
if ($v) {
$membershipTypes[$k] = CRM_Utils_Array::value("auto_renew_{$k}", $params);
}
}
}
if ($this->_id && !empty($params['member_price_set_id'])) {
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'amount_block_is_active', 0);
}
// check for price set.
$priceSetID = CRM_Utils_Array::value('member_price_set_id', $params);
if (!empty($params['member_is_active']) && is_array($membershipTypes) && !$priceSetID) {
$usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 2);
if (empty($params['mem_price_field_id']) && !$usedPriceSetId) {
$pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
$setParams['title'] = $this->_values['title'];
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
$setParams['name'] = $pageTitle;
} elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
$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++;
//.........这里部分代码省略.........
示例5: addParticipantWithContribution
/**
* Add participant with contribution
*
* @return array
*/
protected function addParticipantWithContribution()
{
// creating price set, price field
require_once 'CiviTest/Event.php';
$this->_contactId = Contact::createIndividual();
$this->_eventId = Event::create($this->_contactId);
$paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 4);
$paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']);
$paramsSet['is_active'] = TRUE;
$paramsSet['financial_type_id'] = 4;
$paramsSet['extends'] = 1;
$priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
$priceSetId = $priceset->id;
//Checking for priceset added in the table.
$this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
$paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_value' => array('1' => 100, '2' => 200), 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_weight' => array('1' => 1, '2' => 2), 'option_amount' => array('1' => 100, '2' => 200), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1, '2' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', 'Event Fee', 'id', 'name'));
$priceField = CRM_Price_BAO_PriceField::create($paramsField);
$eventParams = array('id' => $this->_eventId, 'financial_type_id' => 4, 'is_monetary' => 1);
CRM_Event_BAO_Event::create($eventParams);
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $priceSetId);
$priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id));
$participantParams = array('financial_type_id' => 4, 'event_id' => $this->_eventId, 'role_id' => 1, 'status_id' => 14, 'fee_currency' => 'USD', 'contact_id' => $this->_contactId);
$participant = CRM_Event_BAO_Participant::add($participantParams);
$contributionParams = array('total_amount' => 150, 'currency' => 'USD', 'contact_id' => $this->_contactId, 'financial_type_id' => 4, 'contribution_status_id' => 1, 'partial_payment_total' => 300.0, 'partial_amount_pay' => 150, 'contribution_mode' => 'participant', 'participant_id' => $participant->id);
foreach ($priceFields['values'] as $key => $priceField) {
$lineItems[1][$key] = array('price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], 'field_title' => $priceField['label'], 'qty' => 1, 'unit_price' => $priceField['amount'], 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id']);
}
$contributionParams['line_item'] = $lineItems;
$contributions = CRM_Contribute_BAO_Contribution::create($contributionParams);
$paymentParticipant = array('participant_id' => $participant->id, 'contribution_id' => $contributions->id);
$ids = array();
CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
return array($lineItems, $contributions);
}
示例6: postProcess
/**
* Process the form.
*/
public function postProcess()
{
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
//update 'is_billing_required'
if (empty($params['is_pay_later'])) {
$params['is_billing_required'] = 0;
}
if (array_key_exists('payment_processor', $params)) {
if (array_key_exists(CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type_id'), CRM_Utils_Array::value('payment_processor', $params))) {
CRM_Core_Session::setStatus(ts(' Please note that the Authorize.net payment processor only allows recurring contributions and auto-renew memberships with payment intervals from 7-365 days or 1-12 months (i.e. not greater than 1 year).'), '', 'alert');
}
}
// check for price set.
$priceSetID = CRM_Utils_Array::value('price_set_id', $params);
// get required fields.
$fields = array('id' => $this->_id, 'is_recur' => FALSE, 'min_amount' => "null", 'max_amount' => "null", 'is_monetary' => FALSE, 'is_pay_later' => FALSE, 'is_billing_required' => FALSE, 'is_recur_interval' => FALSE, 'is_recur_installments' => FALSE, 'recur_frequency_unit' => "null", 'default_amount_id' => "null", 'is_allow_other_amount' => FALSE, 'amount_block_is_active' => FALSE);
$resetFields = array();
if ($priceSetID) {
$resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount');
}
if (empty($params['is_recur'])) {
$resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit'));
}
foreach ($fields as $field => $defaultVal) {
$val = CRM_Utils_Array::value($field, $params, $defaultVal);
if (in_array($field, $resetFields)) {
$val = $defaultVal;
}
if (in_array($field, array('min_amount', 'max_amount'))) {
$val = CRM_Utils_Rule::cleanMoney($val);
}
$params[$field] = $val;
}
if ($params['is_recur']) {
$params['recur_frequency_unit'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['recur_frequency_unit']));
$params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, FALSE);
$params['is_recur_installments'] = CRM_Utils_Array::value('is_recur_installments', $params, FALSE);
}
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';
}
$contributionPage = CRM_Contribute_BAO_ContributionPage::create($params);
$contributionPageID = $contributionPage->id;
// prepare for data cleanup.
$deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = FALSE;
if ($this->_priceSetID) {
$deletePriceSet = TRUE;
}
if ($this->_pledgeBlockID) {
$deletePledgeBlk = TRUE;
}
if (!empty($this->_amountBlock)) {
$deleteAmountBlk = TRUE;
}
if ($contributionPageID) {
if (!empty($params['amount_block_is_active'])) {
// handle price set.
if ($priceSetID) {
// add/update price set.
$deletePriceSet = FALSE;
if (!empty($params['price_field_id']) || !empty($params['price_field_other'])) {
$deleteAmountBlk = TRUE;
}
CRM_Price_BAO_PriceSet::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID);
} else {
$deletePriceSet = FALSE;
// process contribution amount block
$deleteAmountBlk = FALSE;
$labels = CRM_Utils_Array::value('label', $params);
$values = CRM_Utils_Array::value('value', $params);
$default = CRM_Utils_Array::value('default', $params);
$options = array();
for ($i = 1; $i < self::NUM_OPTION; $i++) {
if (isset($values[$i]) && strlen(trim($values[$i])) > 0) {
$options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
}
}
/* || !empty($params['price_field_value']) || CRM_Utils_Array::value( 'price_field_other', $params )*/
if (!empty($options) || !empty($params['is_allow_other_amount'])) {
$fieldParams['is_quick_config'] = 1;
$noContriAmount = NULL;
$usedPriceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3);
if (!(!empty($params['price_field_id']) || !empty($params['price_field_other'])) && !$usedPriceSetId) {
$pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245));
$setParams['title'] = $this->_values['title'];
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle, 'id', 'name')) {
$setParams['name'] = $pageTitle;
} elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $pageTitle . '_' . $this->_id, 'id', 'name')) {
$setParams['name'] = $pageTitle . '_' . $this->_id;
} else {
$timeSec = explode(".", microtime(TRUE));
$setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
}
$setParams['is_quick_config'] = 1;
//.........这里部分代码省略.........
示例7: postProcess
/**
* Process the form.
*
* @return void
*/
public function postProcess()
{
// get the submitted form values.
$params = $this->controller->exportValues('Set');
$nameLength = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'name');
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params, FALSE);
$compIds = array();
$extends = CRM_Utils_Array::value('extends', $params);
if (is_array($extends)) {
foreach ($extends as $compId => $selected) {
if ($selected) {
$compIds[] = $compId;
}
}
}
$params['extends'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $compIds);
if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_sid;
} else {
$params['name'] = CRM_Utils_String::titleToVar($params['title'], CRM_Utils_Array::value('maxlength', $nameLength));
}
$set = CRM_Price_BAO_PriceSet::create($params);
if ($this->_action & CRM_Core_Action::UPDATE) {
CRM_Core_Session::setStatus(ts('The Set \'%1\' has been saved.', array(1 => $set->title)), ts('Saved'), 'success');
} else {
// Jump directly to adding a field if popups are disabled
$action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? 'browse' : 'add';
$url = CRM_Utils_System::url('civicrm/admin/price/field', array('reset' => 1, 'action' => $action, 'sid' => $set->id, 'new' => 1));
CRM_Core_Session::setStatus(ts("Your Set '%1' has been added. You can add fields to this set now.", array(1 => $set->title)), ts('Saved'), 'success');
$session = CRM_Core_Session::singleton();
$session->replaceUserContext($url);
}
}
示例8: eventPriceSetCreate
/**
* Create a price set for an event.
*
* @param int $feeTotal
*
* @return int
* Price Set ID.
*/
protected function eventPriceSetCreate($feeTotal)
{
// creating price set, price field
$paramsSet['title'] = 'Price Set';
$paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set');
$paramsSet['is_active'] = FALSE;
$paramsSet['extends'] = 1;
$priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
$priceSetId = $priceset->id;
//Checking for priceset added in the table.
$this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
$paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => $feeTotal, 'option_label' => array('1' => 'Price Field'), 'option_value' => array('1' => $feeTotal), 'option_name' => array('1' => $feeTotal), 'option_weight' => array('1' => 1), 'option_amount' => array('1' => 1), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => $this->getFinancialTypeId('Event Fee'));
CRM_Price_BAO_PriceField::create($paramsField);
return $priceSetId;
}
示例9: testcheckPermissionedLineItems
/**
* Check method testcheckPermissionedLineItems()
*/
public function testcheckPermissionedLineItems()
{
$contactId = Contact::createIndividual();
$paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 4);
$paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']);
$paramsSet['is_active'] = TRUE;
$paramsSet['financial_type_id'] = 1;
$paramsSet['extends'] = 1;
$priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
$priceSetId = $priceset->id;
//Checking for priceset added in the table.
$this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
$paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_value' => array('1' => 100, '2' => 200), 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_weight' => array('1' => 1, '2' => 2), 'option_amount' => array('1' => 100, '2' => 200), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1, '2' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => 1);
$priceField = CRM_Price_BAO_PriceField::create($paramsField);
$priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id));
$contributionParams = array('total_amount' => 300, 'currency' => 'USD', 'contact_id' => $contactId, 'financial_type_id' => 1, 'contribution_status_id' => 1);
foreach ($priceFields['values'] as $key => $priceField) {
$lineItems[1][$key] = array('price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], 'field_title' => $priceField['label'], 'qty' => 1, 'unit_price' => $priceField['amount'], 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id']);
}
$contributionParams['line_item'] = $lineItems;
$contributions = CRM_Contribute_BAO_Contribution::create($contributionParams);
CRM_Financial_BAO_FinancialType::$_statusACLFt = array();
$this->setACL();
$this->setPermissions(array('view contributions of type Member Dues'));
try {
CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributions->id, 'view');
$this->fail("Missed expected exception");
} catch (Exception $e) {
$this->assertEquals("A fatal error was triggered: You do not have permission to access this page.", $e->getMessage());
}
$this->setPermissions(array('view contributions of type Donation'));
$perm = CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributions->id, 'view');
$this->assertEquals($perm, TRUE, 'Verify that lineitems now have permission.');
}
示例10: 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) {
//.........这里部分代码省略.........