First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,912 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Business objects for managing price fields.
*
*/
class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField {
protected $_options;
/**
* List of visibility option ID's, of the form name => ID
*
* @var array
*/
private static $visibilityOptionsKeys;
/**
* Takes an associative array and creates a price field object.
*
* the function extract all the params it needs to initialize the create a
* price field object. the params array could contain additional unused name/value
* pairs
*
* @param array $params
* (reference) an assoc array of name/value pairs.
*
* @return CRM_Price_BAO_PriceField
*/
public static function add(&$params) {
$priceFieldBAO = new CRM_Price_BAO_PriceField();
$priceFieldBAO->copyValues($params);
if ($id = CRM_Utils_Array::value('id', $params)) {
$priceFieldBAO->id = $id;
}
$priceFieldBAO->save();
return $priceFieldBAO;
}
/**
* Takes an associative array and creates a price field object.
*
* This function is invoked from within the web form layer and also from the api layer
*
* @param array $params
* (reference) an assoc array of name/value pairs.
*
* @return CRM_Price_DAO_PriceField
* @throws \CRM_Core_Exception
*/
public static function create(&$params) {
if (empty($params['id']) && empty($params['name'])) {
$params['name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 242));
}
$transaction = new CRM_Core_Transaction();
$priceField = self::add($params);
if (is_a($priceField, 'CRM_Core_Error')) {
$transaction->rollback();
return $priceField;
}
if (!empty($params['id']) && empty($priceField->html_type)) {
$priceField->html_type = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['id'], 'html_type');
}
$optionsIds = array();
$maxIndex = CRM_Price_Form_Field::NUM_OPTION;
if ($priceField->html_type == 'Text') {
$maxIndex = 1;
$fieldOptions = civicrm_api3('price_field_value', 'get', array(
'price_field_id' => $priceField->id,
'sequential' => 1,
));
foreach ($fieldOptions['values'] as $option) {
$optionsIds['id'] = $option['id'];
// CRM-19741 If we are dealing with price fields that are Text only set the field value label to match
if (!empty($params['id']) && $priceField->label != $option['label']) {
$fieldValue = new CRM_Price_DAO_PriceFieldValue();
$fieldValue->label = $priceField->label;
$fieldValue->id = $option['id'];
$fieldValue->save();
}
}
}
$defaultArray = array();
//html type would be empty in update scenario not sure what would happen ...
if (!empty($params['html_type']) && $params['html_type'] == 'CheckBox' && isset($params['default_checkbox_option'])) {
$tempArray = array_keys($params['default_checkbox_option']);
foreach ($tempArray as $v) {
if ($params['option_amount'][$v]) {
$defaultArray[$v] = 1;
}
}
}
else {
if (!empty($params['default_option'])) {
$defaultArray[$params['default_option']] = 1;
}
}
for ($index = 1; $index <= $maxIndex; $index++) {
if (array_key_exists('option_amount', $params) &&
array_key_exists($index, $params['option_amount']) &&
(CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_label', $params)) || !empty($params['is_quick_config'])) &&
!CRM_Utils_System::isNull($params['option_amount'][$index])
) {
$options = array(
'price_field_id' => $priceField->id,
'label' => trim($params['option_label'][$index]),
'name' => CRM_Utils_String::munge($params['option_label'][$index], '_', 64),
'amount' => CRM_Utils_Rule::cleanMoney(trim($params['option_amount'][$index])),
'count' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_count', $params), NULL),
'max_value' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_max_value', $params), NULL),
'description' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_description', $params), NULL),
'membership_type_id' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('membership_type_id', $params), NULL),
'weight' => $params['option_weight'][$index],
'is_active' => 1,
'is_default' => CRM_Utils_Array::value($params['option_weight'][$index], $defaultArray) ? $defaultArray[$params['option_weight'][$index]] : 0,
'membership_num_terms' => NULL,
'non_deductible_amount' => CRM_Utils_Array::value('non_deductible_amount', $params),
'visibility_id' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_visibility_id', $params), self::getVisibilityOptionID('public')),
);
if ($options['membership_type_id']) {
$options['membership_num_terms'] = CRM_Utils_Array::value($index, CRM_Utils_Array::value('membership_num_terms', $params), 1);
$options['is_default'] = CRM_Utils_Array::value($params['membership_type_id'][$index], $defaultArray) ? $defaultArray[$params['membership_type_id'][$index]] : 0;
}
if (CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_financial_type_id', $params))) {
$options['financial_type_id'] = $params['option_financial_type_id'][$index];
}
elseif (!empty($params['financial_type_id'])) {
$options['financial_type_id'] = $params['financial_type_id'];
}
if ($opIds = CRM_Utils_Array::value('option_id', $params)) {
if ($opId = CRM_Utils_Array::value($index, $opIds)) {
$optionsIds['id'] = $opId;
}
else {
$optionsIds['id'] = NULL;
}
}
try {
CRM_Price_BAO_PriceFieldValue::create($options, $optionsIds);
}
catch (Exception $e) {
$transaction->rollback();
throw new CRM_Core_Exception($e->getMessage());
}
}
elseif (!empty($optionsIds) && !empty($optionsIds['id'])) {
$optionsLoad = civicrm_api3('price_field_value', 'get', array('id' => $optionsIds['id']));
$options = $optionsLoad['values'][$optionsIds['id']];
$options['is_active'] = CRM_Utils_Array::value('is_active', $params, 1);
try {
CRM_Price_BAO_PriceFieldValue::create($options, $optionsIds);
}
catch (Exception $e) {
$transaction->rollback();
throw new CRM_Core_Exception($e->getMessage());
}
}
}
$transaction->commit();
return $priceField;
}
/**
* Fetch object based on array of properties.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $defaults
* (reference ) an assoc array to hold the flattened values.
*
* @return CRM_Price_DAO_PriceField
*/
public static function retrieve(&$params, &$defaults) {
return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $params, $defaults);
}
/**
* Update the is_active flag in the db.
*
* @param int $id
* Id of the database record.
* @param bool $is_active
* Value we want to set the is_active field.
*
* @return Object
* DAO object on success, null otherwise.
*/
public static function setIsActive($id, $is_active) {
return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceField', $id, 'is_active', $is_active);
}
/**
* Freeze form if the event is full.
*
* @param $element
* @param $fieldOptions
*
* @return null
*/
public static function freezeIfEnabled(&$element, $fieldOptions) {
if (!empty($fieldOptions['is_full'])) {
$element->freeze();
}
return NULL;
}
/**
* Get the field title.
*
* @param int $id
* Id of field.
*
* @return string
* name
*
*/
public static function getTitle($id) {
return CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $id, 'label');
}
/**
* 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 . '&nbsp;<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';
}
// 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);
}
foreach ($customOption as $opId => $opt) {
$taxAmount = CRM_Utils_Array::value('tax_amount', $opt);
if ($field->is_display_amounts) {
$opt['label'] = !empty($opt['label']) ? $opt['label'] . '<span class="crm-price-amount-label-separator">&nbsp;-&nbsp;</span>' : '';
$preHelpText = $postHelpText = '';
if (isset($opt['help_pre'])) {
$preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span>: ';
}
if (isset($opt['help_post'])) {
$postHelpText = ': <span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
}
if (isset($taxAmount) && $invoicing) {
if ($displayOpt == 'Do_not_show') {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
}
elseif ($displayOpt == 'Inclusive') {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName] + $taxAmount) . '</span>';
$opt['label'] .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money::format($opt['tax_amount']) . ')</span>';
}
else {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
$opt['label'] .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
}
}
else {
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
}
$opt['label'] = $preHelpText . $opt['label'] . $postHelpText;
}
$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');
$priceVal = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
if (isset($opt['visibility_id'])) {
$visibility_id = $opt['visibility_id'];
}
else {
$visibility_id = self::getVisibilityOptionID('public');
}
$extra = array(
'price' => json_encode(array($elementName, $priceVal)),
'data-amount' => $opt[$valueFieldName],
'data-currency' => $currencyName,
'data-price-field-values' => json_encode($customOption),
'visibility' => $visibility_id,
);
if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') {
$extra += array('onclick' => 'clearAmountOther();');
}
elseif (!empty($qf->_quickConfig) && $field->name == 'membership_amount') {
$extra += array(
'onclick' => "return showHideAutoRenew({$opt['membership_type_id']});",
'membership-type' => $opt['membership_type_id'],
);
$qf->assign('membershipFieldID', $field->id);
}
$choice[$opId] = $qf->createElement('radio', NULL, '', $opt['label'], $opt['id'], $extra);
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($opId, $freezeOptions)) {
self::freezeIfEnabled($choice[$opId], $customOption[$opId]);
// CRM-14696 - Improve display for sold out price set options
$choice[$opId]->setText('<span class="sold-out-option">' . $choice[$opId]->getText() . '&nbsp;(' . ts('Sold out') . ')</span>');
}
}
if (!empty($qf->_membershipBlock) && $field->name == 'contribution_amount') {
$choice[] = $qf->createElement('radio', NULL, '', ts('No thank you'), '-1',
array(
'price' => json_encode(array($elementName, '0|0')),
'data-currency' => $currencyName,
'onclick' => 'clearAmountOther();',
)
);
}
if (!$field->is_required) {
// add "none" option
if (!empty($otherAmount['is_allow_other_amount']) && $field->name == 'contribution_amount') {
$none = ts('Other Amount');
}
elseif (!empty($qf->_membershipBlock) && empty($qf->_membershipBlock['is_required']) && $field->name == 'membership_amount') {
$none = ts('No thank you');
}
else {
$none = ts('- none -');
}
$choice[] = $qf->createElement('radio', NULL, '', $none, '0',
array('price' => json_encode(array($elementName, '0')))
);
}
$element = &$qf->addGroup($choice, $elementName, $label);
// make contribution field required for quick config when membership block is enabled
if (($field->name == 'membership_amount' || $field->name == 'contribution_amount')
&& !empty($qf->_membershipBlock) && !$field->is_required
) {
$useRequired = $field->is_required = TRUE;
}
if ($useRequired && $field->is_required) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
break;
case 'Select':
$selectOption = $allowedOptions = $priceVal = array();
foreach ($customOption as $opt) {
$taxAmount = CRM_Utils_Array::value('tax_amount', $opt);
$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');
if ($field->is_display_amounts) {
$opt['label'] .= '&nbsp;-&nbsp;';
if (isset($taxAmount) && $invoicing) {
$opt['label'] = $opt['label'] . self::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
}
else {
$opt['label'] = $opt['label'] . CRM_Utils_Money::format($opt[$valueFieldName]);
}
}
$priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
if (!in_array($opt['id'], $freezeOptions)) {
$allowedOptions[] = $opt['id'];
}
// CRM-14696 - Improve display for sold out price set options
else {
$opt['id'] = 'crm_disabled_opt-' . $opt['id'];
$opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
}
$selectOption[$opt['id']] = $opt['label'];
if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
}
}
if (isset($opt['visibility_id'])) {
$visibility_id = $opt['visibility_id'];
}
else {
$visibility_id = self::getVisibilityOptionID('public');
}
$element = &$qf->add('select', $elementName, $label,
array(
'' => ts('- select -'),
) + $selectOption,
$useRequired && $field->is_required,
array('price' => json_encode($priceVal), 'class' => 'crm-select2', 'data-price-field-values' => json_encode($customOption))
);
// CRM-6902 - Add "max" option for a price set field
$button = substr($qf->controller->getButtonName(), -4);
if (!empty($freezeOptions) && $button != 'skip') {
$qf->addRule($elementName, ts('Sorry, this option is currently sold out.'), 'regex', "/" . implode('|', $allowedOptions) . "/");
}
break;
case 'CheckBox':
$check = array();
foreach ($customOption as $opId => $opt) {
$taxAmount = CRM_Utils_Array::value('tax_amount', $opt);
$count = CRM_Utils_Array::value('count', $opt, '');
$max_value = CRM_Utils_Array::value('max_value', $opt, '');
if ($field->is_display_amounts) {
$preHelpText = $postHelpText = '';
if (isset($opt['help_pre'])) {
$preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span>: ';
}
if (isset($opt['help_post'])) {
$postHelpText = ': <span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
}
$opt['label'] = '<span class="crm-price-amount-label">' . $opt['label'] . '</span>&nbsp;-&nbsp;';
if (isset($taxAmount) && $invoicing) {
$opt['label'] .= self::getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm);
}
else {
$opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
}
$opt['label'] = $preHelpText . $opt['label'] . $postHelpText;
}
$priceVal = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
$check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
array(
'price' => json_encode(array($opt['id'], $priceVal)),
'data-amount' => $opt[$valueFieldName],
'data-currency' => $currencyName,
'visibility' => $opt['visibility_id'],
)
);
if ($is_pay_later) {
$txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], array('size' => '4'));
$qf->addGroup($txtcheck, 'txt-' . $elementName, $label);
}
// CRM-6902 - Add "max" option for a price set field
if (in_array($opId, $freezeOptions)) {
self::freezeIfEnabled($check[$opId], $customOption[$opId]);
// CRM-14696 - Improve display for sold out price set options
$check[$opId]->setText('<span class="sold-out-option">' . $check[$opId]->getText() . '&nbsp;(' . ts('Sold out') . ')</span>');
}
}
$element = &$qf->addGroup($check, $elementName, $label);
if ($useRequired && $field->is_required) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
break;
}
if (isset($qf->_online) && $qf->_online) {
$element->freeze();
}
}
/**
* Retrieve a list of options for the specified field.
*
* @param int $fieldId
* Price field ID.
* @param bool $inactiveNeeded
* Include inactive options.
* @param bool $reset
* Discard stored values.
* @param bool $isDefaultContributionPriceSet
* Discard tax amount calculation for price set = default_contribution_amount.
*
* @return array
* array of options
*/
public static function getOptions($fieldId, $inactiveNeeded = FALSE, $reset = FALSE, $isDefaultContributionPriceSet = FALSE) {
static $options = array();
if ($reset) {
$options = array();
// This would happen if the function was only called to clear the cache.
if (empty($fieldId)) {
return array();
}
}
if (empty($options[$fieldId])) {
$values = array();
CRM_Price_BAO_PriceFieldValue::getValues($fieldId, $values, 'weight', !$inactiveNeeded);
$options[$fieldId] = $values;
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
// ToDo - Code for Hook Invoke
foreach ($options[$fieldId] as $priceFieldId => $priceFieldValues) {
if (isset($priceFieldValues['financial_type_id']) && array_key_exists($priceFieldValues['financial_type_id'], $taxRates) && !$isDefaultContributionPriceSet) {
$options[$fieldId][$priceFieldId]['tax_rate'] = $taxRates[$priceFieldValues['financial_type_id']];
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceFieldValues['amount'], $options[$fieldId][$priceFieldId]['tax_rate']);
$options[$fieldId][$priceFieldId]['tax_amount'] = $taxAmount['tax_amount'];
}
}
}
return $options[$fieldId];
}
/**
* @param $optionLabel
* @param int $fid
*
* @return mixed
*/
public static function getOptionId($optionLabel, $fid) {
if (!$optionLabel || !$fid) {
return;
}
$optionGroupName = "civicrm_price_field.amount.{$fid}";
$query = "
SELECT
option_value.id as id
FROM
civicrm_option_value option_value,
civicrm_option_group option_group
WHERE
option_group.name = %1
AND option_group.id = option_value.option_group_id
AND option_value.label = %2";
$dao = CRM_Core_DAO::executeQuery($query, array(
1 => array($optionGroupName, 'String'),
2 => array($optionLabel, 'String'),
));
while ($dao->fetch()) {
return $dao->id;
}
}
/**
* Delete the price set field.
*
* @param int $id
* Field Id.
*
* @return bool
*
*/
public static function deleteField($id) {
$field = new CRM_Price_DAO_PriceField();
$field->id = $id;
if ($field->find(TRUE)) {
// delete the options for this field
CRM_Price_BAO_PriceFieldValue::deleteValues($id);
// reorder the weight before delete
$fieldValues = array('price_set_id' => $field->price_set_id);
CRM_Utils_Weight::delWeight('CRM_Price_DAO_PriceField', $field->id, $fieldValues);
// now delete the field
return $field->delete();
}
return NULL;
}
/**
* @return array
*/
public static function &htmlTypes() {
static $htmlTypes = NULL;
if (!$htmlTypes) {
$htmlTypes = array(
'Text' => ts('Text / Numeric Quantity'),
'Select' => ts('Select'),
'Radio' => ts('Radio'),
'CheckBox' => ts('CheckBox'),
);
}
return $htmlTypes;
}
/**
* Validate the priceset.
*
* @param int $priceSetId
* , array $fields.
*
* retrun the error string
*
* @param $fields
* @param $error
* @param bool $allowNoneSelection
*
*/
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 = "
SELECT id, html_type
FROM civicrm_price_field
WHERE 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.');
}
}
}
/**
* Generate the label for price fields based on tax display setting option on CiviContribute Component Settings page.
*
* @param array $opt
* @param string $valueFieldName
* Amount.
* @param string $displayOpt
* Tax display setting option.
*
* @param string $taxTerm
*
* @return string
* Tax label for custom field.
*/
public static function getTaxLabel($opt, $valueFieldName, $displayOpt, $taxTerm) {
if ($displayOpt == 'Do_not_show') {
$label = CRM_Utils_Money::format($opt[$valueFieldName] + $opt['tax_amount']);
}
elseif ($displayOpt == 'Inclusive') {
$label = CRM_Utils_Money::format($opt[$valueFieldName] + $opt['tax_amount']);
$label .= '<span class="crm-price-amount-tax"> (includes ' . $taxTerm . ' of ' . CRM_Utils_Money::format($opt['tax_amount']) . ')</span>';
}
else {
$label = CRM_Utils_Money::format($opt[$valueFieldName]);
$label .= '<span class="crm-price-amount-tax"> + ' . CRM_Utils_Money::format($opt['tax_amount']) . ' ' . $taxTerm . '</span>';
}
return $label;
}
/**
* Given the name of a visibility option, returns its ID.
*
* @param string $visibilityName
*
* @return int
*/
public static function getVisibilityOptionID($visibilityName) {
if (!isset(self::$visibilityOptionsKeys)) {
self::$visibilityOptionsKeys = CRM_Price_BAO_PriceField::buildOptions(
'visibility_id',
NULL,
array(
'labelColumn' => 'name',
'flip' => TRUE,
)
);
}
if (isset(self::$visibilityOptionsKeys[$visibilityName])) {
return self::$visibilityOptionsKeys[$visibilityName];
}
return 0;
}
}

