本文整理汇总了PHP中CRM_Price_BAO_PriceField::getOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Price_BAO_PriceField::getOptions方法的具体用法?PHP CRM_Price_BAO_PriceField::getOptions怎么用?PHP CRM_Price_BAO_PriceField::getOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Price_BAO_PriceField
的用法示例。
在下文中一共展示了CRM_Price_BAO_PriceField::getOptions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* Insert/update a new entry in the database.
*
* @param array $params
* (reference), array $ids.
*
* @param $ids
*
* @return CRM_Price_DAO_PriceFieldValue
*/
public static function add(&$params, $ids = array())
{
$fieldValueBAO = new CRM_Price_BAO_PriceFieldValue();
$fieldValueBAO->copyValues($params);
if ($id = CRM_Utils_Array::value('id', $ids)) {
$fieldValueBAO->id = $id;
}
if (!empty($params['is_default'])) {
$query = 'UPDATE civicrm_price_field_value SET is_default = 0 WHERE price_field_id = %1';
$p = array(1 => array($params['price_field_id'], 'Integer'));
CRM_Core_DAO::executeQuery($query, $p);
}
$fieldValueBAO->save();
// Reset the cached values in this function.
CRM_Price_BAO_PriceField::getOptions(CRM_Utils_Array::value('price_field_id', $params), FALSE, TRUE);
return $fieldValueBAO;
}
示例2: addQuickFormElement
/**
* This function for building custom fields
*
* @param CRM_Core_Form $qf form object (reference)
* @param string $elementName name of the custom field
* @param $fieldId
* @param boolean $inactiveNeeded
* @param boolean $useRequired true if required else false
* @param string $label label for custom field
*
* @param null $fieldOptions
* @param array $feezeOptions
*
* @return null
* @internal param bool $search true if used for search else false
* @access public
* @static
*/
public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = TRUE, $label = NULL, $fieldOptions = NULL, $feezeOptions = array())
{
$field = new CRM_Price_DAO_PriceField();
$field->id = $fieldId;
if (!$field->find(TRUE)) {
/* FIXME: failure! */
return NULL;
}
$is_pay_later = 0;
if (isset($qf->_mode) && empty($qf->_mode)) {
$is_pay_later = 1;
} elseif (isset($qf->_values)) {
$is_pay_later = CRM_Utils_Array::value('is_pay_later', $qf->_values);
}
$otherAmount = $qf->get('values');
$config = CRM_Core_Config::singleton();
$currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name');
$qf->assign('currencySymbol', $currencySymbol);
// get currency name for price field and option attributes
$currencyName = $config->defaultCurrency;
if (!isset($label)) {
$label = !empty($qf->_membershipBlock) && $field->name == 'contribution_amount' ? ts('Additional Contribution') : $field->label;
}
if ($field->name == 'contribution_amount') {
$qf->_contributionAmount = 1;
}
if (isset($qf->_online) && $qf->_online) {
$useRequired = FALSE;
}
$customOption = $fieldOptions;
if (!is_array($customOption)) {
$customOption = CRM_Price_BAO_PriceField::getOptions($field->id, $inactiveNeeded);
}
//use value field.
$valueFieldName = 'amount';
$seperator = '|';
switch ($field->html_type) {
case 'Text':
$optionKey = key($customOption);
$count = CRM_Utils_Array::value('count', $customOption[$optionKey], '');
$max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], '');
$priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value));
$extra = array();
if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
foreach ($fieldOptions as &$fieldOption) {
if ($fieldOption['name'] == 'other_amount') {
$fieldOption['label'] = $fieldOption['label'] . ' ' . $currencySymbol;
}
}
$qf->assign('priceset', $elementName);
$extra = array('onclick' => 'useAmountOther();');
}
if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) {
$useRequired = 0;
} elseif (!empty($fieldOptions[$optionKey]['label'])) {
//check for label.
$label = $fieldOptions[$optionKey]['label'];
}
$element =& $qf->add('text', $elementName, $label, array_merge($extra, array('price' => json_encode(array($optionKey, $priceVal)), 'size' => '4')), $useRequired && $field->is_required);
if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
}
// CRM-6902
if (in_array($optionKey, $feezeOptions)) {
$element->freeze();
}
//CRM-10117
if (!empty($qf->_quickConfig)) {
$message = ts('Please enter a valid amount.');
$type = 'money';
} else {
$message = ts('%1 must be an integer (whole number).', array(1 => $label));
$type = 'positiveInteger';
}
// integers will have numeric rule applied to them.
$qf->addRule($elementName, $message, $type);
break;
case 'Radio':
$choice = array();
if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
$qf->assign('contriPriceset', $elementName);
}
//.........这里部分代码省略.........
示例3: getSetDetail
/**
* Get price set details.
*
* An array containing price set details (including price fields) is returned
*
* @param int $setID
* Price Set ID.
* @param bool $required
* Appears to have no effect based on reading the code.
* @param bool $validOnly
* Should only fields where today's date falls within the valid range be returned?
*
* @return array
* Array consisting of field details
*/
public static function getSetDetail($setID, $required = TRUE, $validOnly = FALSE)
{
// create a new tree
$setTree = array();
$priceFields = array('id', 'name', 'label', 'html_type', 'is_enter_qty', 'help_pre', 'help_post', 'weight', 'is_display_amounts', 'options_per_line', 'is_active', 'active_on', 'expire_on', 'javascript', 'visibility_id', 'is_required');
if ($required == TRUE) {
$priceFields[] = 'is_required';
}
// create select
$select = 'SELECT ' . implode(',', $priceFields);
$from = ' FROM civicrm_price_field';
$params = array();
$params[1] = array($setID, 'Integer');
$where = '
WHERE price_set_id = %1
AND is_active = 1
';
$dateSelect = '';
if ($validOnly) {
$currentTime = date('YmdHis');
$dateSelect = "\nAND ( active_on IS NULL OR active_on <= {$currentTime} )\nAND ( expire_on IS NULL OR expire_on >= {$currentTime} )\n";
}
$orderBy = ' ORDER BY weight';
$sql = $select . $from . $where . $dateSelect . $orderBy;
$dao = CRM_Core_DAO::executeQuery($sql, $params);
$visibility = CRM_Core_PseudoConstant::visibility('name');
while ($dao->fetch()) {
$fieldID = $dao->id;
$setTree[$setID]['fields'][$fieldID] = array();
$setTree[$setID]['fields'][$fieldID]['id'] = $fieldID;
foreach ($priceFields as $field) {
if ($field == 'id' || is_null($dao->{$field})) {
continue;
}
if ($field == 'visibility_id') {
$setTree[$setID]['fields'][$fieldID]['visibility'] = $visibility[$dao->{$field}];
}
$setTree[$setID]['fields'][$fieldID][$field] = $dao->{$field};
}
$setTree[$setID]['fields'][$fieldID]['options'] = CRM_Price_BAO_PriceField::getOptions($fieldID, FALSE);
}
// also get the pre and post help from this price set
$sql = "\nSELECT extends, financial_type_id, help_pre, help_post, is_quick_config\nFROM civicrm_price_set\nWHERE id = %1";
$dao = CRM_Core_DAO::executeQuery($sql, $params);
if ($dao->fetch()) {
$setTree[$setID]['extends'] = $dao->extends;
$setTree[$setID]['financial_type_id'] = $dao->financial_type_id;
$setTree[$setID]['help_pre'] = $dao->help_pre;
$setTree[$setID]['help_post'] = $dao->help_post;
$setTree[$setID]['is_quick_config'] = $dao->is_quick_config;
}
return $setTree;
}
示例4: addQuickFormElement
/**
* This function for building custom fields.
*
* @param CRM_Core_Form $qf
* Form object (reference).
* @param string $elementName
* Name of the custom field.
* @param int $fieldId
* @param bool $inactiveNeeded
* @param bool $useRequired
* True if required else false.
* @param string $label
* Label for custom field.
*
* @param null $fieldOptions
* @param array $freezeOptions
*
* @return null
*/
public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = TRUE, $label = NULL, $fieldOptions = NULL, $freezeOptions = array())
{
$field = new CRM_Price_DAO_PriceField();
$field->id = $fieldId;
if (!$field->find(TRUE)) {
/* FIXME: failure! */
return NULL;
}
$is_pay_later = 0;
if (isset($qf->_mode) && empty($qf->_mode)) {
$is_pay_later = 1;
} elseif (isset($qf->_values)) {
$is_pay_later = CRM_Utils_Array::value('is_pay_later', $qf->_values);
}
$otherAmount = $qf->get('values');
$config = CRM_Core_Config::singleton();
$currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name');
$qf->assign('currencySymbol', $currencySymbol);
// get currency name for price field and option attributes
$currencyName = $config->defaultCurrency;
if (!isset($label)) {
$label = !empty($qf->_membershipBlock) && $field->name == 'contribution_amount' ? ts('Additional Contribution') : $field->label;
}
if ($field->name == 'contribution_amount') {
$qf->_contributionAmount = 1;
}
if (isset($qf->_online) && $qf->_online) {
$useRequired = FALSE;
}
$customOption = $fieldOptions;
if (!is_array($customOption)) {
$customOption = CRM_Price_BAO_PriceField::getOptions($field->id, $inactiveNeeded);
}
//use value field.
$valueFieldName = 'amount';
$seperator = '|';
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
$displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings);
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
switch ($field->html_type) {
case 'Text':
$optionKey = key($customOption);
$count = CRM_Utils_Array::value('count', $customOption[$optionKey], '');
$max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], '');
$taxAmount = CRM_Utils_Array::value('tax_amount', $customOption[$optionKey]);
if (isset($taxAmount) && $displayOpt && $invoicing) {
$qf->assign('displayOpt', $displayOpt);
$qf->assign('taxTerm', $taxTerm);
$qf->assign('invoicing', $invoicing);
}
$priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName] + $taxAmount, $count, $max_value));
$extra = array();
if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) {
$useRequired = 0;
} elseif (!empty($fieldOptions[$optionKey]['label'])) {
//check for label.
$label = $fieldOptions[$optionKey]['label'];
if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount) && strtolower($fieldOptions[$optionKey]['name']) == 'other_amount') {
$label .= ' ' . $currencySymbol;
$qf->assign('priceset', $elementName);
$extra = array('onclick' => 'useAmountOther();');
}
}
$element =& $qf->add('text', $elementName, $label, array_merge($extra, array('price' => json_encode(array($optionKey, $priceVal)), 'size' => '4')), $useRequired && $field->is_required);
if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
}
// CRM-6902 - Add "max" option for a price set field
if (in_array($optionKey, $freezeOptions)) {
self::freezeIfEnabled($element, $fieldOptions[$optionKey]);
// CRM-14696 - Improve display for sold out price set options
$element->setLabel($label . ' <span class="sold-out-option">' . ts('Sold out') . '</span>');
}
//CRM-10117
if (!empty($qf->_quickConfig)) {
$message = ts('Please enter a valid amount.');
$type = 'money';
} else {
$message = ts('%1 must be a number (with or without decimal point).', array(1 => $label));
$type = 'numeric';
//.........这里部分代码省略.........