本文整理汇总了PHP中CRM_Price_DAO_PriceField类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Price_DAO_PriceField类的具体用法?PHP CRM_Price_DAO_PriceField怎么用?PHP CRM_Price_DAO_PriceField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Price_DAO_PriceField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
function validate()
{
parent::validate();
if ($this->_errors) {
return FALSE;
}
$this->cart->load_associations();
$fields = $this->_submitValues;
foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) {
$price_set_id = CRM_Event_BAO_Event::usesPriceSet($event_in_cart->event_id);
if ($price_set_id) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $price_set_id;
$priceField->find();
$check = array();
while ($priceField->fetch()) {
if (!empty($fields["event_{$event_in_cart->event_id}_price_{$priceField->id}"])) {
$check[] = $priceField->id;
}
}
//XXX
if (empty($check)) {
$this->_errors['_qf_default'] = ts("Select at least one option from Price Levels.");
}
$lineItem = array();
if (is_array($this->_values['fee']['fields'])) {
CRM_Price_BAO_PriceSet::processAmount($this->_values['fee']['fields'], $fields, $lineItem);
//XXX total...
if ($fields['amount'] < 0) {
$this->_errors['_qf_default'] = ts("Price Levels can not be less than zero. Please select the options accordingly");
}
}
}
foreach ($event_in_cart->participants as $mer_participant) {
$participant_fields = $fields['event'][$event_in_cart->event_id]['participant'][$mer_participant->id];
//TODO what to do when profile responses differ for the same contact?
$contact_id = self::find_contact($participant_fields);
if ($contact_id) {
$participant = new CRM_Event_BAO_Participant();
$participant->event_id = $event_in_cart->event_id;
$participant->contact_id = $contact_id;
$statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
$participant->find();
while ($participant->fetch()) {
if (array_key_exists($participant->status_id, $statusTypes)) {
$form = $mer_participant->get_form();
$this->_errors[$form->html_field_name('email')] = ts("The participant %1 is already registered for %2 (%3).", array(1 => $participant_fields['email'], 2 => $event_in_cart->event->title, 3 => $event_in_cart->event->start_date));
}
}
}
}
}
return empty($this->_errors);
}
示例2: addRecurLineItems
/**
* @param $recurId
* @param $contribution
*
* @internal param $contributionId
*
* @return array
*/
function addRecurLineItems($recurId, $contribution)
{
$lineSets = array();
$originalContributionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id');
$lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($originalContributionID);
if (count($lineItems) == 1) {
foreach ($lineItems as $index => $lineItem) {
if ($lineItem['line_total'] != $contribution->total_amount) {
// We are dealing with a changed amount! Per CRM-16397 we can work out what to do with these
// if there is only one line item, and the UI should prevent this situation for those with more than one.
$lineItems[$index]['line_total'] = $contribution->total_amount;
$lineItems[$index]['unit_price'] = round($contribution->total_amount / $lineItems[$index]['qty'], 2);
}
}
}
if (!empty($lineItems)) {
foreach ($lineItems as $key => $value) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->id = $value['price_field_id'];
$priceField->find(TRUE);
$lineSets[$priceField->price_set_id][] = $value;
}
} else {
CRM_Price_BAO_LineItem::processPriceSet($contribution->id, $lineSets, $contribution);
}
return $lineSets;
}
示例3: priceSetValidation
/**
* Validate the priceset
*
* @param int $priceSetId , array $fields
*
* retrun the error string
*
* @param $fields
* @param $error
* @param bool $allowNoneSelection
*
* @access public
* @static
*/
public static function priceSetValidation($priceSetId, $fields, &$error, $allowNoneSelection = FALSE)
{
// check for at least one positive
// amount price field should be selected.
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $priceSetId;
$priceField->find();
$priceFields = array();
if ($allowNoneSelection) {
$noneSelectedPriceFields = array();
}
while ($priceField->fetch()) {
$key = "price_{$priceField->id}";
if ($allowNoneSelection) {
if (array_key_exists($key, $fields)) {
if ($fields[$key] == 0 && !$priceField->is_required) {
$noneSelectedPriceFields[] = $priceField->id;
}
}
}
if (!empty($fields[$key])) {
$priceFields[$priceField->id] = $fields[$key];
}
}
if (!empty($priceFields)) {
// we should has to have positive amount.
$sql = "\nSELECT id, html_type\nFROM civicrm_price_field\nWHERE id IN (" . implode(',', array_keys($priceFields)) . ')';
$fieldDAO = CRM_Core_DAO::executeQuery($sql);
$htmlTypes = array();
while ($fieldDAO->fetch()) {
$htmlTypes[$fieldDAO->id] = $fieldDAO->html_type;
}
$selectedAmounts = array();
foreach ($htmlTypes as $fieldId => $type) {
$options = array();
CRM_Price_BAO_PriceFieldValue::getValues($fieldId, $options);
if (empty($options)) {
continue;
}
if ($type == 'Text') {
foreach ($options as $opId => $option) {
$selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount'];
break;
}
} elseif (is_array($fields["price_{$fieldId}"])) {
foreach (array_keys($fields["price_{$fieldId}"]) as $opId) {
$selectedAmounts[$opId] = $options[$opId]['amount'];
}
} elseif (in_array($fields["price_{$fieldId}"], array_keys($options))) {
$selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount'];
}
}
list($componentName) = explode(':', $fields['_qf_default']);
// now we have all selected amount in hand.
$totalAmount = array_sum($selectedAmounts);
if ($totalAmount < 0) {
$error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
}
} else {
if ($allowNoneSelection) {
if (empty($noneSelectedPriceFields)) {
$error['_qf_default'] = ts('Please select at least one option from price set.');
}
} else {
$error['_qf_default'] = ts('Please select at least one option from price set.');
}
}
}
示例4: submit
/**
* Submit function.
*
* This is the guts of the postProcess made also accessible to the test suite.
*
* @param array $params
* Submitted values.
*/
public function submit($params)
{
//carry campaign from profile.
if (array_key_exists('contribution_campaign_id', $params)) {
$params['campaign_id'] = $params['contribution_campaign_id'];
}
$params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency;
$is_quick_config = 0;
if (!empty($params['priceSetId'])) {
$is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
if ($is_quick_config) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $params['priceSetId'];
$priceField->orderBy('weight');
$priceField->find();
$priceOptions = array();
while ($priceField->fetch()) {
CRM_Price_BAO_PriceFieldValue::getValues($priceField->id, $priceOptions);
if (($selectedPriceOptionID = CRM_Utils_Array::value("price_{$priceField->id}", $params)) != FALSE && $selectedPriceOptionID > 0) {
switch ($priceField->name) {
case 'membership_amount':
$this->_params['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array::value('membership_type_id', $priceOptions[$selectedPriceOptionID]);
$this->set('selectMembership', $params['selectMembership']);
case 'contribution_amount':
$params['amount'] = $selectedPriceOptionID;
if ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount' && CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) == 0) {
$this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
}
$this->_values[$selectedPriceOptionID]['value'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['label'] = CRM_Utils_Array::value('label', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['amount_id'] = CRM_Utils_Array::value('id', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['weight'] = CRM_Utils_Array::value('weight', $priceOptions[$selectedPriceOptionID]);
break;
case 'other_amount':
$params['amount_other'] = $selectedPriceOptionID;
break;
}
}
}
}
}
if (!empty($this->_ccid) && !empty($this->_pendingAmount)) {
$params['amount'] = $this->_pendingAmount;
} else {
// from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
$params['amount'] = self::computeAmount($params, $this->_values);
}
$params['separate_amount'] = $params['amount'];
$memFee = NULL;
if (!empty($params['selectMembership'])) {
if (empty($this->_membershipTypeValues)) {
$this->_membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, (array) $params['selectMembership']);
}
$membershipTypeValues = $this->_membershipTypeValues[$params['selectMembership']];
$memFee = $membershipTypeValues['minimum_fee'];
if (!$params['amount'] && !$this->_separateMembershipPayment) {
$params['amount'] = $memFee ? $memFee : 0;
}
}
//If the membership & contribution is used in contribution page & not separate payment
$fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
$proceFieldAmount = 0;
if (property_exists($this, '_separateMembershipPayment') && $this->_separateMembershipPayment == 0) {
$is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
if ($is_quick_config) {
foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) {
if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
$fieldId = $fieldVal['id'];
$fieldOption = $params['price_' . $fieldId];
$proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
$memPresent = TRUE;
} else {
if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
$fieldId = $fieldVal['id'];
if ($fieldVal['name'] == 'other_amount') {
$proceFieldAmount += $this->_submitValues['price_' . $fieldId];
} elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues['price_' . $fieldId] > 0) {
$proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
}
unset($params['price_' . $fieldId]);
break;
}
}
}
}
}
if (!isset($params['amount_other'])) {
$this->set('amount_level', CRM_Utils_Array::value('amount_level', $params));
}
if (!empty($this->_ccid)) {
$this->set('lineItem', $this->_lineItem);
} elseif ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) {
//.........这里部分代码省略.........
示例5: calculateRecurLineItems
/**
* Calculate line items for the relevant recurring calculation.
*
* @param int $recurId
* @param string $total_amount
* @param int $financial_type_id
*
* @return array
*/
public static function calculateRecurLineItems($recurId, $total_amount, $financial_type_id)
{
$originalContributionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id');
$lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($originalContributionID);
$lineSets = array();
if (count($lineItems) == 1) {
foreach ($lineItems as $index => $lineItem) {
if ($financial_type_id) {
// CRM-17718 allow for possibility of changed financial type ID having been set prior to calling this.
$lineItem['financial_type_id'] = $financial_type_id;
}
if ($lineItem['line_total'] != $total_amount) {
// We are dealing with a changed amount! Per CRM-16397 we can work out what to do with these
// if there is only one line item, and the UI should prevent this situation for those with more than one.
$lineItem['line_total'] = $total_amount;
$lineItem['unit_price'] = round($total_amount / $lineItem['qty'], 2);
}
$priceField = new CRM_Price_DAO_PriceField();
$priceField->id = $lineItem['price_field_id'];
$priceField->find(TRUE);
$lineSets[$priceField->price_set_id][] = $lineItem;
}
} elseif (count($lineItems) > 1) {
foreach ($lineItems as $index => $lineItem) {
$lineSets[$index][] = $lineItem;
}
}
return $lineSets;
}
示例6: setFormAmountFields
/**
* This function sets the fields.
*
* - $this->_params['amount_level']
* - $this->_params['selectMembership']
* And under certain circumstances sets
* $this->_params['amount'] = null;
*
* @param int $priceSetID
*/
public function setFormAmountFields($priceSetID)
{
$isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config');
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $priceSetID;
$priceField->orderBy('weight');
$priceField->find();
$paramWeDoNotUnderstand = NULL;
while ($priceField->fetch()) {
if ($priceField->name == "contribution_amount") {
$paramWeDoNotUnderstand = $priceField->id;
}
if ($isQuickConfig && !empty($this->_params["price_{$priceField->id}"])) {
if ($this->_values['fee'][$priceField->id]['html_type'] != 'Text') {
// @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
// function to get correct amount level consistently. Remove setting of the amount level in
// CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
// to cover all variants.
$this->_params['amount_level'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_params["price_{$priceField->id}"], 'label');
}
if ($priceField->name == "membership_amount") {
$this->_params['selectMembership'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_params["price_{$priceField->id}"], 'membership_type_id');
}
} elseif (CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) && !empty($this->_values['fee'][$priceField->id]) && $this->_values['fee'][$priceField->id]['name'] == "other_amount" && CRM_Utils_Array::value("price_{$paramWeDoNotUnderstand}", $this->_params) < 1 && empty($this->_params["price_{$priceField->id}"])) {
$this->_params['amount'] = NULL;
}
// Fix for CRM-14375 - If we are using separate payments and "no
// thank you" is selected for the additional contribution, set
// contribution amount to be null, so that it will not show
// contribution amount same as membership amount.
//@todo - merge with section above
if ($this->_membershipBlock['is_separate_payment'] && !empty($this->_values['fee'][$priceField->id]) && CRM_Utils_Array::value('name', $this->_values['fee'][$priceField->id]) == 'contribution_amount' && CRM_Utils_Array::value("price_{$priceField->id}", $this->_params) == '-1') {
$this->_params['amount'] = NULL;
}
}
}
示例7: formRule
/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
*
* @param $files
* @param CRM_Core_Form $form
*
* @return array
* if errors then list of errors to be posted back to the form,
* true otherwise
*/
public static function formRule($fields, $files, $form)
{
// all option fields are of type "money"
$errors = array();
/** Check the option values entered
* Appropriate values are required for the selected datatype
* Incomplete row checking is also required.
*/
if (($form->_action & CRM_Core_Action::ADD || $form->_action & CRM_Core_Action::UPDATE) && $fields['html_type'] == 'Text' && $fields['price'] == NULL) {
$errors['price'] = ts('Price is a required field');
}
if (($form->_action & CRM_Core_Action::ADD || $form->_action & CRM_Core_Action::UPDATE) && $fields['html_type'] == 'Text' && $fields['financial_type_id'] == '') {
$errors['financial_type_id'] = ts('Financial Type is a required field');
}
//avoid the same price field label in Within PriceSet
$priceFieldLabel = new CRM_Price_DAO_PriceField();
$priceFieldLabel->label = $fields['label'];
$priceFieldLabel->price_set_id = $form->_sid;
$dupeLabel = FALSE;
if ($priceFieldLabel->find(TRUE) && $form->_fid != $priceFieldLabel->id) {
$dupeLabel = TRUE;
}
if ($dupeLabel) {
$errors['label'] = ts('Name already exists in Database.');
}
if (is_numeric(CRM_Utils_Array::value('count', $fields)) && CRM_Utils_Array::value('count', $fields) == 0 && CRM_Utils_Array::value('html_type', $fields) == 'Text') {
$errors['count'] = ts('Participant Count must be greater than zero.');
}
if ($form->_action & CRM_Core_Action::ADD) {
if ($fields['html_type'] != 'Text') {
$countemptyrows = 0;
$_flagOption = $_rowError = 0;
$_showHide = new CRM_Core_ShowHideBlocks('', '');
for ($index = 1; $index <= self::NUM_OPTION; $index++) {
$noLabel = $noAmount = $noWeight = 1;
if (!empty($fields['option_label'][$index])) {
$noLabel = 0;
$duplicateIndex = CRM_Utils_Array::key($fields['option_label'][$index], $fields['option_label']);
if (!($duplicateIndex === FALSE) && !($duplicateIndex == $index)) {
$errors["option_label[{$index}]"] = ts('Duplicate label value');
$_flagOption = 1;
}
}
if ($form->_useForMember) {
if (!empty($fields['membership_type_id'][$index])) {
$memTypesIDS[] = $fields['membership_type_id'][$index];
}
}
// allow for 0 value.
if (!empty($fields['option_amount'][$index]) || strlen($fields['option_amount'][$index]) > 0) {
$noAmount = 0;
}
if (!empty($fields['option_weight'][$index])) {
$noWeight = 0;
$duplicateIndex = CRM_Utils_Array::key($fields['option_weight'][$index], $fields['option_weight']);
if (!($duplicateIndex === FALSE) && !($duplicateIndex == $index)) {
$errors["option_weight[{$index}]"] = ts('Duplicate weight value');
$_flagOption = 1;
}
}
if (!$noLabel && !$noAmount && !empty($fields['option_financial_type_id']) && $fields['option_financial_type_id'][$index] == '' && $fields['html_type'] != 'Text') {
$errors["option_financial_type_id[{$index}]"] = ts('Financial Type is a Required field.');
}
if ($noLabel && !$noAmount) {
$errors["option_label[{$index}]"] = ts('Label cannot be empty.');
$_flagOption = 1;
}
if (!$noLabel && $noAmount) {
$errors["option_amount[{$index}]"] = ts('Amount cannot be empty.');
$_flagOption = 1;
}
if ($noLabel && $noAmount) {
$countemptyrows++;
$_emptyRow = 1;
} elseif (!empty($fields['option_max_value'][$index]) && !empty($fields['option_count'][$index]) && $fields['option_count'][$index] > $fields['option_max_value'][$index]) {
$errors["option_max_value[{$index}]"] = ts('Participant count can not be greater than max participants.');
$_flagOption = 1;
}
$showBlocks = 'optionField_' . $index;
if ($_flagOption) {
$_showHide->addShow($showBlocks);
$_rowError = 1;
}
if (!empty($_emptyRow)) {
$_showHide->addHide($showBlocks);
} else {
$_showHide->addShow($showBlocks);
//.........这里部分代码省略.........
示例8: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
$config = CRM_Core_Config::singleton();
parent::preProcess();
// lineItem isn't set until Register postProcess
$this->_lineItem = $this->get('lineItem');
$this->_paymentProcessor = $this->get('paymentProcessor');
if ($this->_contributeMode == 'express') {
// rfp == redirect from paypal
$rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET');
if ($rfp) {
$payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
$expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
$this->_params['payer'] = $expressParams['payer'];
$this->_params['payer_id'] = $expressParams['payer_id'];
$this->_params['payer_status'] = $expressParams['payer_status'];
CRM_Core_Payment_Form::mapParams($this->_bltID, $expressParams, $this->_params, FALSE);
// fix state and country id if present
if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"]) && $this->_params["billing_state_province_id-{$this->_bltID}"]) {
$this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
}
if (!empty($this->_params["billing_country_id-{$this->_bltID}"]) && $this->_params["billing_country_id-{$this->_bltID}"]) {
$this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
}
// set a few other parameters for PayPal
$this->_params['token'] = $this->get('token');
$this->_params['amount'] = $this->get('amount');
if (!empty($this->_membershipBlock)) {
$this->_params['selectMembership'] = $this->get('selectMembership');
}
// we use this here to incorporate any changes made by folks in hooks
$this->_params['currencyID'] = $config->defaultCurrency;
$this->_params['payment_action'] = 'Sale';
// also merge all the other values from the profile fields
$values = $this->controller->exportValues('Main');
$skipFields = array('amount', 'amount_other', "billing_street_address-{$this->_bltID}", "billing_city-{$this->_bltID}", "billing_state_province_id-{$this->_bltID}", "billing_postal_code-{$this->_bltID}", "billing_country_id-{$this->_bltID}");
foreach ($values as $name => $value) {
// skip amount field
if (!in_array($name, $skipFields)) {
$this->_params[$name] = $value;
}
}
$this->set('getExpressCheckoutDetails', $this->_params);
} else {
$this->_params = $this->get('getExpressCheckoutDetails');
}
} else {
$this->_params = $this->controller->exportValues('Main');
if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) {
$this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
}
if (!empty($this->_params["billing_country_id-{$this->_bltID}"])) {
$this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
}
if (isset($this->_params['credit_card_exp_date'])) {
$this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
$this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
}
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $this->get('amount');
$this->_useForMember = $this->get('useForMember');
if (isset($this->_params['amount'])) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $this->_params['priceSetId'];
$priceField->orderBy('weight');
$priceField->find();
$contriPriceId = NULL;
$isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config');
while ($priceField->fetch()) {
if ($priceField->name == "contribution_amount") {
$contriPriceId = $priceField->id;
}
if ($isQuickConfig && !empty($this->_params["price_{$priceField->id}"])) {
if ($this->_values['fee'][$priceField->id]['html_type'] != 'Text') {
$this->_params['amount_level'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_params["price_{$priceField->id}"], 'label');
}
if ($priceField->name == "membership_amount") {
$this->_params['selectMembership'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_params["price_{$priceField->id}"], 'membership_type_id');
}
} elseif (CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) && !empty($this->_values['fee'][$priceField->id]) && $this->_values['fee'][$priceField->id]['name'] == "other_amount" && CRM_Utils_Array::value("price_{$contriPriceId}", $this->_params) < 1 && empty($this->_params["price_{$priceField->id}"])) {
$this->_params['amount'] = null;
}
}
}
$this->_params['currencyID'] = $config->defaultCurrency;
$this->_params['payment_action'] = 'Sale';
}
$this->_params['is_pay_later'] = $this->get('is_pay_later');
$this->assign('is_pay_later', $this->_params['is_pay_later']);
if ($this->_params['is_pay_later']) {
$this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
}
// if onbehalf-of-organization
if (!empty($this->_params['hidden_onbehalf_profile'])) {
//.........这里部分代码省略.........
示例9: upgrade_3_3_beta1
/**
* @param $rev
*/
public function upgrade_3_3_beta1($rev)
{
$upgrade = new CRM_Upgrade_Form();
$upgrade->processSQL($rev);
// CRM-6902
// Add column price_field_value_id in civicrm_line_item.
// Do not drop option_group_id column now since we need it to
// update line items.
$updateLineItem1 = "ALTER TABLE civicrm_line_item ADD COLUMN price_field_value_id int(10) unsigned default NULL;";
CRM_Core_DAO::executeQuery($updateLineItem1);
$priceFieldDAO = new CRM_Price_DAO_PriceField();
$priceFieldDAO->find();
$ids = array();
while ($priceFieldDAO->fetch()) {
$opGroupDAO = new CRM_Core_DAO_OptionGroup();
$opGroupDAO->name = 'civicrm_price_field.amount.' . $priceFieldDAO->id;
if (!$opGroupDAO->find(TRUE)) {
$opGroupDAO->free();
continue;
}
$opValueDAO = new CRM_Core_DAO_OptionValue();
$opValueDAO->option_group_id = $opGroupDAO->id;
$opValueDAO->find();
while ($opValueDAO->fetch()) {
// FIX ME: not migrating description(?), there will
// be a field description for each option.
$fieldValue = array('price_field_id' => $priceFieldDAO->id, 'label' => $opValueDAO->label, 'name' => CRM_Utils_String::munge($opValueDAO->label, '_', 64), 'amount' => $opValueDAO->name, 'weight' => $opValueDAO->weight, 'is_default' => $opValueDAO->is_default, 'is_active' => $opValueDAO->is_active);
if ($priceFieldDAO->count) {
// Migrate Participant Counts on option level.
// count of each option will be the same
// as earlier field count.
$fieldValue['count'] = $priceFieldDAO->count;
}
$fieldValueDAO = CRM_Price_BAO_PriceFieldValue::add($fieldValue, $ids);
$lineItemDAO = new CRM_Price_DAO_LineItem();
$lineItemDAO->option_group_id = $opGroupDAO->id;
$lineItemDAO->label = $opValueDAO->label;
$lineItemDAO->unit_price = $opValueDAO->name;
$labelFound = $priceFound = FALSE;
// check with label and amount
if (!$lineItemDAO->find(TRUE)) {
$lineItemDAO->free();
$lineItemDAO = new CRM_Price_DAO_LineItem();
$lineItemDAO->option_group_id = $opGroupDAO->id;
$lineItemDAO->label = $opValueDAO->label;
// check with label only
if ($lineItemDAO->find(TRUE)) {
$labelFound = TRUE;
}
} else {
$labelFound = TRUE;
$priceFound = TRUE;
}
$lineItemDAO->free();
// update civicrm_line_item for price_field_value_id.
// Used query to avoid line by line update.
if ($labelFound || $priceFound) {
$lineItemParams = array(1 => array($fieldValueDAO->id, 'Integer'), 2 => array($opValueDAO->label, 'String'));
$updateLineItems = "UPDATE civicrm_line_item SET price_field_value_id = %1 WHERE label = %2";
if ($priceFound) {
$lineItemParams[3] = array($opValueDAO->name, 'Float');
$updateLineItems .= " AND unit_price = %3";
}
CRM_Core_DAO::executeQuery($updateLineItems, $lineItemParams);
}
}
$opGroupDAO->delete();
$opValueDAO->free();
$opGroupDAO->free();
}
$priceFieldDAO->free();
// Now drop option_group_id column from civicrm_line_item
$updateLineItem2 = "ALTER TABLE civicrm_line_item DROP option_group_id,\n ADD CONSTRAINT `FK_civicrm_price_field_value_id` FOREIGN KEY (price_field_value_id) REFERENCES civicrm_price_field_value(id) ON DELETE SET NULL;";
CRM_Core_DAO::executeQuery($updateLineItem2, array(), TRUE, NULL, FALSE, FALSE);
$updatePriceField = "ALTER TABLE civicrm_price_field DROP count";
CRM_Core_DAO::executeQuery($updatePriceField, array(), TRUE, NULL, FALSE, FALSE);
// as the table 'civicrm_price_field' is localised and column 'count' is dropped
// after the views are rebuild, we need to rebuild views to avoid invalid refrence of table.
if ($upgrade->multilingual) {
CRM_Core_I18n_Schema::rebuildMultilingualSchema($upgrade->locales, $rev);
}
}
示例10: getFieldIds
/**
* Get field ids of a price set.
*
* @param int $id
* Price Set id.
*
* @return array
* Array of the field ids
*
*/
public static function getFieldIds($id)
{
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $id;
$priceField->find();
while ($priceField->fetch()) {
$var[] = $priceField->id;
}
return $var;
}
示例11: postProcess
/**
* Process the form submission.
*/
public function postProcess()
{
$config = CRM_Core_Config::singleton();
// we first reset the confirm page so it accepts new values
$this->controller->resetPage('Confirm');
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
//carry campaign from profile.
if (array_key_exists('contribution_campaign_id', $params)) {
$params['campaign_id'] = $params['contribution_campaign_id'];
}
if (!empty($params['onbehalfof_id'])) {
$params['organization_id'] = $params['onbehalfof_id'];
}
$params['currencyID'] = $config->defaultCurrency;
if (!empty($params['priceSetId'])) {
$is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
if ($is_quick_config) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $params['priceSetId'];
$priceField->orderBy('weight');
$priceField->find();
$priceOptions = array();
while ($priceField->fetch()) {
CRM_Price_BAO_PriceFieldValue::getValues($priceField->id, $priceOptions);
if ($selectedPriceOptionID = CRM_Utils_Array::value("price_{$priceField->id}", $params)) {
switch ($priceField->name) {
case 'membership_amount':
$this->_params['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array::value('membership_type_id', $priceOptions[$selectedPriceOptionID]);
$this->set('selectMembership', $params['selectMembership']);
if (CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) == 0) {
$this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
}
break;
case 'contribution_amount':
$params['amount'] = $selectedPriceOptionID;
$this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['value'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['label'] = CRM_Utils_Array::value('label', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['amount_id'] = CRM_Utils_Array::value('id', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['weight'] = CRM_Utils_Array::value('weight', $priceOptions[$selectedPriceOptionID]);
break;
case 'other_amount':
$params['amount_other'] = $selectedPriceOptionID;
break;
}
}
}
}
}
if ($this->_values['is_pay_later'] && empty($this->_paymentProcessor) && !array_key_exists('hidden_processor', $params) || !empty($params['payment_processor_id']) && $params['payment_processor_id'] == 0) {
$params['is_pay_later'] = 1;
} else {
$params['is_pay_later'] = 0;
}
$this->set('is_pay_later', $params['is_pay_later']);
// assign pay later stuff
$this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
$this->assign('is_pay_later', $params['is_pay_later']);
if ($params['is_pay_later']) {
$this->assign('pay_later_text', $this->_values['pay_later_text']);
$this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
}
// from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
$params['amount'] = self::computeAmount($params, $this->_values);
$params['separate_amount'] = $params['amount'];
$memFee = NULL;
if (!empty($params['selectMembership'])) {
if (!empty($this->_membershipTypeValues)) {
$membershipTypeValues = $this->_membershipTypeValues[$params['selectMembership']];
} else {
$membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, $params['selectMembership']);
}
$memFee = $membershipTypeValues['minimum_fee'];
if (!$params['amount'] && !$this->_separateMembershipPayment) {
$params['amount'] = $memFee ? $memFee : 0;
}
}
//If the membership & contribution is used in contribution page & not separate payment
$fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
$proceFieldAmount = 0;
if (property_exists($this, '_separateMembershipPayment') && $this->_separateMembershipPayment == 0) {
$is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
if ($is_quick_config) {
foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) {
if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
$fieldId = $fieldVal['id'];
$fieldOption = $params['price_' . $fieldId];
$proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
$memPresent = TRUE;
} else {
if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
$fieldId = $fieldVal['id'];
if ($fieldVal['name'] == 'other_amount') {
$proceFieldAmount += $this->_submitValues['price_' . $fieldId];
} elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues['price_' . $fieldId] > 0) {
$proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
//.........这里部分代码省略.........
示例12: addRecurLineItems
/**
* Add line items for recurring contribution.
*
* @param int $recurId
* @param $contribution
*
* @return array
*/
public static function addRecurLineItems($recurId, $contribution)
{
$lineSets = array();
$originalContributionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id');
$lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($originalContributionID);
if (count($lineItems) == 1) {
foreach ($lineItems as $index => $lineItem) {
if (isset($contribution->financial_type_id)) {
// CRM-17718 allow for possibility of changed financial type ID having been set prior to calling this.
$lineItems[$index]['financial_type_id'] = $contribution->financial_type_id;
}
if ($lineItem['line_total'] != $contribution->total_amount) {
// We are dealing with a changed amount! Per CRM-16397 we can work out what to do with these
// if there is only one line item, and the UI should prevent this situation for those with more than one.
$lineItems[$index]['line_total'] = $contribution->total_amount;
$lineItems[$index]['unit_price'] = round($contribution->total_amount / $lineItems[$index]['qty'], 2);
}
}
}
if (!empty($lineItems)) {
foreach ($lineItems as $key => $value) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->id = $value['price_field_id'];
$priceField->find(TRUE);
$lineSets[$priceField->price_set_id][] = $value;
if ($value['entity_table'] == 'civicrm_membership') {
try {
civicrm_api3('membership_payment', 'create', array('membership_id' => $value['entity_id'], 'contribution_id' => $contribution->id));
} catch (CiviCRM_API3_Exception $e) {
// we are catching & ignoring errors as an extra precaution since lost IPNs may be more serious that lost membership_payment data
// this fn is unit-tested so risk of changes elsewhere breaking it are otherwise mitigated
}
}
}
} else {
CRM_Price_BAO_LineItem::processPriceSet($contribution->id, $lineSets, $contribution);
}
return $lineSets;
}
示例13: addrecurLineItems
function addrecurLineItems($recurId, $contributionId, &$input)
{
$lineSets = $lineItems = array();
//Get the first contribution id with recur id
if ($recurId) {
$contriID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id');
$lineItems = CRM_Price_BAO_LineItem::getLineItems($contriID, 'contribution');
if (!empty($lineItems)) {
foreach ($lineItems as $key => $value) {
$pricesetID = new CRM_Price_DAO_PriceField();
$pricesetID->id = $value['price_field_id'];
$pricesetID->find(TRUE);
$lineSets[$pricesetID->price_set_id][] = $value;
}
}
if (!empty($input)) {
$input['line_item'] = $lineSets;
} else {
CRM_Price_BAO_LineItem::processPriceSet($contributionId, $lineSets);
}
}
}
示例14: postProcess
/**
* Process the form submission.
*/
public function postProcess()
{
$config = CRM_Core_Config::singleton();
// we first reset the confirm page so it accepts new values
$this->controller->resetPage('Confirm');
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
//carry campaign from profile.
if (array_key_exists('contribution_campaign_id', $params)) {
$params['campaign_id'] = $params['contribution_campaign_id'];
}
if (!empty($params['onbehalfof_id'])) {
$params['organization_id'] = $params['onbehalfof_id'];
}
$params['currencyID'] = $config->defaultCurrency;
if (!empty($params['priceSetId'])) {
$is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
if ($is_quick_config) {
$priceField = new CRM_Price_DAO_PriceField();
$priceField->price_set_id = $params['priceSetId'];
$priceField->orderBy('weight');
$priceField->find();
$priceOptions = array();
while ($priceField->fetch()) {
CRM_Price_BAO_PriceFieldValue::getValues($priceField->id, $priceOptions);
if ($selectedPriceOptionID = CRM_Utils_Array::value("price_{$priceField->id}", $params)) {
switch ($priceField->name) {
case 'membership_amount':
$this->_params['selectMembership'] = $params['selectMembership'] = CRM_Utils_Array::value('membership_type_id', $priceOptions[$selectedPriceOptionID]);
$this->set('selectMembership', $params['selectMembership']);
if (CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) == 0) {
$this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
}
break;
case 'contribution_amount':
$params['amount'] = $selectedPriceOptionID;
$this->_values['amount'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['value'] = CRM_Utils_Array::value('amount', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['label'] = CRM_Utils_Array::value('label', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['amount_id'] = CRM_Utils_Array::value('id', $priceOptions[$selectedPriceOptionID]);
$this->_values[$selectedPriceOptionID]['weight'] = CRM_Utils_Array::value('weight', $priceOptions[$selectedPriceOptionID]);
break;
case 'other_amount':
$params['amount_other'] = $selectedPriceOptionID;
break;
}
}
}
}
}
if ($this->_values['is_pay_later'] && empty($this->_paymentProcessor) && !array_key_exists('hidden_processor', $params) || !empty($params['payment_processor_id']) && $params['payment_processor_id'] == 0) {
$params['is_pay_later'] = 1;
} else {
$params['is_pay_later'] = 0;
}
$this->set('is_pay_later', $params['is_pay_later']);
// assign pay later stuff
$this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
$this->assign('is_pay_later', $params['is_pay_later']);
if ($params['is_pay_later']) {
$this->assign('pay_later_text', $this->_values['pay_later_text']);
$this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
}
// from here on down, $params['amount'] holds a monetary value (or null) rather than an option ID
$params['amount'] = self::computeAmount($params, $this->_values);
$params['separate_amount'] = $params['amount'];
$memFee = NULL;
if (!empty($params['selectMembership'])) {
if (!empty($this->_membershipTypeValues)) {
$membershipTypeValues = $this->_membershipTypeValues[$params['selectMembership']];
} else {
$membershipTypeValues = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, (array) $params['selectMembership']);
}
$memFee = $membershipTypeValues['minimum_fee'];
if (!$params['amount'] && !$this->_separateMembershipPayment) {
$params['amount'] = $memFee ? $memFee : 0;
}
}
//If the membership & contribution is used in contribution page & not separate payment
$fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL;
$proceFieldAmount = 0;
if (property_exists($this, '_separateMembershipPayment') && $this->_separateMembershipPayment == 0) {
$is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
if ($is_quick_config) {
foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) {
if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
$fieldId = $fieldVal['id'];
$fieldOption = $params['price_' . $fieldId];
$proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
$memPresent = TRUE;
} else {
if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
$fieldId = $fieldVal['id'];
if ($fieldVal['name'] == 'other_amount') {
$proceFieldAmount += $this->_submitValues['price_' . $fieldId];
} elseif ($fieldVal['name'] == 'contribution_amount' && $this->_submitValues['price_' . $fieldId] > 0) {
$proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
//.........这里部分代码省略.........
示例15: addDisplayEnums
/**
* adds $value['foo_display'] for each $value['foo'] enum from civicrm_price_field
*
* @param array $values (reference) the array up for enhancing
* @return void
*/
static function addDisplayEnums(&$values)
{
$enumFields =& CRM_Price_DAO_PriceField::getEnums();
foreach ($enumFields as $enum) {
if (isset($values[$enum])) {
$values[$enum . '_display'] = CRM_Price_DAO_PriceField::tsEnum($enum, $values[$enum]);
}
}
}