View file

@ -0,0 +1,349 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* Business objects for managing price fields values.
*
*/
class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
/**
* Insert/update a new entry in the database.
*
* @param array $params
*
* @param array $ids
* Deprecated variable.
*
* @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;
$prevLabel = self::getOptionLabel($id);
if (!empty($params['label']) && $prevLabel != $params['label']) {
self::updateAmountAndFeeLevel($id, $prevLabel, $params['label']);
}
}
// CRM-16189
$priceFieldID = CRM_Utils_Array::value('price_field_id', $params);
if (!$priceFieldID) {
$priceFieldID = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceFieldValue', $id, 'price_field_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;
}
/**
* Creates a new entry in the database.
*
* @param array $params
* (reference), array $ids.
*
* @param $ids
*
* @return CRM_Price_DAO_PriceFieldValue
*/
public static function create(&$params, $ids = array()) {
$id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
if (!is_array($params) || empty($params)) {
return NULL;
}
if (!$id && empty($params['name'])) {
$params['name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 242));
}
if ($id && !empty($params['weight'])) {
if (isset($params['name'])) {
unset($params['name']);
}
$oldWeight = NULL;
if ($id) {
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $id, 'weight', 'id');
}
$fieldValues = array('price_field_id' => CRM_Utils_Array::value('price_field_id', $params, 0));
$params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceFieldValue', $oldWeight, $params['weight'], $fieldValues);
}
else {
if (!$id) {
CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
if (empty($params['name'])) {
$params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64);
}
}
}
$financialType = CRM_Utils_Array::value('financial_type_id', $params, NULL);
if (!$financialType && $id) {
$financialType = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $id, 'financial_type_id', 'id');
}
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
if (!empty($financialType) && !array_key_exists($financialType, $financialTypes) && $params['is_active']) {
throw new CRM_Core_Exception("Financial Type for Price Field Option is either disabled or does not exist");
}
return self::add($params, $ids);
}
/**
* Get defaults for new entity.
* @return array
*/
public static function getDefaults() {
return array(
'is_active' => 1,
'weight' => 1,
);
}
/**
* Retrieve DB object based on input parameters.
*
* It also stores all the retrieved values in the default array.
*
* @param array $params
* (reference ) an assoc array.
* @param array $defaults
* (reference ) an assoc array to hold the flattened values.
*
* @return CRM_Price_DAO_PriceFieldValue
*/
public static function retrieve(&$params, &$defaults) {
return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceFieldValue', $params, $defaults);
}
/**
* Retrieve all values for given field id.
*
* @param int $fieldId
* Price_field_id.
* @param array $values
* (reference ) to hold the values.
* @param string $orderBy
* For order by, default weight.
* @param bool|int $isActive is_active, default false
* @param bool $admin is this loading it for use on an admin page.
*
* @return array
*
*/
public static function getValues($fieldId, &$values, $orderBy = 'weight', $isActive = FALSE, $admin = FALSE) {
$sql = "SELECT cs.id FROM civicrm_price_set cs INNER JOIN civicrm_price_field cp ON cp.price_set_id = cs.id
WHERE cs.name IN ('default_contribution_amount', 'default_membership_type_amount') AND cp.id = {$fieldId} ";
$setId = CRM_Core_DAO::singleValueQuery($sql);
$fieldValueDAO = new CRM_Price_DAO_PriceFieldValue();
$fieldValueDAO->price_field_id = $fieldId;
$addWhere = '';
if (!$setId) {
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
if (!$admin) {
$addWhere = "financial_type_id IN (0)";
}
if (!empty($financialTypes) && !$admin) {
$addWhere = "financial_type_id IN (" . implode(',', array_keys($financialTypes)) . ")";
}
if (!empty($addWhere)) {
$fieldValueDAO->whereAdd($addWhere);
}
}
$fieldValueDAO->orderBy($orderBy, 'label');
if ($isActive) {
$fieldValueDAO->is_active = 1;
}
$fieldValueDAO->find();
while ($fieldValueDAO->fetch()) {
CRM_Core_DAO::storeValues($fieldValueDAO, $values[$fieldValueDAO->id]);
}
return $values;
}
/**
* Get the price field option label.
*
* @param int $id
* Id of field option.
*
* @return string
* name
*
*/
public static function getOptionLabel($id) {
return CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $id, 'label');
}
/**
* Update the is_active flag in the db.
*
* @param int $id
* Id of the database record.
* @param bool $is_active
* Value we want to set the is_active field.
*
* @return Object
* DAO object on success, null otherwise
*
*/
public static function setIsActive($id, $is_active) {
return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceFieldValue', $id, 'is_active', $is_active);
}
/**
* Delete all values of the given field id.
*
* @param int $fieldId
* Price field id.
*
*
*/
public static function deleteValues($fieldId) {
if (!$fieldId) {
return;
}
$fieldValueDAO = new CRM_Price_DAO_PriceFieldValue();
$fieldValueDAO->price_field_id = $fieldId;
$fieldValueDAO->delete();
}
/**
* Delete the value.
*
* @param int $id
* Id.
*
* @return bool
*
*/
public static function del($id) {
if (!$id) {
return FALSE;
}
$fieldValueDAO = new CRM_Price_DAO_PriceFieldValue();
$fieldValueDAO->id = $id;
return $fieldValueDAO->delete();
}
/**
* Update civicrm_price_field_value.financial_type_id
* when financial_type_id of contribution_page or event is changed
*
* @param int $entityId
* Id.
* @param string $entityTable table.
* Entity table.
* @param string $financialTypeID type id.
* Financial type id.
*
*/
public static function updateFinancialType($entityId, $entityTable, $financialTypeID) {
if (!$entityId || !$entityTable || !$financialTypeID) {
return;
}
$params = array(
1 => array($entityId, 'Integer'),
2 => array($entityTable, 'String'),
3 => array($financialTypeID, 'Integer'),
);
// for event discount
$join = $where = '';
if ($entityTable == 'civicrm_event') {
$join = " LEFT JOIN civicrm_discount cd ON cd.price_set_id = cps.id AND cd.entity_id = %1 AND cd.entity_table = %2 ";
$where = ' OR cd.id IS NOT NULL ';
}
$sql = "UPDATE civicrm_price_set cps
LEFT JOIN civicrm_price_set_entity cpse ON cpse.price_set_id = cps.id AND cpse.entity_id = %1 AND cpse.entity_table = %2
LEFT JOIN civicrm_price_field cpf ON cpf.price_set_id = cps.id
LEFT JOIN civicrm_price_field_value cpfv ON cpf.id = cpfv.price_field_id
{$join}
SET cpfv.financial_type_id = CASE
WHEN cpfv.membership_type_id IS NOT NULL
THEN cpfv.financial_type_id
ELSE %3
END,
cps.financial_type_id = %3
WHERE cpse.id IS NOT NULL {$where}";
CRM_Core_DAO::executeQuery($sql, $params);
}
/**
* Update price option label in line_item, civicrm_contribution and civicrm_participant.
*
* @param int $id - id of the price_field_value
* @param string $prevLabel
* @param string $newLabel
*
*/
public static function updateAmountAndFeeLevel($id, $prevLabel, $newLabel) {
// update price field label in line item.
$lineItem = new CRM_Price_DAO_LineItem();
$lineItem->price_field_value_id = $id;
$lineItem->label = $prevLabel;
$lineItem->find();
while ($lineItem->fetch()) {
$lineItemParams['id'] = $lineItem->id;
$lineItemParams['label'] = $newLabel;
CRM_Price_BAO_LineItem::create($lineItemParams);
// update amount and fee level in civicrm_contribution and civicrm_participant
$params = array(
1 => array(CRM_Core_DAO::VALUE_SEPARATOR . $prevLabel . ' -', 'String'),
2 => array(CRM_Core_DAO::VALUE_SEPARATOR . $newLabel . ' -', 'String'),
);
// Update contribution
if (!empty($lineItem->contribution_id)) {
CRM_Core_DAO::executeQuery("UPDATE `civicrm_contribution` SET `amount_level` = REPLACE(amount_level, %1, %2) WHERE id = {$lineItem->contribution_id}", $params);
}
// Update participant
if ($lineItem->entity_table == 'civicrm_participant') {
CRM_Core_DAO::executeQuery("UPDATE `civicrm_participant` SET `fee_level` = REPLACE(fee_level, %1, %2) WHERE id = {$lineItem->entity_id}", $params);
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,466 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*
* Generated from xml/schema/CRM/Price/LineItem.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:db7c7e55df64ed93a7152b5297d13d25)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Price_DAO_LineItem constructor.
*/
class CRM_Price_DAO_LineItem extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_line_item';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = true;
/**
* Line Item
*
* @var int unsigned
*/
public $id;
/**
* table which has the transaction
*
* @var string
*/
public $entity_table;
/**
* entry in table
*
* @var int unsigned
*/
public $entity_id;
/**
* FK to civicrm_contribution
*
* @var int unsigned
*/
public $contribution_id;
/**
* FK to civicrm_price_field
*
* @var int unsigned
*/
public $price_field_id;
/**
* descriptive label for item - from price_field_value.label
*
* @var string
*/
public $label;
/**
* How many items ordered
*
* @var float
*/
public $qty;
/**
* price of each item
*
* @var float
*/
public $unit_price;
/**
* qty * unit_price
*
* @var float
*/
public $line_total;
/**
* Participant count for field
*
* @var int unsigned
*/
public $participant_count;
/**
* FK to civicrm_price_field_value
*
* @var int unsigned
*/
public $price_field_value_id;
/**
* FK to Financial Type.
*
* @var int unsigned
*/
public $financial_type_id;
/**
* Portion of total amount which is NOT tax deductible.
*
* @var float
*/
public $non_deductible_amount;
/**
* tax of each item
*
* @var float
*/
public $tax_amount;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_line_item';
parent::__construct();
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'contribution_id', 'civicrm_contribution', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'price_field_id', 'civicrm_price_field', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'price_field_value_id', 'civicrm_price_field_value', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'financial_type_id', 'civicrm_financial_type', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'entity_id', NULL, 'id', 'entity_table');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Line Item ID') ,
'description' => 'Line Item',
'required' => true,
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
) ,
'entity_table' => array(
'name' => 'entity_table',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Line Item Entity Type') ,
'description' => 'table which has the transaction',
'required' => true,
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
) ,
'entity_id' => array(
'name' => 'entity_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Line Item Entity') ,
'description' => 'entry in table',
'required' => true,
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
) ,
'contribution_id' => array(
'name' => 'contribution_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Line Item Contribution') ,
'description' => 'FK to civicrm_contribution',
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'FKClassName' => 'CRM_Contribute_DAO_Contribution',
) ,
'price_field_id' => array(
'name' => 'price_field_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Line Item Price Field') ,
'description' => 'FK to civicrm_price_field',
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'FKClassName' => 'CRM_Price_DAO_PriceField',
) ,
'label' => array(
'name' => 'label',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Line Item Label') ,
'description' => 'descriptive label for item - from price_field_value.label',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'default' => 'NULL',
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'qty' => array(
'name' => 'qty',
'type' => CRM_Utils_Type::T_MONEY,
'title' => ts('Line Item Quantity') ,
'description' => 'How many items ordered',
'required' => true,
'precision' => array(
20,
2
) ,
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'unit_price' => array(
'name' => 'unit_price',
'type' => CRM_Utils_Type::T_MONEY,
'title' => ts('Unit Price') ,
'description' => 'price of each item',
'required' => true,
'precision' => array(
20,
2
) ,
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'line_total' => array(
'name' => 'line_total',
'type' => CRM_Utils_Type::T_MONEY,
'title' => ts('Line Item Total') ,
'description' => 'qty * unit_price',
'required' => true,
'precision' => array(
20,
2
) ,
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
) ,
'participant_count' => array(
'name' => 'participant_count',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Line Item Participant Count') ,
'description' => 'Participant count for field',
'default' => 'NULL',
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'price_field_value_id' => array(
'name' => 'price_field_value_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Line Item Option') ,
'description' => 'FK to civicrm_price_field_value',
'default' => 'NULL',
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'FKClassName' => 'CRM_Price_DAO_PriceFieldValue',
) ,
'financial_type_id' => array(
'name' => 'financial_type_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Financial Type') ,
'description' => 'FK to Financial Type.',
'default' => 'NULL',
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'FKClassName' => 'CRM_Financial_DAO_FinancialType',
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'table' => 'civicrm_financial_type',
'keyColumn' => 'id',
'labelColumn' => 'name',
)
) ,
'non_deductible_amount' => array(
'name' => 'non_deductible_amount',
'type' => CRM_Utils_Type::T_MONEY,
'title' => ts('Non-deductible Amount') ,
'description' => 'Portion of total amount which is NOT tax deductible.',
'required' => true,
'precision' => array(
20,
2
) ,
'default' => '0.0',
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'tax_amount' => array(
'name' => 'tax_amount',
'type' => CRM_Utils_Type::T_MONEY,
'title' => ts('Tax Amount') ,
'description' => 'tax of each item',
'precision' => array(
20,
2
) ,
'import' => true,
'where' => 'civicrm_line_item.tax_amount',
'headerPattern' => '/tax(.?am(ou)?nt)?/i',
'dataPattern' => '/^\d+(\.\d{2})?$/',
'export' => true,
'table_name' => 'civicrm_line_item',
'entity' => 'LineItem',
'bao' => 'CRM_Price_BAO_LineItem',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return self::$_tableName;
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'line_item', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'line_item', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array(
'index_entity' => array(
'name' => 'index_entity',
'field' => array(
0 => 'entity_table',
1 => 'entity_id',
) ,
'localizable' => false,
'sig' => 'civicrm_line_item::0::entity_table::entity_id',
) ,
'UI_line_item_value' => array(
'name' => 'UI_line_item_value',
'field' => array(
0 => 'entity_table',
1 => 'entity_id',
2 => 'contribution_id',
3 => 'price_field_value_id',
4 => 'price_field_id',
) ,
'localizable' => false,
'unique' => true,
'sig' => 'civicrm_line_item::1::entity_table::entity_id::contribution_id::price_field_value_id::price_field_id',
) ,
);
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,501 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*
* Generated from xml/schema/CRM/Price/PriceField.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:6ee89c3106c27af4ca96897826a2ef8c)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Price_DAO_PriceField constructor.
*/
class CRM_Price_DAO_PriceField extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_price_field';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = true;
/**
* Price Field
*
* @var int unsigned
*/
public $id;
/**
* FK to civicrm_price_set
*
* @var int unsigned
*/
public $price_set_id;
/**
* Variable name/programmatic handle for this field.
*
* @var string
*/
public $name;
/**
* Text for form field label (also friendly name for administering this field).
*
* @var string
*/
public $label;
/**
*
* @var string
*/
public $html_type;
/**
* Enter a quantity for this field?
*
* @var boolean
*/
public $is_enter_qty;
/**
* Description and/or help text to display before this field.
*
* @var text
*/
public $help_pre;
/**
* Description and/or help text to display after this field.
*
* @var text
*/
public $help_post;
/**
* Order in which the fields should appear
*
* @var int
*/
public $weight;
/**
* Should the price be displayed next to the label for each option?
*
* @var boolean
*/
public $is_display_amounts;
/**
* number of options per line for checkbox and radio
*
* @var int unsigned
*/
public $options_per_line;
/**
* Is this price field active
*
* @var boolean
*/
public $is_active;
/**
* Is this price field required (value must be > 1)
*
* @var boolean
*/
public $is_required;
/**
* If non-zero, do not show this field before the date specified
*
* @var datetime
*/
public $active_on;
/**
* If non-zero, do not show this field after the date specified
*
* @var datetime
*/
public $expire_on;
/**
* Optional scripting attributes for field
*
* @var string
*/
public $javascript;
/**
* Implicit FK to civicrm_option_group with name = 'visibility'
*
* @var int unsigned
*/
public $visibility_id;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_price_field';
parent::__construct();
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'price_set_id', 'civicrm_price_set', 'id');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Field ID') ,
'description' => 'Price Field',
'required' => true,
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
) ,
'price_set_id' => array(
'name' => 'price_set_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Set') ,
'description' => 'FK to civicrm_price_set',
'required' => true,
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'FKClassName' => 'CRM_Price_DAO_PriceSet',
) ,
'name' => array(
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Name') ,
'description' => 'Variable name/programmatic handle for this field.',
'required' => true,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'label' => array(
'name' => 'label',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Label') ,
'description' => 'Text for form field label (also friendly name for administering this field).',
'required' => true,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 1,
'html' => array(
'type' => 'Text',
) ,
) ,
'html_type' => array(
'name' => 'html_type',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Html Type') ,
'required' => true,
'maxlength' => 12,
'size' => CRM_Utils_Type::TWELVE,
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'callback' => 'CRM_Price_BAO_PriceField::htmlTypes',
)
) ,
'is_enter_qty' => array(
'name' => 'is_enter_qty',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Price Field Quantity Required?') ,
'description' => 'Enter a quantity for this field?',
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
'help_pre' => array(
'name' => 'help_pre',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Price Field Pre Text') ,
'description' => 'Description and/or help text to display before this field.',
'rows' => 4,
'cols' => 80,
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 1,
'html' => array(
'type' => 'TextArea',
) ,
) ,
'help_post' => array(
'name' => 'help_post',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Price Field Post Text') ,
'description' => 'Description and/or help text to display after this field.',
'rows' => 4,
'cols' => 80,
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 1,
'html' => array(
'type' => 'TextArea',
) ,
) ,
'weight' => array(
'name' => 'weight',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Order') ,
'description' => 'Order in which the fields should appear',
'default' => '1',
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'Select',
) ,
) ,
'is_display_amounts' => array(
'name' => 'is_display_amounts',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Price Field Show Amounts?') ,
'description' => 'Should the price be displayed next to the label for each option?',
'default' => '1',
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
'options_per_line' => array(
'name' => 'options_per_line',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Field Options per Row') ,
'description' => 'number of options per line for checkbox and radio',
'default' => '1',
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'is_active' => array(
'name' => 'is_active',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Price Field Is Active?') ,
'description' => 'Is this price field active',
'default' => '1',
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
'is_required' => array(
'name' => 'is_required',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Price Field is Required?') ,
'description' => 'Is this price field required (value must be > 1)',
'default' => '1',
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
'active_on' => array(
'name' => 'active_on',
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => ts('Price Field Start Date') ,
'description' => 'If non-zero, do not show this field before the date specified',
'default' => 'NULL',
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
'expire_on' => array(
'name' => 'expire_on',
'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
'title' => ts('Price Field End Date') ,
'description' => 'If non-zero, do not show this field after the date specified',
'default' => 'NULL',
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'Select Date',
) ,
) ,
'javascript' => array(
'name' => 'javascript',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Price Field Javascript') ,
'description' => 'Optional scripting attributes for field',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'visibility_id' => array(
'name' => 'visibility_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Field Visibility') ,
'description' => 'Implicit FK to civicrm_option_group with name = \'visibility\'',
'default' => '1',
'table_name' => 'civicrm_price_field',
'entity' => 'PriceField',
'bao' => 'CRM_Price_BAO_PriceField',
'localizable' => 0,
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'optionGroupName' => 'visibility',
'optionEditPath' => 'civicrm/admin/options/visibility',
)
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'price_field', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'price_field', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array(
'index_name' => array(
'name' => 'index_name',
'field' => array(
0 => 'name',
) ,
'localizable' => false,
'sig' => 'civicrm_price_field::0::name',
) ,
);
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,525 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*
* Generated from xml/schema/CRM/Price/PriceFieldValue.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:fed218269d1baab495490130b4e2442a)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Price_DAO_PriceFieldValue constructor.
*/
class CRM_Price_DAO_PriceFieldValue extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_price_field_value';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = false;
/**
* Price Field Value
*
* @var int unsigned
*/
public $id;
/**
* FK to civicrm_price_field
*
* @var int unsigned
*/
public $price_field_id;
/**
* Price field option name
*
* @var string
*/
public $name;
/**
* Price field option label
*
* @var string
*/
public $label;
/**
* >Price field option description.
*
* @var text
*/
public $description;
/**
* Price field option pre help text.
*
* @var text
*/
public $help_pre;
/**
* Price field option post field help.
*
* @var text
*/
public $help_post;
/**
* Price field option amount
*
* @var float
*/
public $amount;
/**
* Number of participants per field option
*
* @var int unsigned
*/
public $count;
/**
* Max number of participants per field options
*
* @var int unsigned
*/
public $max_value;
/**
* Order in which the field options should appear
*
* @var int
*/
public $weight;
/**
* FK to Membership Type
*
* @var int unsigned
*/
public $membership_type_id;
/**
* Number of terms for this membership
*
* @var int unsigned
*/
public $membership_num_terms;
/**
* Is this default price field option
*
* @var boolean
*/
public $is_default;
/**
* Is this price field value active
*
* @var boolean
*/
public $is_active;
/**
* FK to Financial Type.
*
* @var int unsigned
*/
public $financial_type_id;
/**
* Portion of total amount which is NOT tax deductible.
*
* @var float
*/
public $non_deductible_amount;
/**
* Implicit FK to civicrm_option_group with name = 'visibility'
*
* @var int unsigned
*/
public $visibility_id;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_price_field_value';
parent::__construct();
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'price_field_id', 'civicrm_price_field', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'membership_type_id', 'civicrm_membership_type', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'financial_type_id', 'civicrm_financial_type', 'id');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Field Value ID') ,
'description' => 'Price Field Value',
'required' => true,
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
) ,
'price_field_id' => array(
'name' => 'price_field_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Field') ,
'description' => 'FK to civicrm_price_field',
'required' => true,
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'FKClassName' => 'CRM_Price_DAO_PriceField',
) ,
'name' => array(
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Name') ,
'description' => 'Price field option name',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'label' => array(
'name' => 'label',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Label') ,
'description' => 'Price field option label',
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 1,
'html' => array(
'type' => 'Text',
) ,
) ,
'description' => array(
'name' => 'description',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Description') ,
'description' => '>Price field option description.',
'rows' => 2,
'cols' => 60,
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 1,
'html' => array(
'type' => 'TextArea',
) ,
) ,
'help_pre' => array(
'name' => 'help_pre',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Help Pre') ,
'description' => 'Price field option pre help text.',
'rows' => 2,
'cols' => 60,
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 1,
'html' => array(
'type' => 'TextArea',
) ,
) ,
'help_post' => array(
'name' => 'help_post',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Help Post') ,
'description' => 'Price field option post field help.',
'rows' => 2,
'cols' => 60,
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 1,
'html' => array(
'type' => 'TextArea',
) ,
) ,
'amount' => array(
'name' => 'amount',
'type' => CRM_Utils_Type::T_MONEY,
'title' => ts('Amount') ,
'description' => 'Price field option amount',
'required' => true,
'precision' => array(
18,
9
) ,
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'count' => array(
'name' => 'count',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Count') ,
'description' => 'Number of participants per field option',
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'max_value' => array(
'name' => 'max_value',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Max Value') ,
'description' => 'Max number of participants per field options',
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'weight' => array(
'name' => 'weight',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Order') ,
'description' => 'Order in which the field options should appear',
'default' => '1',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'membership_type_id' => array(
'name' => 'membership_type_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Membership Type') ,
'description' => 'FK to Membership Type',
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'FKClassName' => 'CRM_Member_DAO_MembershipType',
'html' => array(
'type' => 'Select',
) ,
) ,
'membership_num_terms' => array(
'name' => 'membership_num_terms',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Membership Num Terms') ,
'description' => 'Number of terms for this membership',
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'is_default' => array(
'name' => 'is_default',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Is Default Price Field Option?') ,
'description' => 'Is this default price field option',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
'is_active' => array(
'name' => 'is_active',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Price Field Value is Active') ,
'description' => 'Is this price field value active',
'default' => '1',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
) ,
'financial_type_id' => array(
'name' => 'financial_type_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Financial Type') ,
'description' => 'FK to Financial Type.',
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'FKClassName' => 'CRM_Financial_DAO_FinancialType',
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'table' => 'civicrm_financial_type',
'keyColumn' => 'id',
'labelColumn' => 'name',
)
) ,
'non_deductible_amount' => array(
'name' => 'non_deductible_amount',
'type' => CRM_Utils_Type::T_MONEY,
'title' => ts('Non-deductible Amount') ,
'description' => 'Portion of total amount which is NOT tax deductible.',
'required' => true,
'precision' => array(
20,
2
) ,
'default' => '0.0',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'visibility_id' => array(
'name' => 'visibility_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Field Option Visibility') ,
'description' => 'Implicit FK to civicrm_option_group with name = \'visibility\'',
'default' => '1',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
'localizable' => 0,
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'optionGroupName' => 'visibility',
'optionEditPath' => 'civicrm/admin/options/visibility',
)
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'price_field_value', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'price_field_value', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array();
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,434 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*
* Generated from xml/schema/CRM/Price/PriceSet.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:7250a5af1e713fc047875f2cc22443ff)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Price_DAO_PriceSet constructor.
*/
class CRM_Price_DAO_PriceSet extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_price_set';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = true;
/**
* Price Set
*
* @var int unsigned
*/
public $id;
/**
* Which Domain is this price-set for
*
* @var int unsigned
*/
public $domain_id;
/**
* Variable name/programmatic handle for this set of price fields.
*
* @var string
*/
public $name;
/**
* Displayed title for the Price Set.
*
* @var string
*/
public $title;
/**
* Is this price set active
*
* @var boolean
*/
public $is_active;
/**
* Description and/or help text to display before fields in form.
*
* @var text
*/
public $help_pre;
/**
* Description and/or help text to display after fields in form.
*
* @var text
*/
public $help_post;
/**
* Optional Javascript script function(s) included on the form with this price_set. Can be used for conditional
*
* @var string
*/
public $javascript;
/**
* What components are using this price set?
*
* @var string
*/
public $extends;
/**
* FK to Financial Type(for membership price sets only).
*
* @var int unsigned
*/
public $financial_type_id;
/**
* Is set if edited on Contribution or Event Page rather than through Manage Price Sets
*
* @var boolean
*/
public $is_quick_config;
/**
* Is this a predefined system price set (i.e. it can not be deleted, edited)?
*
* @var boolean
*/
public $is_reserved;
/**
* Minimum Amount required for this set.
*
* @var int unsigned
*/
public $min_amount;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_price_set';
parent::__construct();
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'domain_id', 'civicrm_domain', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'financial_type_id', 'civicrm_financial_type', 'id');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Set ID') ,
'description' => 'Price Set',
'required' => true,
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
) ,
'domain_id' => array(
'name' => 'domain_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Set Domain') ,
'description' => 'Which Domain is this price-set for',
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
'FKClassName' => 'CRM_Core_DAO_Domain',
'html' => array(
'type' => 'Text',
) ,
'pseudoconstant' => array(
'table' => 'civicrm_domain',
'keyColumn' => 'id',
'labelColumn' => 'name',
)
) ,
'name' => array(
'name' => 'name',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Name') ,
'description' => 'Variable name/programmatic handle for this set of price fields.',
'required' => true,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'title' => array(
'name' => 'title',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Price Set Title') ,
'description' => 'Displayed title for the Price Set.',
'required' => true,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 1,
'html' => array(
'type' => 'Text',
) ,
) ,
'is_active' => array(
'name' => 'is_active',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Price Set Is Active?') ,
'description' => 'Is this price set active',
'default' => '1',
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
'help_pre' => array(
'name' => 'help_pre',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Price Set Pre Help') ,
'description' => 'Description and/or help text to display before fields in form.',
'rows' => 4,
'cols' => 80,
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 1,
'html' => array(
'type' => 'TextArea',
) ,
) ,
'help_post' => array(
'name' => 'help_post',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Price Set Post Help') ,
'description' => 'Description and/or help text to display after fields in form.',
'rows' => 4,
'cols' => 80,
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 1,
'html' => array(
'type' => 'TextArea',
) ,
) ,
'javascript' => array(
'name' => 'javascript',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Price Set Javascript') ,
'description' => 'Optional Javascript script function(s) included on the form with this price_set. Can be used for conditional',
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
'extends' => array(
'name' => 'extends',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Price Set Extends') ,
'description' => 'What components are using this price set?',
'required' => true,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
'pseudoconstant' => array(
'table' => 'civicrm_component',
'keyColumn' => 'id',
'labelColumn' => 'name',
)
) ,
'financial_type_id' => array(
'name' => 'financial_type_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Financial Type') ,
'description' => 'FK to Financial Type(for membership price sets only).',
'default' => 'NULL',
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
'FKClassName' => 'CRM_Financial_DAO_FinancialType',
'html' => array(
'type' => 'Select',
) ,
'pseudoconstant' => array(
'table' => 'civicrm_financial_type',
'keyColumn' => 'id',
'labelColumn' => 'name',
)
) ,
'is_quick_config' => array(
'name' => 'is_quick_config',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Is Price Set Quick Config?') ,
'description' => 'Is set if edited on Contribution or Event Page rather than through Manage Price Sets',
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
'is_reserved' => array(
'name' => 'is_reserved',
'type' => CRM_Utils_Type::T_BOOLEAN,
'title' => ts('Price Set Is Reserved') ,
'description' => 'Is this a predefined system price set (i.e. it can not be deleted, edited)?',
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
'html' => array(
'type' => 'CheckBox',
) ,
) ,
'min_amount' => array(
'name' => 'min_amount',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Minimum Amount') ,
'description' => 'Minimum Amount required for this set.',
'table_name' => 'civicrm_price_set',
'entity' => 'PriceSet',
'bao' => 'CRM_Price_BAO_PriceSet',
'localizable' => 0,
'html' => array(
'type' => 'Text',
) ,
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'price_set', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'price_set', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array(
'UI_name' => array(
'name' => 'UI_name',
'field' => array(
0 => 'name',
) ,
'localizable' => false,
'unique' => true,
'sig' => 'civicrm_price_set::1::name',
) ,
);
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,227 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*
* Generated from xml/schema/CRM/Price/PriceSetEntity.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:6113d40ca79159b19d2c915aeb620e7c)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
/**
* CRM_Price_DAO_PriceSetEntity constructor.
*/
class CRM_Price_DAO_PriceSetEntity extends CRM_Core_DAO {
/**
* Static instance to hold the table name.
*
* @var string
*/
static $_tableName = 'civicrm_price_set_entity';
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var boolean
*/
static $_log = true;
/**
* Price Set Entity
*
* @var int unsigned
*/
public $id;
/**
* Table which uses this price set
*
* @var string
*/
public $entity_table;
/**
* Item in table
*
* @var int unsigned
*/
public $entity_id;
/**
* price set being used
*
* @var int unsigned
*/
public $price_set_id;
/**
* Class constructor.
*/
function __construct() {
$this->__table = 'civicrm_price_set_entity';
parent::__construct();
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static ::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName() , 'price_set_id', 'civicrm_price_set', 'id');
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName() , 'entity_id', NULL, 'id', 'entity_table');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = array(
'id' => array(
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Set Entity ID') ,
'description' => 'Price Set Entity',
'required' => true,
'table_name' => 'civicrm_price_set_entity',
'entity' => 'PriceSetEntity',
'bao' => 'CRM_Price_DAO_PriceSetEntity',
'localizable' => 0,
) ,
'entity_table' => array(
'name' => 'entity_table',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Entity Table') ,
'description' => 'Table which uses this price set',
'required' => true,
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
'table_name' => 'civicrm_price_set_entity',
'entity' => 'PriceSetEntity',
'bao' => 'CRM_Price_DAO_PriceSetEntity',
'localizable' => 0,
) ,
'entity_id' => array(
'name' => 'entity_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Entity IF') ,
'description' => 'Item in table',
'required' => true,
'table_name' => 'civicrm_price_set_entity',
'entity' => 'PriceSetEntity',
'bao' => 'CRM_Price_DAO_PriceSetEntity',
'localizable' => 0,
) ,
'price_set_id' => array(
'name' => 'price_set_id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Price Set') ,
'description' => 'price set being used',
'required' => true,
'table_name' => 'civicrm_price_set_entity',
'entity' => 'PriceSetEntity',
'bao' => 'CRM_Price_DAO_PriceSetEntity',
'localizable' => 0,
'FKClassName' => 'CRM_Price_DAO_PriceSet',
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
static function getTableName() {
return self::$_tableName;
}
/**
* Returns if this table needs to be logged
*
* @return boolean
*/
function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
static function &import($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'price_set_entity', $prefix, array());
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
static function &export($prefix = false) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'price_set_entity', $prefix, array());
return $r;
}
/**
* Returns the list of indices
*/
public static function indices($localize = TRUE) {
$indices = array(
'UI_entity' => array(
'name' => 'UI_entity',
'field' => array(
0 => 'entity_table',
1 => 'entity_id',
) ,
'localizable' => false,
'unique' => true,
'sig' => 'civicrm_price_set_entity::1::entity_table::entity_id',
) ,
);
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}

View file

@ -0,0 +1,104 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class is to build the form for Deleting Group
*/
class CRM_Price_Form_DeleteField extends CRM_Core_Form {
/**
* The field id.
*
* @var int
*/
protected $_fid;
/**
* The title of the group being deleted.
*
* @var string
*/
protected $_title;
/**
* Set up variables to build the form.
*
* @return void
* @access protected
*/
public function preProcess() {
$this->_fid = $this->get('fid');
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField',
$this->_fid,
'label', 'id'
);
$this->assign('title', $this->_title);
CRM_Utils_System::setTitle(ts('Confirm Price Field Delete'));
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Delete Price Field'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
}
/**
* Process the form when submitted.
*
* @return void
*/
public function postProcess() {
if (CRM_Price_BAO_PriceField::deleteField($this->_fid)) {
CRM_Core_Session::setStatus(ts('The Price Field \'%1\' has been deleted.', array(1 => $this->_title)), '', 'success');
}
}
}

