本文整理匯總了PHP中CRM_Price_BAO_PriceFieldValue::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP CRM_Price_BAO_PriceFieldValue::create方法的具體用法?PHP CRM_Price_BAO_PriceFieldValue::create怎麽用?PHP CRM_Price_BAO_PriceFieldValue::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CRM_Price_BAO_PriceFieldValue
的用法示例。
在下文中一共展示了CRM_Price_BAO_PriceFieldValue::create方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: civicrm_api3_price_field_value_create
/**
* Create or update a price_field_value
*
* @param array $params Associative array of property
* name/value pairs to insert in new 'price_field_value'
* @example PriceFieldValueCreate.php Std Create example
*
* @return array api result array
* {@getfields price_field_value_create}
* @access public
*/
function civicrm_api3_price_field_value_create($params)
{
$ids = array();
if (!empty($params['id'])) {
$ids['id'] = $params['id'];
}
$bao = CRM_Price_BAO_PriceFieldValue::create($params, $ids);
$values = array();
_civicrm_api3_object_to_array($bao, $values[$bao->id]);
return civicrm_api3_create_success($values, $params, 'price_field_value', 'create', $bao);
}
示例2: create
/**
* 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 object CRM_Price_DAO_PriceField object
* @access public
* @static
*/
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;
}
$optionsIds = array();
$maxIndex = CRM_Price_Form_Field::NUM_OPTION;
if ($priceField->html_type == 'Text') {
$maxIndex = 1;
$fieldValue = new CRM_Price_DAO_PriceFieldValue();
$fieldValue->price_field_id = $priceField->id;
// update previous field values( if any )
if ($fieldValue->find(TRUE)) {
$optionsIds['id'] = $fieldValue->id;
}
}
$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);
if ($options['membership_type_id']) {
$options['membership_num_terms'] = CRM_Utils_Array::value($index, CRM_Utils_Array::value('membership_num_terms', $params), 1);
}
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;
}
}
CRM_Price_BAO_PriceFieldValue::create($options, $optionsIds);
}
}
$transaction->commit();
return $priceField;
}
示例3: postProcess
/**
* 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);
$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');
}
}