View file

@ -0,0 +1,104 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class is to build the form for Deleting Set
*/
class CRM_Price_Form_DeleteSet extends CRM_Core_Form {
/**
* The set id.
*
* @var int
*/
protected $_sid;
/**
* The title of the set being deleted.
*
* @var string
*/
protected $_title;
/**
* Set up variables to build the form.
*
* @return void
*/
public function preProcess() {
$this->_sid = $this->get('sid');
$this->_title = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet',
$this->_sid, 'title'
);
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
$this->assign('title', $this->_title);
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Delete Price Set'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
}
/**
* Process the form when submitted.
*
* @return void
*/
public function postProcess() {
if (CRM_Price_BAO_PriceSet::deleteSet($this->_sid)) {
CRM_Core_Session::setStatus(ts('The Price Set \'%1\' has been deleted.',
array(1 => $this->_title), ts('Deleted'), 'success'
));
}
else {
CRM_Core_Session::setStatus(ts('The Price Set \'%1\' has not been deleted! You must delete all price fields in this set prior to deleting the set.',
array(1 => $this->_title)
), 'Unable to Delete', 'error');
}
}
}

View file

@ -0,0 +1,717 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* form to process actions on the field aspect of Price
*/
class CRM_Price_Form_Field extends CRM_Core_Form {
/**
* Constants for number of options for data types of multiple option.
*/
const NUM_OPTION = 15;
/**
* The custom set id saved to the session for an update.
*
* @var int
*/
protected $_sid;
/**
* The field id, used when editing the field
*
* @var int
*/
protected $_fid;
/**
* The extended component Id.
*
* @var array
*/
protected $_extendComponentId;
/**
* Variable is set if price set is used for membership.
*/
protected $_useForMember;
/**
* Set variables up before form is built.
*/
public function preProcess() {
$this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this, FALSE, NULL, 'REQUEST');
$this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, NULL, 'REQUEST');
$url = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
$breadCrumb = array(array('title' => ts('Price Set Fields'), 'url' => $url));
$this->_extendComponentId = array();
$extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
if ($extendComponentId) {
$this->_extendComponentId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $extendComponentId);
}
CRM_Utils_System::appendBreadCrumb($breadCrumb);
$this->setPageTitle(ts('Price Field'));
}
/**
* Set default values for the form.
*
* @return array
* array of default values
*/
public function setDefaultValues() {
$defaults = array();
// is it an edit operation ?
if (isset($this->_fid)) {
$params = array('id' => $this->_fid);
$this->assign('fid', $this->_fid);
CRM_Price_BAO_PriceField::retrieve($params, $defaults);
$this->_sid = $defaults['price_set_id'];
// if text, retrieve price
if ($defaults['html_type'] == 'Text') {
$isActive = $defaults['is_active'];
$valueParams = array('price_field_id' => $this->_fid);
CRM_Price_BAO_PriceFieldValue::retrieve($valueParams, $defaults);
// fix the display of the monetary value, CRM-4038
$defaults['price'] = CRM_Utils_Money::format($defaults['amount'], NULL, '%a');
$defaults['is_active'] = $isActive;
}
if (!empty($defaults['active_on'])) {
list($defaults['active_on'],
$defaults['active_on_time']
) = CRM_Utils_Date::setDateDefaults($defaults['active_on'], 'activityDateTime');
}
if (!empty($defaults['expire_on'])) {
list($defaults['expire_on'],
$defaults['expire_on_time']
) = CRM_Utils_Date::setDateDefaults($defaults['expire_on'], 'activityDateTime');
}
}
else {
$defaults['is_active'] = 1;
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
$defaults['option_status[' . $i . ']'] = 1;
$defaults['option_weight[' . $i . ']'] = $i;
$defaults['option_visibility_id[' . $i . ']'] = 1;
}
}
if ($this->_action & CRM_Core_Action::ADD) {
$fieldValues = array('price_set_id' => $this->_sid);
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_PriceField', $fieldValues);
$defaults['options_per_line'] = 1;
$defaults['is_display_amounts'] = 1;
}
$enabledComponents = CRM_Core_Component::getEnabledComponents();
$eventComponentId = NULL;
if (array_key_exists('CiviEvent', $enabledComponents)) {
$eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
}
if (isset($this->_sid) && $this->_action == CRM_Core_Action::ADD) {
$financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'financial_type_id');
$defaults['financial_type_id'] = $financialTypeId;
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
$defaults['option_financial_type_id[' . $i . ']'] = $financialTypeId;
}
}
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
// lets trim all the whitespace
$this->applyFilter('__ALL__', 'trim');
// add a hidden field to remember the price set id
// this get around the browser tab issue
$this->add('hidden', 'sid', $this->_sid);
$this->add('hidden', 'fid', $this->_fid);
// label
$this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'label'), TRUE);
// html_type
$javascript = 'onchange="option_html_type(this.form)";';
$htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
// Text box for Participant Count for a field
// Financial Type
$financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
foreach ($financialType as $finTypeId => $type) {
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
&& !CRM_Core_Permission::check('add contributions of type ' . $type)
) {
unset($financialType[$finTypeId]);
}
}
if (count($financialType)) {
$this->assign('financialType', $financialType);
}
//Visibility Type Options
$visibilityType = CRM_Core_PseudoConstant::visibility();
$this->assign('visibilityType', $visibilityType);
$enabledComponents = CRM_Core_Component::getEnabledComponents();
$eventComponentId = $memberComponentId = NULL;
if (array_key_exists('CiviEvent', $enabledComponents)) {
$eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
}
if (array_key_exists('CiviMember', $enabledComponents)) {
$memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
}
$attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
$this->add('select', 'financial_type_id',
ts('Financial Type'),
array(' ' => ts('- select -')) + $financialType
);
$this->assign('useForMember', FALSE);
if (in_array($eventComponentId, $this->_extendComponentId)) {
$this->add('text', 'count', ts('Participant Count'), $attributes['count']);
$this->addRule('count', ts('Participant Count should be a positive number'), 'positiveInteger');
$this->add('text', 'max_value', ts('Max Participants'), $attributes['max_value']);
$this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger');
$this->assign('useForEvent', TRUE);
}
else {
if (in_array($memberComponentId, $this->_extendComponentId)) {
$this->_useForMember = 1;
$this->assign('useForMember', $this->_useForMember);
}
$this->assign('useForEvent', FALSE);
}
$sel = $this->add('select', 'html_type', ts('Input Field Type'),
$htmlTypes, TRUE, $javascript
);
// price (for text inputs)
$this->add('text', 'price', ts('Price'));
$this->registerRule('price', 'callback', 'money', 'CRM_Utils_Rule');
$this->addRule('price', ts('must be a monetary value'), 'money');
$this->add('text', 'non_deductible_amount', ts('Non-deductible Amount'), NULL);
$this->registerRule('non_deductible_amount', 'callback', 'money', 'CRM_Utils_Rule');
$this->addRule('non_deductible_amount', ts('Please enter a monetary value for this field.'), 'money');
if ($this->_action == CRM_Core_Action::UPDATE) {
$this->freeze('html_type');
}
// form fields of Custom Option rows
$_showHide = new CRM_Core_ShowHideBlocks('', '');
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
//the show hide blocks
$showBlocks = 'optionField_' . $i;
if ($i > 2) {
$_showHide->addHide($showBlocks);
if ($i == self::NUM_OPTION) {
$_showHide->addHide('additionalOption');
}
}
else {
$_showHide->addShow($showBlocks);
}
// label
$attributes['label']['size'] = 25;
$this->add('text', 'option_label[' . $i . ']', ts('Label'), $attributes['label']);
// amount
$this->add('text', 'option_amount[' . $i . ']', ts('Amount'), $attributes['amount']);
$this->addRule('option_amount[' . $i . ']', ts('Please enter a valid amount for this field.'), 'money');
//Financial Type
$this->add(
'select',
'option_financial_type_id[' . $i . ']',
ts('Financial Type'),
array('' => ts('- select -')) + $financialType
);
if (in_array($eventComponentId, $this->_extendComponentId)) {
// count
$this->add('text', 'option_count[' . $i . ']', ts('Participant Count'), $attributes['count']);
$this->addRule('option_count[' . $i . ']', ts('Please enter a valid Participants Count.'), 'positiveInteger');
// max_value
$this->add('text', 'option_max_value[' . $i . ']', ts('Max Participants'), $attributes['max_value']);
$this->addRule('option_max_value[' . $i . ']', ts('Please enter a valid Max Participants.'), 'positiveInteger');
// description
//$this->add('textArea', 'option_description['.$i.']', ts('Description'), array('rows' => 1, 'cols' => 40 ));
}
elseif (in_array($memberComponentId, $this->_extendComponentId)) {
$membershipTypes = CRM_Member_PseudoConstant::membershipType();
$js = array('onchange' => "calculateRowValues( $i );");
$this->add('select', 'membership_type_id[' . $i . ']', ts('Membership Type'),
array('' => ' ') + $membershipTypes, FALSE, $js
);
$this->add('text', 'membership_num_terms[' . $i . ']', ts('Number of Terms'), CRM_Utils_Array::value('membership_num_terms', $attributes));
}
// weight
$this->add('text', 'option_weight[' . $i . ']', ts('Order'), $attributes['weight']);
// is active ?
$this->add('checkbox', 'option_status[' . $i . ']', ts('Active?'));
$this->add('select', 'option_visibility_id[' . $i . ']', ts('Visibility'), array('' => ts('- select -')) + $visibilityType);
$defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i);
//for checkbox handling of default option
$this->add('checkbox', "default_checkbox_option[$i]", NULL);
}
//default option selection
$this->addGroup($defaultOption, 'default_option');
$_showHide->addToTemplate();
// is_display_amounts
$this->add('checkbox', 'is_display_amounts', ts('Display Amount?'));
// weight
$this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'weight'), TRUE);
$this->addRule('weight', ts('is a numeric field'), 'numeric');
// checkbox / radio options per line
$this->add('text', 'options_per_line', ts('Options Per Line'));
$this->addRule('options_per_line', ts('must be a numeric value'), 'numeric');
$this->add('textarea', 'help_pre', ts('Pre Field Help'),
CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'help_post')
);
// help post, mask, attributes, javascript ?
$this->add('textarea', 'help_post', ts('Post Field Help'),
CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'help_post')
);
$this->addDateTime('active_on', ts('Active On'), FALSE, array('formatType' => 'activityDateTime'));
// expire_on
$this->addDateTime('expire_on', ts('Expire On'), FALSE, array('formatType' => 'activityDateTime'));
// is required ?
$this->add('checkbox', 'is_required', ts('Required?'));
// is active ?
$this->add('checkbox', 'is_active', ts('Active?'));
// add buttons
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'next',
'name' => ts('Save and New'),
'subName' => 'new',
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
// is public?
$this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
// add a form rule to check default value
$this->addFormRule(array('CRM_Price_Form_Field', 'formRule'), $this);
// if view mode pls freeze it with the done button.
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
$url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid);
$this->addElement('button',
'done',
ts('Done'),
array('onclick' => "location.href='$url'")
);
}
}
/**
* 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'
) {
if ($fields['price'] == NULL) {
$errors['price'] = ts('Price is a required field');
}
if ($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;
$publicOptionCount = $_flagOption = $_rowError = 0;
$_showHide = new CRM_Core_ShowHideBlocks('', '');
$visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, array('labelColumn' => 'name'));
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);
}
if ($index == self::NUM_OPTION) {
$hideBlock = 'additionalOption';
$_showHide->addHide($hideBlock);
}
if (!empty($fields['option_visibility_id'][$index]) && (!$noLabel || !$noAmount)) {
if ($visibilityOptions[$fields['option_visibility_id'][$index]] == 'public') {
$publicOptionCount++;
}
}
$_flagOption = $_emptyRow = 0;
}
if (!empty($memTypesIDS)) {
// check for checkboxes allowing user to select multiple memberships from same membership organization
if ($fields['html_type'] == 'CheckBox') {
$foundDuplicate = FALSE;
$orgIds = array();
foreach ($memTypesIDS as $key => $val) {
$org = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization($val);
if (in_array($org[$val], $orgIds)) {
$foundDuplicate = TRUE;
break;
}
$orgIds[$val] = $org[$val];
}
if ($foundDuplicate) {
$errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity.');
}
}
// CRM-10390 - Only one price field in a set can include auto-renew membership options
$foundAutorenew = FALSE;
foreach ($memTypesIDS as $key => $val) {
// see if any price field option values in this price field are for memberships with autorenew
$memTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($val);
if (!empty($memTypeDetails['auto_renew'])) {
$foundAutorenew = TRUE;
break;
}
}
if ($foundAutorenew) {
// if so, check for other fields in this price set which also have auto-renew membership options
$otherFieldAutorenew = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($form->_sid);
if ($otherFieldAutorenew) {
$errors['_qf_default'] = ts('You can include auto-renew membership choices for only one price field in a price set. Another field in this set already contains one or more auto-renew membership options.');
}
}
}
$_showHide->addToTemplate();
if ($countemptyrows == 15) {
$errors['option_label[1]'] = $errors['option_amount[1]'] = ts('Label and value cannot be empty.');
$_flagOption = 1;
}
if ($visibilityOptions[$fields['visibility_id']] == 'public' && $publicOptionCount == 0) {
$errors['visibility_id'] = ts('You have selected to make this field public but have not enabled any public price options. Please update your selections to include a public price option, or make this field admin visibility only.');
for ($index = 1; $index <= self::NUM_OPTION; $index++) {
if (!empty($fields['option_label'][$index]) || !empty($fields['option_amount'][$index])) {
$errors["option_visibility_id[{$index}]"] = ts('Public field should at least have one public option.');
}
}
}
if ($visibilityOptions[$fields['visibility_id']] == 'admin' && $publicOptionCount > 0) {
$errors['visibility_id'] = ts('Field with \'Admin\' visibility should only contain \'Admin\' options.');
for ($index = 1; $index <= self::NUM_OPTION; $index++) {
$isOptionSet = !empty($fields['option_label'][$index]) || !empty($fields['option_amount'][$index]);
$currentOptionVisibility = CRM_Utils_Array::value($fields['option_visibility_id'][$index], $visibilityOptions);
if ($isOptionSet && $currentOptionVisibility == 'public') {
$errors["option_visibility_id[{$index}]"] = ts('\'Admin\' field should only have \'Admin\' visibility options.');
}
}
}
}
elseif (!empty($fields['max_value']) &&
!empty($fields['count']) &&
($fields['count'] > $fields['max_value'])
) {
$errors['max_value'] = ts('Participant count can not be greater than max participants.');
}
// do not process if no option rows were submitted
if (empty($fields['option_amount']) && empty($fields['option_label'])) {
return TRUE;
}
if (empty($fields['option_name'])) {
$fields['option_amount'] = array();
}
if (empty($fields['option_label'])) {
$fields['option_label'] = array();
}
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form.
*/
public function postProcess() {
// store the submitted values in an array
$params = $this->controller->exportValues('Field');
$params['is_display_amounts'] = CRM_Utils_Array::value('is_display_amounts', $params, FALSE);
$params['is_required'] = CRM_Utils_Array::value('is_required', $params, FALSE);
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params, FALSE);
if (isset($params['active_on'])) {
$params['active_on'] = CRM_Utils_Date::processDate($params['active_on'],
CRM_Utils_Array::value('active_on_time', $params),
TRUE
);
}
if (isset($params['expire_on'])) {
$params['expire_on'] = CRM_Utils_Date::processDate($params['expire_on'],
CRM_Utils_Array::value('expire_on_time', $params),
TRUE
);
}
$params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE);
$params['count'] = CRM_Utils_Array::value('count', $params, FALSE);
// need the FKEY - price set id
$params['price_set_id'] = $this->_sid;
if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
$fieldValues = array('price_set_id' => $this->_sid);
$oldWeight = NULL;
if ($this->_fid) {
$oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'weight', 'id');
}
$params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceField', $oldWeight, $params['weight'], $fieldValues);
}
// make value <=> name consistency.
if (isset($params['option_name'])) {
$params['option_value'] = $params['option_name'];
}
$params['is_enter_qty'] = CRM_Utils_Array::value('is_enter_qty', $params, FALSE);
if ($params['html_type'] == 'Text') {
// if html type is Text, force is_enter_qty on
$params['is_enter_qty'] = 1;
// modify params values as per the option group and option
// value
$params['option_amount'] = array(1 => $params['price']);
$params['option_label'] = array(1 => $params['label']);
$params['option_count'] = array(1 => $params['count']);
$params['option_max_value'] = array(1 => CRM_Utils_Array::value('max_value', $params));
//$params['option_description'] = array( 1 => $params['description'] );
$params['option_weight'] = array(1 => $params['weight']);
$params['option_financial_type_id'] = array(1 => $params['financial_type_id']);
$params['option_visibility_id'] = array(1 => CRM_Utils_Array::value('visibility_id', $params));
$params['is_active'] = array(1 => 1);
}
if ($this->_fid) {
$params['id'] = $this->_fid;
}
$params['membership_num_terms'] = (!empty($params['membership_type_id'])) ? CRM_Utils_Array::value('membership_num_terms', $params, 1) : NULL;
$priceField = CRM_Price_BAO_PriceField::create($params);
if (!is_a($priceField, 'CRM_Core_Error')) {
CRM_Core_Session::setStatus(ts('Price Field \'%1\' has been saved.', array(1 => $priceField->label)), ts('Saved'), 'success');
}
$buttonName = $this->controller->getButtonName();
$session = CRM_Core_Session::singleton();
if ($buttonName == $this->getButtonName('next', 'new')) {
CRM_Core_Session::setStatus(ts(' You can add another price set field.'), '', 'info');
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=add&sid=' . $this->_sid));
}
else {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
}
}
}

View file

@ -0,0 +1,357 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* form to process actions on the field aspect of Custom
*/
class CRM_Price_Form_Option extends CRM_Core_Form {
/**
* The price field id saved to the session for an update.
*
* @var int
*/
protected $_fid;
/**
* Option value id, used when editing the Option
*
* @var int
*/
protected $_oid;
/**
* Set variables up before form is built.
*
* @return void
*/
public function preProcess() {
$this->setPageTitle(ts('Price Option'));
$this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive',
$this
);
$this->_oid = CRM_Utils_Request::retrieve('oid', 'Positive',
$this
);
}
/**
* Set default values for the form. Note that in edit/view mode
* the default values are retrieved from the database
*
* @return array|void array of default values
*/
public function setDefaultValues() {
if ($this->_action == CRM_Core_Action::DELETE) {
return NULL;
}
$defaults = array();
if (isset($this->_oid)) {
$params = array('id' => $this->_oid);
CRM_Price_BAO_PriceFieldValue::retrieve($params, $defaults);
// fix the display of the monetary value, CRM-4038
$defaults['value'] = CRM_Utils_Money::format(CRM_Utils_Array::value('value', $defaults), NULL, '%a');
}
$memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
$extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
if (!isset($defaults['membership_num_terms']) && $memberComponentId == $extendComponentId) {
$defaults['membership_num_terms'] = 1;
}
// set financial type used for price set to set default for new option
if (!$this->_oid) {
$defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'financial_type_id', 'id');;
}
if (!isset($defaults['weight']) || !$defaults['weight']) {
$fieldValues = array('price_field_id' => $this->_fid);
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Price_DAO_PriceFieldValue', $fieldValues);
$defaults['is_active'] = 1;
}
return $defaults;
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
if ($this->_action == CRM_Core_Action::UPDATE) {
$finTypeId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $this->_oid, 'financial_type_id');
if (!CRM_Financial_BAO_FinancialType::checkPermissionToEditFinancialType($finTypeId)) {
CRM_Core_Error::fatal(ts("You do not have permission to access this page"));
}
}
if ($this->_action == CRM_Core_Action::DELETE) {
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Delete'),
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
return NULL;
}
else {
$attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
// lets trim all the whitespace
$this->applyFilter('__ALL__', 'trim');
// hidden Option Id for validation use
$this->add('hidden', 'optionId', $this->_oid);
// Needed for i18n dialog
$this->assign('optionId', $this->_oid);
//hidden field ID for validation use
$this->add('hidden', 'fieldId', $this->_fid);
// label
$this->add('text', 'label', ts('Option Label'), NULL, TRUE);
$memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
if ($this->_action == CRM_Core_Action::UPDATE) {
$this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
}
elseif ($this->_action == CRM_Core_Action::ADD ||
$this->_action == CRM_Core_Action::VIEW
) {
$this->_sid = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'price_set_id', 'id');
}
$this->isEvent = FALSE;
$extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
$this->assign('showMember', FALSE);
if ($memberComponentId == $extendComponentId) {
$this->assign('showMember', TRUE);
$membershipTypes = CRM_Member_PseudoConstant::membershipType();
$this->add('select', 'membership_type_id', ts('Membership Type'), array(
'' => ' ',
) + $membershipTypes, FALSE,
array('onClick' => "calculateRowValues( );"));
$this->add('text', 'membership_num_terms', ts('Number of Terms'), $attributes['membership_num_terms']);
}
else {
$allComponents = explode(CRM_Core_DAO::VALUE_SEPARATOR, $extendComponentId);
$eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
if (in_array($eventComponentId, $allComponents)) {
$this->isEvent = TRUE;
// count
$this->add('text', 'count', ts('Participant Count'));
$this->addRule('count', ts('Please enter a valid Max Participants.'), 'positiveInteger');
$this->add('text', 'max_value', ts('Max Participants'));
$this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger');
}
}
//Financial Type
$financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
if (count($financialType)) {
$this->assign('financialType', $financialType);
}
$this->add(
'select',
'financial_type_id',
ts('Financial Type'),
array('' => ts('- select -')) + $financialType,
TRUE
);
//CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_PriceField', $this->_fid, 'weight', 'id' );
// FIX ME: duplicate rule?
/*
$this->addRule( 'label',
ts('Duplicate option label.'),
'optionExists',
array( 'CRM_Core_DAO_OptionValue', $this->_oid, $this->_ogId, 'label' ) );
*/
// value
$this->add('text', 'amount', ts('Option Amount'), NULL, TRUE);
// the above value is used directly by QF, so the value has to be have a rule
// please check with Lobo before u comment this
$this->registerRule('amount', 'callback', 'money', 'CRM_Utils_Rule');
$this->addRule('amount', ts('Please enter a monetary value for this field.'), 'money');
$this->add('text', 'non_deductible_amount', ts('Non-deductible Amount'), NULL);
$this->registerRule('non_deductible_amount', 'callback', 'money', 'CRM_Utils_Rule');
$this->addRule('non_deductible_amount', ts('Please enter a monetary value for this field.'), 'money');
$this->add('textarea', 'description', ts('Description'));
$this->add('textarea', 'help_pre', ts('Pre Option Help'));
$this->add('textarea', 'help_post', ts('Post Option Help'));
// weight
$this->add('text', 'weight', ts('Order'), NULL, TRUE);
$this->addRule('weight', ts('is a numeric field'), 'numeric');
// is active ?
$this->add('checkbox', 'is_active', ts('Active?'));
// is public?
$this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
//is default
$this->add('checkbox', 'is_default', ts('Default'));
if ($this->_fid) {
//hide the default checkbox option for text field
$htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $this->_fid, 'html_type');
$this->assign('hideDefaultOption', FALSE);
if ($htmlType == 'Text') {
$this->assign('hideDefaultOption', TRUE);
}
}
// add buttons
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
// if view mode pls freeze it with the done button.
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
$this->addButtons(array(
array(
'type' => 'cancel',
'name' => ts('Done'),
'isDefault' => TRUE,
),
));
}
}
$this->addFormRule(array('CRM_Price_Form_Option', 'formRule'), $this);
}
/**
* 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) {
$errors = array();
if (!empty($fields['count']) && !empty($fields['max_value']) &&
$fields['count'] > $fields['max_value']
) {
$errors['count'] = ts('Participant count can not be greater than max participants.');
}
$priceField = CRM_Price_BAO_PriceField::findById($fields['fieldId']);
$visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, array('labelColumn' => 'name'));
$publicCount = 0;
$options = CRM_Price_BAO_PriceField::getOptions($priceField->id);
foreach ($options as $currentOption) {
if ($fields['optionId'] == $currentOption['id'] && $visibilityOptions[$fields['visibility_id']] == 'public') {
$publicCount++;
}
elseif ($fields['optionId'] != $currentOption['id'] && $visibilityOptions[$currentOption['visibility_id']] == 'public') {
$publicCount++;
}
}
if ($visibilityOptions[$priceField->visibility_id] == 'public' && $publicCount == 0) {
$errors['visibility_id'] = ts('All other options for this \'Public\' field have \'Admin\' visibility. There should at least be one \'Public\' option, or make the field \'Admin\' only.');
}
elseif ($visibilityOptions[$priceField->visibility_id] == 'admin' && $publicCount > 0) {
$errors['visibility_id'] = ts('You must choose \'Admin\' visibility for this price option, as it belongs to a field with \'Admin\' visibility.');
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form.
*
* @return void
*/
public function postProcess() {
if ($this->_action == CRM_Core_Action::DELETE) {
$fieldValues = array('price_field_id' => $this->_fid);
$wt = CRM_Utils_Weight::delWeight('CRM_Price_DAO_PriceFieldValue', $this->_oid, $fieldValues);
$label = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue',
$this->_oid,
'label', 'id'
);
if (CRM_Price_BAO_PriceFieldValue::del($this->_oid)) {
CRM_Core_Session::setStatus(ts('%1 option has been deleted.', array(1 => $label)), ts('Record Deleted'), 'success');
}
return NULL;
}
else {
$params = $ids = array();
$params = $this->controller->exportValues('Option');
$fieldLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $this->_fid, 'label');
$params['amount'] = CRM_Utils_Rule::cleanMoney(trim($params['amount']));
$params['price_field_id'] = $this->_fid;
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE);
$ids = array();
if ($this->_oid) {
$ids['id'] = $this->_oid;
}
$optionValue = CRM_Price_BAO_PriceFieldValue::create($params, $ids);
CRM_Core_Session::setStatus(ts("The option '%1' has been saved.", array(1 => $params['label'])), ts('Value Saved'), 'success');
}
}
}

View file

@ -0,0 +1,151 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* This class generates form components for previewing custom data
*
* It delegates the work to lower level subclasses and integrates the changes
* back in. It also uses a lot of functionality with the CRM API's, so any change
* made here could potentially affect the API etc. Be careful, be aware, use unit tests.
*
*/
class CRM_Price_Form_Preview extends CRM_Core_Form {
/**
* The group tree data.
*
* @var array
*/
protected $_groupTree;
/**
* Pre processing work done here.
*
* gets session variables for group or field id
*
* @return void
*/
public function preProcess() {
// get the controller vars
$groupId = $this->get('groupId');
$fieldId = $this->get('fieldId');
if ($fieldId) {
$groupTree = CRM_Price_BAO_PriceSet::getSetDetail($groupId);
$this->_groupTree[$groupId]['fields'][$fieldId] = $groupTree[$groupId]['fields'][$fieldId];
$this->assign('preview_type', 'field');
$url = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$groupId}");
$breadCrumb = array(
array(
'title' => ts('Price Set Fields'),
'url' => $url,
),
);
}
else {
// group preview
$this->_groupTree = CRM_Price_BAO_PriceSet::getSetDetail($groupId);
$this->assign('preview_type', 'group');
$this->assign('setTitle', CRM_Price_BAO_PriceSet::getTitle($groupId));
$url = CRM_Utils_System::url('civicrm/admin/price', 'reset=1');
$breadCrumb = array(
array(
'title' => ts('Price Sets'),
'url' => $url,
),
);
}
CRM_Utils_System::appendBreadCrumb($breadCrumb);
}
/**
* Set the default form values.
*
* @return array
* the default array reference
*/
public function setDefaultValues() {
$defaults = array();
$groupId = $this->get('groupId');
$fieldId = $this->get('fieldId');
if (!empty($this->_groupTree[$groupId]['fields'])) {
foreach ($this->_groupTree[$groupId]['fields'] as $key => $val) {
foreach ($val['options'] as $keys => $values) {
if ($values['is_default']) {
if ($val['html_type'] == 'CheckBox') {
$defaults["price_{$key}"][$keys] = 1;
}
else {
$defaults["price_{$key}"] = $keys;
}
}
}
}
}
return $defaults;
}
/**
* Build the form object.
*
* @return void
*/
public function buildQuickForm() {
$this->assign('groupTree', $this->_groupTree);
// add the form elements
foreach ($this->_groupTree as $group) {
if (is_array($group['fields']) && !empty($group['fields'])) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'price_' . $fieldId;
if (!empty($field['options'])) {
CRM_Price_BAO_PriceField::addQuickFormElement($this, $elementName, $fieldId, FALSE, $field['is_required']);
}
}
}
}
$this->addButtons(array(
array(
'type' => 'cancel',
'name' => ts('Done with Preview'),
'isDefault' => TRUE,
),
));
}
}

View file

@ -0,0 +1,306 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* Form to process actions on Price Sets.
*/
class CRM_Price_Form_Set extends CRM_Core_Form {
/**
* The set id saved to the session for an update.
*
* @var int
*/
protected $_sid;
/**
* Set variables up before form is built.
*/
public function preProcess() {
// current set id
$this->_sid = $this->get('sid');
// setting title for html page
$title = ts('New Price Set');
if ($this->_sid) {
$title = CRM_Price_BAO_PriceSet::getTitle($this->_sid);
}
if ($this->_action & CRM_Core_Action::UPDATE) {
$title = ts('Edit %1', array(1 => $title));
}
elseif ($this->_action & CRM_Core_Action::VIEW) {
$title = ts('Preview %1', array(1 => $title));
}
CRM_Utils_System::setTitle($title);
$url = CRM_Utils_System::url('civicrm/admin/price', 'reset=1');
$breadCrumb = array(
array(
'title' => ts('Price Sets'),
'url' => $url,
),
);
CRM_Utils_System::appendBreadCrumb($breadCrumb);
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param array $options
* Additional user data.
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $options) {
$errors = array();
$count = count(CRM_Utils_Array::value('extends', $fields));
//price sets configured for membership
if ($count && array_key_exists(CRM_Core_Component::getComponentID('CiviMember'), $fields['extends'])) {
if ($count > 1) {
$errors['extends'] = ts('If you plan on using this price set for membership signup and renewal, you can not also use it for Events or Contributions. However, a membership price set may include additional fields for non-membership options that require an additional fee (e.g. magazine subscription).');
}
}
// Checks the given price set does not start with a digit
if (strlen($fields['title']) && is_numeric($fields['title'][0])) {
$errors['title'] = ts("Name cannot not start with a digit");
}
return empty($errors) ? TRUE : $errors;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->applyFilter('__ALL__', 'trim');
$this->assign('sid', $this->_sid);
// title
$this->add('text', 'title', ts('Set Name'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title'), TRUE);
$this->addRule('title', ts('Name already exists in Database.'),
'objectExists', array('CRM_Price_DAO_PriceSet', $this->_sid, 'title')
);
$priceSetUsedTables = $extends = array();
if ($this->_action == CRM_Core_Action::UPDATE && $this->_sid) {
$priceSetUsedTables = CRM_Price_BAO_PriceSet::getUsedBy($this->_sid, 'table');
}
$config = CRM_Core_Config::singleton();
$showContribution = FALSE;
$enabledComponents = CRM_Core_Component::getEnabledComponents();
foreach ($enabledComponents as $name => $compObj) {
switch ($name) {
case 'CiviEvent':
$option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Event'));
if (!empty($priceSetUsedTables)) {
foreach (array('civicrm_event', 'civicrm_participant') as $table) {
if (in_array($table, $priceSetUsedTables)) {
$option->freeze();
break;
}
}
}
$extends[] = $option;
break;
case 'CiviContribute':
$option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Contribution'));
if (!empty($priceSetUsedTables)) {
foreach (array('civicrm_contribution', 'civicrm_contribution_page') as $table) {
if (in_array($table, $priceSetUsedTables)) {
$option->freeze();
break;
}
}
}
$extends[] = $option;
break;
case 'CiviMember':
$option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Membership'));
if (!empty($priceSetUsedTables)) {
foreach (array('civicrm_membership', 'civicrm_contribution_page') as $table) {
if (in_array($table, $priceSetUsedTables)) {
$option->freeze();
break;
}
}
}
$extends[] = $option;
break;
}
}
$this->addElement('text', 'min_amount', ts('Minimum Amount'));
if (CRM_Utils_System::isNull($extends)) {
$this->assign('extends', FALSE);
}
else {
$this->assign('extends', TRUE);
}
$this->addGroup($extends, 'extends', ts('Used For'), '&nbsp;', TRUE);
$this->addRule('extends', ts('%1 is a required field.', array(1 => ts('Used For'))), 'required');
// financial type
$financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
foreach ($financialType as $finTypeId => $type) {
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()
&& !CRM_Core_Permission::check('add contributions of type ' . $type)
) {
unset($financialType[$finTypeId]);
}
}
$this->add('select', 'financial_type_id',
ts('Default Financial Type'),
array('' => ts('- select -')) + $financialType, 'required'
);
// help text
$this->add('textarea', 'help_pre', ts('Pre-form Help'),
CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'help_pre')
);
$this->add('textarea', 'help_post', ts('Post-form Help'),
CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'help_post')
);
// is this set active ?
$this->addElement('checkbox', 'is_active', ts('Is this Price Set active?'));
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
$this->addFormRule(array('CRM_Price_Form_Set', 'formRule'));
// views are implemented as frozen form
if ($this->_action & CRM_Core_Action::VIEW) {
$this->freeze();
//$this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/price?reset=1&action=browse'"));
}
}
/**
* Set default values for the form. Note that in edit/view mode.
*
* The default values are retrieved from the database.
*
* @return array
* array of default values
*/
public function setDefaultValues() {
$defaults = array('is_active' => TRUE);
if ($this->_sid) {
$params = array('id' => $this->_sid);
CRM_Price_BAO_PriceSet::retrieve($params, $defaults);
$extends = explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['extends']);
unset($defaults['extends']);
foreach ($extends as $compId) {
$defaults['extends'][$compId] = 1;
}
}
return $defaults;
}
/**
* Process the form.
*/
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);
}
}
}

View file

@ -0,0 +1,343 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying Price Fields.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Price_Page_Field extends CRM_Core_Page {
public $useLivePageJS = TRUE;
/**
* The price set group id of the field.
*
* @var int
*/
protected $_sid;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_actionLinks;
/**
* The price set is reserved or not.
*
* @var boolean
*/
protected $_isSetReserved = FALSE;
/**
* Get the action links for this page.
*
* @return array
* array of action links that we need to display for the browse screen
*/
public static function &actionLinks() {
if (!isset(self::$_actionLinks)) {
self::$_actionLinks = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit Price Field'),
'url' => 'civicrm/admin/price/field',
'qs' => 'action=update&reset=1&sid=%%sid%%&fid=%%fid%%',
'title' => ts('Edit Price'),
),
CRM_Core_Action::PREVIEW => array(
'name' => ts('Preview Field'),
'url' => 'civicrm/admin/price/field',
'qs' => 'action=preview&reset=1&sid=%%sid%%&fid=%%fid%%',
'title' => ts('Preview Price'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Price'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Price'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/price/field',
'qs' => 'action=delete&reset=1&sid=%%sid%%&fid=%%fid%%',
'title' => ts('Delete Price'),
),
);
}
return self::$_actionLinks;
}
/**
* Browse all price set fields.
*/
public function browse() {
$resourceManager = CRM_Core_Resources::singleton();
if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
$resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
}
$priceField = array();
$priceFieldBAO = new CRM_Price_BAO_PriceField();
// fkey is sid
$priceFieldBAO->price_set_id = $this->_sid;
$priceFieldBAO->orderBy('weight, label');
$priceFieldBAO->find();
// display taxTerm for priceFields
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
$getTaxDetails = FALSE;
$taxRate = CRM_Core_PseudoConstant::getTaxRates();
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
while ($priceFieldBAO->fetch()) {
$priceField[$priceFieldBAO->id] = array();
CRM_Core_DAO::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id]);
// get price if it's a text field
if ($priceFieldBAO->html_type == 'Text') {
$optionValues = array();
$params = array('price_field_id' => $priceFieldBAO->id);
CRM_Price_BAO_PriceFieldValue::retrieve($params, $optionValues);
$priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('amount', $optionValues);
$financialTypeId = $optionValues['financial_type_id'];
if ($invoicing && isset($taxRate[$financialTypeId])) {
$priceField[$priceFieldBAO->id]['tax_rate'] = $taxRate[$financialTypeId];
$getTaxDetails = TRUE;
}
if (isset($priceField[$priceFieldBAO->id]['tax_rate'])) {
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceField[$priceFieldBAO->id]['price'], $priceField[$priceFieldBAO->id]['tax_rate'], TRUE);
$priceField[$priceFieldBAO->id]['tax_amount'] = $taxAmount['tax_amount'];
}
}
$action = array_sum(array_keys(self::actionLinks()));
if ($this->_isSetReserved) {
$action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::ENABLE + CRM_Core_Action::DISABLE;
}
else {
if ($priceFieldBAO->is_active) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
}
if ($priceFieldBAO->active_on == '0000-00-00 00:00:00') {
$priceField[$priceFieldBAO->id]['active_on'] = '';
}
if ($priceFieldBAO->expire_on == '0000-00-00 00:00:00') {
$priceField[$priceFieldBAO->id]['expire_on'] = '';
}
// need to translate html types from the db
$htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
$priceField[$priceFieldBAO->id]['html_type_display'] = $htmlTypes[$priceField[$priceFieldBAO->id]['html_type']];
$priceField[$priceFieldBAO->id]['order'] = $priceField[$priceFieldBAO->id]['weight'];
$priceField[$priceFieldBAO->id]['action'] = CRM_Core_Action::formLink(
self::actionLinks(),
$action,
array(
'fid' => $priceFieldBAO->id,
'sid' => $this->_sid,
),
ts('more'),
FALSE,
'priceField.row.actions',
'PriceField',
$priceFieldBAO->id
);
$this->assign('taxTerm', $taxTerm);
$this->assign('getTaxDetails', $getTaxDetails);
}
$returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
$filter = "price_set_id = {$this->_sid}";
CRM_Utils_Weight::addOrder($priceField, 'CRM_Price_DAO_PriceField',
'id', $returnURL, $filter
);
$this->assign('priceField', $priceField);
}
/**
* Edit price data.
*
* editing would involved modifying existing fields + adding data to new fields.
*
* @param string $action
* The action to be invoked.
*/
public function edit($action) {
// create a simple controller for editing price data
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Field', ts('Price Field'), $action);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
$controller->set('sid', $this->_sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
*
* @return void
*/
public function run() {
// get the group id
$this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive',
$this
);
$fid = CRM_Utils_Request::retrieve('fid', 'Positive',
$this, FALSE, 0
);
$action = CRM_Utils_Request::retrieve('action', 'String',
// default to 'browse'
$this, FALSE, 'browse'
);
if ($this->_sid) {
$usedBy = CRM_Price_BAO_PriceSet::getUsedBy($this->_sid);
$this->assign('usedBy', $usedBy);
$this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'is_reserved');
$this->assign('isReserved', $this->_isSetReserved);
CRM_Price_BAO_PriceSet::checkPermission($this->_sid);
$comps = array(
'Event' => 'civicrm_event',
'Contribution' => 'civicrm_contribution_page',
'EventTemplate' => 'civicrm_event_template',
);
$priceSetContexts = array();
foreach ($comps as $name => $table) {
if (array_key_exists($table, $usedBy)) {
$priceSetContexts[] = $name;
}
}
$this->assign('contexts', $priceSetContexts);
}
if ($action & (CRM_Core_Action::DELETE) && !$this->_isSetReserved) {
if (empty($usedBy)) {
// prompt to delete
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', 'Delete Price Field', '');
$controller->set('fid', $fid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
else {
// add breadcrumb
$url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1');
CRM_Utils_System::appendBreadCrumb(ts('Price'),
$url
);
$this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceField::getTitle($fid));
}
}
if ($action & CRM_Core_Action::DELETE) {
CRM_Utils_System::setTitle(ts('Delete Price Field'));
}
elseif ($this->_sid) {
$groupTitle = CRM_Price_BAO_PriceSet::getTitle($this->_sid);
$this->assign('sid', $this->_sid);
$this->assign('groupTitle', $groupTitle);
CRM_Utils_System::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle)));
}
// assign vars to templates
$this->assign('action', $action);
// what action to take ?
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD) && !$this->_isSetReserved) {
// no browse for edit/update/view
$this->edit($action);
}
elseif ($action & CRM_Core_Action::PREVIEW) {
$this->preview($fid);
}
else {
$this->browse();
}
// Call the parents run method
return parent::run();
}
/**
* Preview price field.
*
* @param int $fid
*
* @internal param int $id price field id
*
* @return void
*/
public function preview($fid) {
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Form Field'), CRM_Core_Action::PREVIEW);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
$controller->set('fieldId', $fid);
$controller->set('groupId', $this->_sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
}

View file

@ -0,0 +1,341 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying Custom Options.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Price_Page_Option extends CRM_Core_Page {
public $useLivePageJS = TRUE;
/**
* The field id of the option.
*
* @var int
*/
protected $_fid;
/**
* The field id of the option.
*
* @var int
*/
protected $_sid;
/**
* The price set is reserved or not.
*
* @var boolean
*/
protected $_isSetReserved = FALSE;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_actionLinks;
/**
* Get the action links for this page.
*
* @return array
* array of action links that we need to display for the browse screen
*/
public static function &actionLinks() {
if (!isset(self::$_actionLinks)) {
self::$_actionLinks = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit Option'),
'url' => 'civicrm/admin/price/field/option',
'qs' => 'reset=1&action=update&oid=%%oid%%&fid=%%fid%%&sid=%%sid%%',
'title' => ts('Edit Price Option'),
),
CRM_Core_Action::VIEW => array(
'name' => ts('View'),
'url' => 'civicrm/admin/price/field/option',
'qs' => 'action=view&oid=%%oid%%',
'title' => ts('View Price Option'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Price Option'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Price Option'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/price/field/option',
'qs' => 'action=delete&oid=%%oid%%',
'title' => ts('Disable Price Option'),
),
);
}
return self::$_actionLinks;
}
/**
* Browse all price fields.
*
* @return void
*/
public function browse() {
$priceOptions = civicrm_api3('PriceFieldValue', 'get', array(
'price_field_id' => $this->_fid,
// Explicitly do not check permissions so we are not
// restricted by financial type, so we can change them.
'check_permissions' => FALSE,
'options' => array(
'limit' => 0,
'sort' => array('weight', 'label'),
),
));
$customOption = $priceOptions['values'];
// CRM-15378 - check if these price options are in an Event price set
$isEvent = FALSE;
$extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
$allComponents = explode(CRM_Core_DAO::VALUE_SEPARATOR, $extendComponentId);
$eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
if (in_array($eventComponentId, $allComponents)) {
$isEvent = TRUE;
}
$config = CRM_Core_Config::singleton();
$taxRate = CRM_Core_PseudoConstant::getTaxRates();
// display taxTerm for priceFields
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
$getTaxDetails = FALSE;
foreach ($customOption as $id => $values) {
$action = array_sum(array_keys(self::actionLinks()));
// Adding the required fields in the array
if (isset($taxRate[$values['financial_type_id']])) {
// Cast to float so trailing zero decimals are removed
$customOption[$id]['tax_rate'] = (float) $taxRate[$values['financial_type_id']];
if ($invoicing && isset($customOption[$id]['tax_rate'])) {
$getTaxDetails = TRUE;
}
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($customOption[$id]['amount'], $customOption[$id]['tax_rate'], TRUE);
$customOption[$id]['tax_amount'] = $taxAmount['tax_amount'];
}
if (!empty($values['financial_type_id'])) {
$customOption[$id]['financial_type_id'] = CRM_Contribute_PseudoConstant::financialType($values['financial_type_id']);
}
// update enable/disable links depending on price_field properties.
if ($this->_isSetReserved) {
$action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::DISABLE + CRM_Core_Action::ENABLE;
}
else {
if ($values['is_active']) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
}
if (!empty($customOption[$id]['is_default'])) {
$customOption[$id]['is_default'] = '<img src="' . $config->resourceBase . 'i/check.gif" />';
}
else {
$customOption[$id]['is_default'] = '';
}
$customOption[$id]['order'] = $customOption[$id]['weight'];
$customOption[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action,
array(
'oid' => $id,
'fid' => $this->_fid,
'sid' => $this->_sid,
),
ts('more'),
FALSE,
'priceFieldValue.row.actions',
'PriceFieldValue',
$id
);
}
// Add order changing widget to selector
$returnURL = CRM_Utils_System::url('civicrm/admin/price/field/option', "action=browse&reset=1&fid={$this->_fid}&sid={$this->_sid}");
$filter = "price_field_id = {$this->_fid}";
CRM_Utils_Weight::addOrder($customOption, 'CRM_Price_DAO_PriceFieldValue',
'id', $returnURL, $filter
);
$this->assign('taxTerm', $taxTerm);
$this->assign('getTaxDetails', $getTaxDetails);
$this->assign('customOption', $customOption);
$this->assign('sid', $this->_sid);
$this->assign('isEvent', $isEvent);
}
/**
* Edit custom Option.
*
* editing would involved modifying existing fields + adding data to new fields.
*
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function edit($action) {
$oid = CRM_Utils_Request::retrieve('oid', 'Positive',
$this, FALSE, 0
);
$params = array();
if ($oid) {
$params['oid'] = $oid;
$sid = CRM_Price_BAO_PriceSet::getSetId($params);
$usedBy = CRM_Price_BAO_PriceSet::getUsedBy($sid);
}
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field/option',
"reset=1&action=browse&fid={$this->_fid}&sid={$this->_sid}"
));
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Option', ts('Price Field Option'), $action);
$controller->set('fid', $this->_fid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
if ($action & CRM_Core_Action::DELETE) {
// add breadcrumb
$url = CRM_Utils_System::url('civicrm/admin/price/field/option', 'reset=1');
CRM_Utils_System::appendBreadCrumb(ts('Price Option'),
$url
);
$this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceFieldValue::getOptionLabel($oid));
$this->assign('usedBy', $usedBy);
$comps = array(
"Event" => "civicrm_event",
"Contribution" => "civicrm_contribution_page",
);
$priceSetContexts = array();
foreach ($comps as $name => $table) {
if (array_key_exists($table, $usedBy)) {
$priceSetContexts[] = $name;
}
}
$this->assign('contexts', $priceSetContexts);
}
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
*
* @return void
*/
public function run() {
// get the field id
$this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive',
$this, FALSE, 0
);
//get the price set id
if (!$this->_sid) {
$this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
}
if ($this->_sid) {
CRM_Price_BAO_PriceSet::checkPermission($this->_sid);
$this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'is_reserved');
$this->assign('isReserved', $this->_isSetReserved);
}
//as url contain $sid so append breadcrumb dynamically.
$breadcrumb = array(
array(
'title' => ts('Price Fields'),
'url' => CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&sid=' . $this->_sid),
),
);
CRM_Utils_System::appendBreadCrumb($breadcrumb);
if ($this->_fid) {
$fieldTitle = CRM_Price_BAO_PriceField::getTitle($this->_fid);
$this->assign('fid', $this->_fid);
$this->assign('fieldTitle', $fieldTitle);
CRM_Utils_System::setTitle(ts('%1 - Price Options', array(1 => $fieldTitle)));
$htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $this->_fid, 'html_type');
$this->assign('addMoreFields', TRUE);
//for text price field only single option present
if ($htmlType == 'Text') {
$this->assign('addMoreFields', FALSE);
}
}
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String',
// default to 'browse'
$this, FALSE, 'browse'
);
// assign vars to templates
$this->assign('action', $action);
$oid = CRM_Utils_Request::retrieve('oid', 'Positive',
$this, FALSE, 0
);
// what action to take ?
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD |
CRM_Core_Action::VIEW | CRM_Core_Action::DELETE
) && !$this->_isSetReserved
) {
// no browse for edit/update/view
$this->edit($action);
}
else {
$this->browse();
}
// Call the parents run method
return parent::run();
}
}

View file

@ -0,0 +1,327 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying Price Sets.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Price_Page_Set extends CRM_Core_Page {
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_actionLinks;
/**
* Get the action links for this page.
*
* @return array
* array of action links that we need to display for the browse screen
*/
public function &actionLinks() {
// check if variable _actionsLinks is populated
if (!isset(self::$_actionLinks)) {
// helper variable for nicer formatting
$deleteExtra = ts('Are you sure you want to delete this price set?');
$copyExtra = ts('Are you sure you want to make a copy of this price set?');
self::$_actionLinks = array(
CRM_Core_Action::BROWSE => array(
'name' => ts('View and Edit Price Fields'),
'url' => 'civicrm/admin/price/field',
'qs' => 'reset=1&action=browse&sid=%%sid%%',
'title' => ts('View and Edit Price Fields'),
),
CRM_Core_Action::PREVIEW => array(
'name' => ts('Preview'),
'url' => 'civicrm/admin/price',
'qs' => 'action=preview&reset=1&sid=%%sid%%',
'title' => ts('Preview Price Set'),
),
CRM_Core_Action::UPDATE => array(
'name' => ts('Settings'),
'url' => 'civicrm/admin/price',
'qs' => 'action=update&reset=1&sid=%%sid%%',
'title' => ts('Edit Price Set'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Price Set'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Price Set'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/price',
'qs' => 'action=delete&reset=1&sid=%%sid%%',
'title' => ts('Delete Price Set'),
'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
),
CRM_Core_Action::COPY => array(
'name' => ts('Copy Price Set'),
'url' => CRM_Utils_System::currentPath(),
'qs' => 'action=copy&sid=%%sid%%',
'title' => ts('Make a Copy of Price Set'),
'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
),
);
}
return self::$_actionLinks;
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
* Finally it calls the parent's run method.
*
* @return void
*/
public function run() {
// get the requested action
$action = CRM_Utils_Request::retrieve('action', 'String',
// default to 'browse'
$this, FALSE, 'browse'
);
// assign vars to templates
$this->assign('action', $action);
$sid = CRM_Utils_Request::retrieve('sid', 'Positive',
$this, FALSE, 0
);
if ($sid) {
CRM_Price_BAO_PriceSet::checkPermission($sid);
}
// what action to take ?
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
$this->edit($sid, $action);
}
elseif ($action & CRM_Core_Action::PREVIEW) {
$this->preview($sid);
}
elseif ($action & CRM_Core_Action::COPY) {
CRM_Core_Session::setStatus(ts('A copy of the price set has been created'), ts('Saved'), 'success');
$this->copy();
}
else {
// if action is delete do the needful.
if ($action & (CRM_Core_Action::DELETE)) {
$usedBy = CRM_Price_BAO_PriceSet::getUsedBy($sid);
if (empty($usedBy)) {
// prompt to delete
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/price', 'action=browse'));
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteSet', 'Delete Price Set', NULL);
$controller->set('sid', $sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
else {
// add breadcrumb
$url = CRM_Utils_System::url('civicrm/admin/price', 'reset=1');
CRM_Utils_System::appendBreadCrumb(ts('Price Sets'), $url);
$this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceSet::getTitle($sid));
$this->assign('usedBy', $usedBy);
$comps = array(
'Event' => 'civicrm_event',
'Contribution' => 'civicrm_contribution_page',
'EventTemplate' => 'civicrm_event_template',
);
$priceSetContexts = array();
foreach ($comps as $name => $table) {
if (array_key_exists($table, $usedBy)) {
$priceSetContexts[] = $name;
}
}
$this->assign('contexts', $priceSetContexts);
}
}
// finally browse the price sets
$this->browse();
}
// parent run
return parent::run();
}
/**
* Edit price set.
*
* @param int $sid
* Price set id.
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function edit($sid, $action) {
// create a simple controller for editing price sets
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Set', ts('Price Set'), $action);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price', 'action=browse'));
$controller->set('sid', $sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Preview price set.
*
* @param int $sid
* Price set id.
*
* @return void
*/
public function preview($sid) {
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Price Set'), NULL);
$session = CRM_Core_Session::singleton();
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
if ($context == 'field') {
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', "action=browse&sid={$sid}"));
}
else {
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price', 'action=browse'));
}
$controller->set('groupId', $sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Browse all price sets.
*
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function browse($action = NULL) {
// get all price sets
$priceSet = array();
$comps = array(
'CiviEvent' => ts('Event'),
'CiviContribute' => ts('Contribution'),
'CiviMember' => ts('Membership'),
);
$dao = new CRM_Price_DAO_PriceSet();
if (CRM_Price_BAO_PriceSet::eventPriceSetDomainID()) {
$dao->domain_id = CRM_Core_Config::domainID();
}
$dao->is_quick_config = 0;
$dao->find();
while ($dao->fetch()) {
$priceSet[$dao->id] = array();
CRM_Core_DAO::storeValues($dao, $priceSet[$dao->id]);
$compIds = explode(CRM_Core_DAO::VALUE_SEPARATOR,
CRM_Utils_Array::value('extends', $priceSet[$dao->id])
);
$extends = array();
//CRM-10225
foreach ($compIds as $compId) {
if (!empty($comps[CRM_Core_Component::getComponentName($compId)])) {
$extends[] = $comps[CRM_Core_Component::getComponentName($compId)];
}
}
$priceSet[$dao->id]['extends'] = implode(', ', $extends);
// form all action links
$action = array_sum(array_keys($this->actionLinks()));
// update enable/disable links depending on price_set properties.
if ($dao->is_reserved) {
$action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DISABLE + CRM_Core_Action::ENABLE + CRM_Core_Action::DELETE + CRM_Core_Action::COPY;
}
else {
if ($dao->is_active) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
}
$actionLinks = self::actionLinks();
//CRM-10117
if ($dao->is_reserved) {
$actionLinks[CRM_Core_Action::BROWSE]['name'] = 'View Price Fields';
}
$priceSet[$dao->id]['action'] = CRM_Core_Action::formLink($actionLinks, $action,
array('sid' => $dao->id),
ts('more'),
FALSE,
'priceSet.row.actions',
'PriceSet',
$dao->id
);
}
$this->assign('rows', $priceSet);
}
/**
* make a copy of a price set, including
* all the fields in the page
*
* @return void
*/
public function copy() {
$id = CRM_Utils_Request::retrieve('sid', 'Positive',
$this, TRUE, 0, 'GET'
);
CRM_Price_BAO_PriceSet::copy($id);
CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
}
}