本文整理汇总了PHP中CRM_Core_BAO_Discount类的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Discount类的具体用法?PHP CRM_Core_BAO_Discount怎么用?PHP CRM_Core_BAO_Discount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CRM_Core_BAO_Discount类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createDiscountTrxn
/**
* create trxn entry if an event has discount.
*
* @param int $eventID
* Event id.
* @param array $contributionParams
* Contribution params.
*
* @param $feeLevel
*
*/
public static function createDiscountTrxn($eventID, $contributionParams, $feeLevel)
{
// CRM-11124
$checkDiscount = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event');
if (!empty($checkDiscount)) {
$feeLevel = current($feeLevel);
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID, NULL);
$query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv\nLEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id\nWHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2";
$params = array(1 => array($priceSetId, 'Integer'), 2 => array($feeLevel, 'String'));
$mainAmount = CRM_Core_DAO::singleValueQuery($query, $params);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Discounts Account is' "));
$contributionParams['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType($contributionParams['contribution']->financial_type_id, $relationTypeId);
if (!empty($contributionParams['trxnParams']['from_financial_account_id'])) {
$contributionParams['trxnParams']['total_amount'] = $mainAmount - $contributionParams['total_amount'];
$contributionParams['trxnParams']['payment_processor_id'] = NULL;
$contributionParams['trxnParams']['payment_instrument_id'] = NULL;
$contributionParams['trxnParams']['check_number'] = NULL;
$contributionParams['trxnParams']['trxn_id'] = NULL;
$contributionParams['trxnParams']['net_amount'] = NULL;
$contributionParams['trxnParams']['fee_amount'] = NULL;
CRM_Core_BAO_FinancialTrxn::create($contributionParams['trxnParams']);
}
}
}
示例2: postProcess
/**
* Process the form submission.
*
*
* @return void
*/
public function postProcess()
{
//get the button name.
$button = substr($this->controller->getButtonName(), -4);
//take the participant instance.
$addParticipantNum = substr($this->_name, 12);
//user submitted params.
$params = $this->controller->exportValues($this->_name);
if (!$this->_allowConfirmation) {
// check if the participant is already registered
$params['contact_id'] = CRM_Event_Form_Registration_Register::checkRegistration($params, $this, TRUE, TRUE);
}
//carry campaign to partcipants.
if (array_key_exists('participant_campaign_id', $params)) {
$params['campaign_id'] = $params['participant_campaign_id'];
} else {
$params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
}
// if waiting is enabled
if (!$this->_allowConfirmation && is_numeric($this->_availableRegistrations)) {
$this->_allowWaitlist = FALSE;
//get the current page count.
$currentCount = self::getParticipantCount($this, $params);
if ($button == 'skip') {
$currentCount = 'skip';
}
//get the total count.
$previousCount = self::getParticipantCount($this, $this->_params, TRUE);
$totalParticipants = $previousCount;
if (is_numeric($currentCount)) {
$totalParticipants += $currentCount;
}
if (!empty($this->_values['event']['has_waitlist']) && $totalParticipants > $this->_availableRegistrations) {
$this->_allowWaitlist = TRUE;
}
$this->set('allowWaitlist', $this->_allowWaitlist);
$this->_lineItemParticipantsCount[$addParticipantNum] = $currentCount;
}
if ($button == 'skip') {
//hack for free/zero amount event.
if ($this->_resetAllowWaitlist) {
$this->_allowWaitlist = FALSE;
$this->set('allowWaitlist', FALSE);
if ($this->_requireApproval) {
$status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.");
} else {
$status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list.");
}
CRM_Core_Session::setStatus($status);
}
$this->_params[$addParticipantNum] = 'skip';
if (isset($this->_lineItem)) {
$this->_lineItem[$addParticipantNum] = 'skip';
$this->_lineItemParticipantsCount[$addParticipantNum] = 'skip';
}
} else {
$config = CRM_Core_Config::singleton();
$params['currencyID'] = $config->defaultCurrency;
if ($this->_values['event']['is_monetary']) {
//added for discount
$discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
if (!empty($this->_values['discount'][$discountId])) {
$params['discount_id'] = $discountId;
$params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
$params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
} elseif (empty($params['priceSetId'])) {
$params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
$params['amount'] = $this->_values['fee'][$params['amount']]['value'];
} else {
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
//build line item array..
//if requireApproval/waitlist is enabled we hide fees for primary participant
// (and not for additional participant which might be is a bug)
//lineItem are not correctly build for primary participant
//this results in redundancy since now lineItems for additional participant will be build against primary participantNum
//therefore lineItems must always be build against current participant No
$this->_lineItem[$addParticipantNum] = $lineItem;
}
}
if (array_key_exists('participant_role', $params)) {
$params['participant_role_id'] = $params['participant_role'];
}
if (empty($params['participant_role_id']) && $this->_values['event']['default_role_id']) {
$params['participant_role_id'] = $this->_values['event']['default_role_id'];
}
if (!empty($this->_params[0]['is_pay_later'])) {
$params['is_pay_later'] = 1;
}
//carry additional participant id, contact id if pre-registered.
if ($this->_allowConfirmation && $this->_additionalParticipantId) {
$params['contact_id'] = $this->_contactId;
$params['participant_id'] = $this->_additionalParticipantId;
}
//.........这里部分代码省略.........
示例3: copy
/**
* This function is to make a copy of a Event, including
* all the fields in the event Wizard
*
* @param int $id the event id to copy
*
* @return void
* @access public
*/
static function copy($id)
{
$defaults = $eventValues = array();
//get the require event values.
$eventParams = array('id' => $id);
$returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id');
CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);
// since the location is sharable, lets use the same loc_block_id.
$locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues);
$fieldsFix = array('prefix' => array('title' => ts('Copy of') . ' '));
if (!CRM_Utils_Array::value('is_show_location', $eventValues)) {
$fieldsFix['prefix']['is_show_location'] = 0;
}
$copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : null), $fieldsFix);
$copyPriceSet =& CRM_Core_DAO::copyGeneric('CRM_Price_DAO_SetEntity', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
$copyUF =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
$copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id));
require_once "CRM/Core/BAO/OptionGroup.php";
//copy option Group and values
$copyEvent->default_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_fee_id', $eventValues));
//copy discounted fee levels
require_once 'CRM/Core/BAO/Discount.php';
$discount = CRM_Core_BAO_Discount::getOptionGroup($id, 'civicrm_event');
if (!empty($discount)) {
foreach ($discount as $discountOptionGroup) {
$name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $discountOptionGroup);
$length = substr_compare($name, "civicrm_event.amount." . $id, 0);
$discountSuffix = substr($name, $length * -1);
$copyEvent->default_discount_fee_id = CRM_Core_BAO_OptionGroup::copyValue('event', $id, $copyEvent->id, CRM_Utils_Array::value('default_discount_fee_id', $eventValues), $discountSuffix);
}
}
//copy custom data
require_once 'CRM/Core/BAO/CustomGroup.php';
$extends = array('event');
$groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(null, null, $extends);
if ($groupTree) {
foreach ($groupTree as $groupID => $group) {
$table[$groupTree[$groupID]['table_name']] = array('entity_id');
foreach ($group['fields'] as $fieldID => $field) {
$table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
}
}
foreach ($table as $tableName => $tableColumns) {
$insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') ';
$tableColumns[0] = $copyEvent->id;
$select = 'SELECT ' . implode(', ', $tableColumns);
$from = ' FROM ' . $tableName;
$where = " WHERE {$tableName}.entity_id = {$id}";
$query = $insert . $select . $from . $where;
$dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
}
}
$copyEvent->save();
require_once 'CRM/Utils/Hook.php';
CRM_Utils_Hook::copy('Event', $copyEvent);
return $copyEvent;
}
示例4: postProcess
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess()
{
$params = $this->controller->exportValues($this->_name);
//format params
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
$params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], true);
$params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, false);
$params['is_map'] = CRM_Utils_Array::value('is_map', $params, false);
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
$params['is_public'] = CRM_Utils_Array::value('is_public', $params, false);
$params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, false);
$params['id'] = $this->_id;
//new event, so lets set the created_id
if ($this->_action & CRM_Core_Action::ADD) {
$session =& CRM_Core_Session::singleton();
$params['created_id'] = $session->get('userID');
$params['created_date'] = date('YmdHis');
}
$customFields = CRM_Core_BAO_CustomField::getFields('Event', false, false, CRM_Utils_Array::value('event_type_id', $params));
$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event');
require_once 'CRM/Event/BAO/Event.php';
// copy all not explicitely set $params keys from the template (if it should be sourced)
if (CRM_Utils_Array::value('template_id', $params)) {
$defaults = array();
$templateParams = array('id' => $params['template_id']);
CRM_Event_BAO_Event::retrieve($templateParams, $defaults);
unset($defaults['id']);
unset($defaults['default_fee_id']);
unset($defaults['default_discount_fee_id']);
foreach ($defaults as $key => $value) {
if (!isset($params[$key])) {
$params[$key] = $value;
}
}
}
$event = CRM_Event_BAO_Event::create($params);
// now that we have the event’s id, do some more template-based stuff
if (CRM_Utils_Array::value('template_id', $params)) {
// copy event fees
$ogParams = array('name' => "civicrm_event.amount.{$event->id}");
$defaults = array();
require_once 'CRM/Core/BAO/OptionGroup.php';
if (is_null(CRM_Core_BAO_OptionGroup::retrieve($ogParams, $defaults))) {
// Copy the Main Event Fees
CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id);
// Copy the Discount option Group and Values
require_once 'CRM/Core/BAO/Discount.php';
$optionGroupIds = CRM_Core_BAO_Discount::getOptionGroup($params['template_id'], "civicrm_event");
foreach ($optionGroupIds as $id) {
$discountSuffix = '.discount.' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $id, 'label');
CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id, false, $discountSuffix);
}
}
// copy price sets if any
require_once 'CRM/Price/BAO/Set.php';
$priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']);
if ($priceSetId) {
CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId);
}
// link profiles if none linked
$ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
require_once 'CRM/Core/BAO/UFJoin.php';
if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) {
CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id));
}
// if no Tell-a-Friend defined, check whether there’s one for template and copy if so
$tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
require_once 'CRM/Friend/BAO/Friend.php';
if (!CRM_Friend_BAO_Friend::getValues($tafParams)) {
$tafParams['entity_id'] = $params['template_id'];
if (CRM_Friend_BAO_Friend::getValues($tafParams)) {
$tafParams['entity_id'] = $event->id;
CRM_Friend_BAO_Friend::addTellAFriend($tafParams);
}
}
}
$this->set('id', $event->id);
if ($this->_action & CRM_Core_Action::ADD) {
$urlParam = "action=update&reset=1&subPage=Location&id={$event->id}";
// special case for 'Save and Done' consistency.
if ($this->controller->getButtonName('submit') == "_qf_EventInfo_upload_done") {
$urlParam = "action=update&reset=1&id={$event->id}";
CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())));
}
CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlParam));
}
parent::endPostProcess();
}
示例5: run
/**
* 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
* @access public
*
*/
function run()
{
//get the event id.
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, true);
$config =& CRM_Core_Config::singleton();
require_once 'CRM/Event/BAO/Event.php';
// ensure that the user has permission to see this page
if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW, $this->_id)) {
CRM_Core_Error::fatal(ts('You do not have permission to view this event'));
}
$action = CRM_Utils_Request::retrieve('action', 'String', $this, false);
$context = CRM_Utils_Request::retrieve('context', 'String', $this, false, 'register');
$this->assign('context', $context);
// Sometimes we want to suppress the Event Full msg
$noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, false, 'false');
// set breadcrumb to append to 2nd layer pages
$breadCrumbPath = CRM_Utils_System::url("civicrm/event/info", "id={$this->_id}&reset=1");
$additionalBreadCrumb = "<a href=\"{$breadCrumbPath}\">" . ts('Events') . '</a>';
//retrieve event information
$params = array('id' => $this->_id);
CRM_Event_BAO_Event::retrieve($params, $values['event']);
if (!$values['event']['is_active']) {
// form is inactive, die a fatal death
CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
}
$this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
// show event fees.
require_once 'CRM/Price/BAO/Set.php';
if ($this->_id && CRM_Utils_Array::value('is_monetary', $values['event'])) {
// get price set options, - CRM-5209
if ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $this->_id)) {
$setDetails = CRM_Price_BAO_Set::getSetDetail($priceSetId);
eval("\$priceSetFields = \$setDetails[{$priceSetId}][fields];");
if (is_array($priceSetFields)) {
$fieldCnt = 1;
foreach ($priceSetFields as $fid => $fieldValues) {
if (!is_array($fieldValues['options']) || empty($fieldValues['options'])) {
continue;
}
foreach ($fieldValues['options'] as $optionId => $optionVal) {
$values['feeBlock']['value'][$fieldCnt] = $optionVal['value'];
$values['feeBlock']['label'][$fieldCnt] = $optionVal['description'];
$fieldCnt++;
}
}
}
} else {
//retrieve event fee block.
require_once 'CRM/Core/OptionGroup.php';
require_once 'CRM/Core/BAO/Discount.php';
$discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
if ($discountId) {
CRM_Core_OptionGroup::getAssoc(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'option_group_id'), $values['feeBlock'], false, 'id');
} else {
CRM_Core_OptionGroup::getAssoc("civicrm_event.amount.{$this->_id}", $values['feeBlock']);
}
}
}
$params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
require_once 'CRM/Core/BAO/Location.php';
$values['location'] = CRM_Core_BAO_Location::getValues($params, true);
//retrieve custom field information
require_once 'CRM/Core/BAO/CustomGroup.php';
$groupTree =& CRM_Core_BAO_CustomGroup::getTree("Event", $this, $this->_id, 0, $values['event']['event_type_id']);
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
$this->assign('action', CRM_Core_Action::VIEW);
//To show the event location on maps directly on event info page
$locations =& CRM_Event_BAO_Event::getMapInfo($this->_id);
if (!empty($locations) && CRM_Utils_Array::value('is_map', $values['event'])) {
$this->assign('locations', $locations);
$this->assign('mapProvider', $config->mapProvider);
$this->assign('mapKey', $config->mapAPIKey);
$sumLat = $sumLng = 0;
$maxLat = $maxLng = -400;
$minLat = $minLng = +400;
foreach ($locations as $location) {
$sumLat += $location['lat'];
$sumLng += $location['lng'];
if ($location['lat'] > $maxLat) {
$maxLat = $location['lat'];
}
if ($location['lat'] < $minLat) {
$minLat = $location['lat'];
}
if ($location['lng'] > $maxLng) {
$maxLng = $location['lng'];
}
if ($location['lng'] < $minLng) {
$minLng = $location['lng'];
//.........这里部分代码省略.........
示例6: postProcess
/**
* Process the form.
*/
public function postProcess()
{
$eventTitle = '';
$params = $this->exportValues();
$this->set('discountSection', 0);
if (!empty($_POST['_qf_Fee_submit'])) {
$this->buildAmountLabel();
$this->set('discountSection', 2);
return;
}
if (!empty($params['payment_processor'])) {
$params['payment_processor'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['payment_processor']);
} else {
$params['payment_processor'] = 'null';
}
$params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
$params['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $params, 0);
if ($this->_id) {
// delete all the prior label values or discounts in the custom options table
// and delete a price set if one exists
//@todo note that this removes the reference from existing participants -
// even where there is not change - redress?
// note that a more tentative form of this is invoked by passing price_set_id as an array
// to event.create see CRM-14069
// @todo get all of this logic out of form layer (currently partially in BAO/api layer)
if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_event', $this->_id)) {
CRM_Core_BAO_Discount::del($this->_id, 'civicrm_event');
}
}
if ($params['is_monetary']) {
if (!empty($params['price_set_id'])) {
//@todo this is now being done in the event BAO if passed price_set_id as an array
// per notes on that fn - looking at the api converting to an array
// so calling via the api may cause this to be done in the api
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $params['price_set_id']);
if (!empty($params['price_field_id'])) {
$priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $params['price_field_id'], 'price_set_id');
CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetID, 0);
}
} else {
// if there are label / values, create custom options for them
$labels = CRM_Utils_Array::value('label', $params);
$values = CRM_Utils_Array::value('value', $params);
$default = CRM_Utils_Array::value('default', $params);
$options = array();
if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
for ($i = 1; $i < self::NUM_OPTION; $i++) {
if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
$options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
}
}
if (!empty($options)) {
$params['default_fee_id'] = NULL;
if (empty($params['price_set_id'])) {
if (empty($params['price_field_id'])) {
$setParams['title'] = $eventTitle = $this->_isTemplate ? $this->_defaultValues['template_title'] : $this->_defaultValues['title'];
$eventTitle = strtolower(CRM_Utils_String::munge($eventTitle, '_', 245));
if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle, 'id', 'name')) {
$setParams['name'] = $eventTitle;
} elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceSet', $eventTitle . '_' . $this->_id, 'id', 'name')) {
$setParams['name'] = $eventTitle . '_' . $this->_id;
} else {
$timeSec = explode('.', microtime(TRUE));
$setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1];
}
$setParams['is_quick_config'] = 1;
$setParams['financial_type_id'] = $params['financial_type_id'];
$setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent');
$priceSet = CRM_Price_BAO_PriceSet::create($setParams);
$fieldParams['name'] = strtolower(CRM_Utils_String::munge($params['fee_label'], '_', 245));
$fieldParams['price_set_id'] = $priceSet->id;
} else {
foreach ($params['price_field_value'] as $arrayID => $fieldValueID) {
if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) {
CRM_Price_BAO_PriceFieldValue::setIsActive($fieldValueID, '0');
unset($params['price_field_value'][$arrayID]);
}
}
$fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params);
$fieldParams['option_id'] = $params['price_field_value'];
$priceSet = new CRM_Price_BAO_PriceSet();
$priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id');
if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) {
CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $priceSet->id, 'financial_type_id', $params['financial_type_id']);
}
}
$fieldParams['label'] = $params['fee_label'];
$fieldParams['html_type'] = 'Radio';
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_id, $priceSet->id);
$fieldParams['option_label'] = $params['label'];
$fieldParams['option_amount'] = $params['value'];
$fieldParams['financial_type_id'] = $params['financial_type_id'];
foreach ($options as $value) {
$fieldParams['option_weight'][$value['weight']] = $value['weight'];
}
$fieldParams['default_option'] = $params['default'];
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
//.........这里部分代码省略.........
示例7: setDefaultValues
//.........这里部分代码省略.........
foreach ($val['options'] as $keys => $values) {
if ($values['is_default']) {
if (get_class($form) != 'CRM_Event_Form_Participant' && CRM_Utils_Array::value('is_full', $values)) {
continue;
}
if ($val['html_type'] == 'CheckBox') {
$defaults[$form->_pId]["price_{$key}"][$keys] = 1;
} else {
$defaults[$form->_pId]["price_{$key}"] = $keys;
}
}
}
}
}
$form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
if ($form->_action == CRM_Core_Action::UPDATE) {
$fee_level = $defaults[$form->_pId]['fee_level'];
CRM_Event_BAO_Participant::fixEventLevel($fee_level);
$form->assign('fee_level', $fee_level);
$form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
}
} else {
$optionGroupId = NULL;
// if user has selected discount use that to set default
if (isset($form->_discountId)) {
$defaults[$form->_pId]['discount_id'] = $form->_discountId;
//hack to set defaults for already selected discount value
if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) {
$form->_originalDiscountId = $defaults[$form->_pId]['discount_id'];
if ($form->_originalDiscountId) {
$optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $form->_originalDiscountId, 'option_group_id');
$defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId;
}
}
}
if ($form->_action == CRM_Core_Action::ADD) {
// this case is for add mode, where we show discount automatically
if (!isset($form->_discountId)) {
$discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
} else {
$discountId = $form->_discountId;
}
if ($form->_eventId && $discountId) {
$defaultDiscountId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'default_discount_fee_id');
if ($defaultDiscountId) {
$discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $defaultDiscountId, 'weight');
}
$defaults[$form->_pId]['discount_id'] = $discountId;
$defaults[$form->_pId]['amount'] = key(array_slice($form->_values['discount'][$discountId], $discountKey - 1, $discountKey, TRUE));
$optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'option_group_id');
} else {
if ($form->_eventId) {
$defaults[$form->_pId]['amount'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'default_fee_id');
}
}
}
if (CRM_Utils_Array::value('event_id', $defaults[$form->_pId]) && ($form->_action == CRM_Core_Action::UPDATE || $form->_allowConfirmation)) {
if (!empty($form->_feeBlock)) {
$feeLevel = CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]);
$feeAmount = CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]);
foreach ($form->_feeBlock as $amountId => $amountInfo) {
if ($amountInfo['label'] == $feeLevel && $amountInfo['value'] == $feeAmount) {
$defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
}
// if amount is not set do fuzzy matching
if (!isset($defaults[$form->_pId]['amount'])) {
// if only level use that
if ($amountInfo['label'] == $feeLevel) {
$defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
} elseif (strpos($feeLevel, $amountInfo['label']) !== FALSE) {
$defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
} elseif ($amountInfo['value'] == $feeAmount) {
// if amount matches use that
$defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
}
}
}
}
}
$form->assign('amountId', CRM_Utils_Array::value('amount', $defaults[$form->_pId]));
}
//CRM-4453
if (CRM_Utils_Array::value('participant_fee_currency', $defaults[$form->_pId])) {
$form->assign('fee_currency', $defaults[$form->_pId]['participant_fee_currency']);
}
// CRM-4395
if ($contriId = $form->get('onlinePendingContributionId')) {
$contribution = new CRM_Contribute_DAO_Contribution();
$contribution->id = $contriId;
$contribution->find(TRUE);
foreach (array('contribution_type_id', 'payment_instrument_id', 'contribution_status_id', 'receive_date', 'total_amount') as $f) {
if ($f == 'receive_date') {
list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults($contribution->{$f});
} else {
$defaults[$form->_pId][$f] = $contribution->{$f};
}
}
}
return $defaults[$form->_pId];
}
示例8: postProcess
/**
* Process the form submission.
*/
public function postProcess()
{
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
//set as Primary participant
$params['is_primary'] = 1;
if ($this->_values['event']['is_pay_later'] && (!array_key_exists('hidden_processor', $params) || $params['payment_processor_id'] == 0)) {
$params['is_pay_later'] = 1;
} else {
$params['is_pay_later'] = 0;
}
$this->set('is_pay_later', $params['is_pay_later']);
// assign pay later stuff
$this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
$this->assign('is_pay_later', $params['is_pay_later']);
if ($params['is_pay_later']) {
$this->assign('pay_later_text', $this->_values['event']['pay_later_text']);
$this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
}
if (!$this->_allowConfirmation) {
// check if the participant is already registered
if (!$this->_skipDupeRegistrationCheck) {
$params['contact_id'] = self::checkRegistration($params, $this, FALSE, TRUE, TRUE);
}
}
if (!empty($params['image_URL'])) {
CRM_Contact_BAO_Contact::processImageParams($params);
}
//carry campaign to partcipants.
if (array_key_exists('participant_campaign_id', $params)) {
$params['campaign_id'] = $params['participant_campaign_id'];
} else {
$params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
}
//hack to allow group to register w/ waiting
$primaryParticipantCount = self::getParticipantCount($this, $params);
$totalParticipants = $primaryParticipantCount;
if (!empty($params['additional_participants'])) {
$totalParticipants += $params['additional_participants'];
}
if (!$this->_allowConfirmation && !empty($params['bypass_payment']) && is_numeric($this->_availableRegistrations) && $totalParticipants > $this->_availableRegistrations) {
$this->_allowWaitlist = TRUE;
$this->set('allowWaitlist', TRUE);
}
//carry participant id if pre-registered.
if ($this->_allowConfirmation && $this->_participantId) {
$params['participant_id'] = $this->_participantId;
}
$params['defaultRole'] = 1;
if (array_key_exists('participant_role', $params)) {
$params['participant_role_id'] = $params['participant_role'];
}
if (array_key_exists('participant_role_id', $params)) {
$params['defaultRole'] = 0;
}
if (empty($params['participant_role_id']) && $this->_values['event']['default_role_id']) {
$params['participant_role_id'] = $this->_values['event']['default_role_id'];
}
$config = CRM_Core_Config::singleton();
$params['currencyID'] = $config->defaultCurrency;
if ($this->_values['event']['is_monetary']) {
// we first reset the confirm page so it accepts new values
$this->controller->resetPage('Confirm');
//added for discount
$discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
$params['amount_level'] = $this->getAmountLevel($params, $discountId);
if (!empty($this->_values['discount'][$discountId])) {
$params['discount_id'] = $discountId;
$params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
} elseif (empty($params['priceSetId'])) {
if (!empty($params['amount'])) {
$params['amount'] = $this->_values['fee'][$params['amount']]['value'];
} else {
$params['amount'] = '';
}
} else {
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
if ($params['tax_amount']) {
$this->set('tax_amount', $params['tax_amount']);
}
$submittedLineItems = $this->get('lineItem');
if (!empty($submittedLineItems) && is_array($submittedLineItems)) {
$submittedLineItems[0] = $lineItem;
} else {
$submittedLineItems = array($lineItem);
}
$this->set('lineItem', $submittedLineItems);
$this->set('lineItemParticipantsCount', array($primaryParticipantCount));
}
$this->set('amount', $params['amount']);
$this->set('amount_level', $params['amount_level']);
// generate and set an invoiceID for this transaction
$invoiceID = md5(uniqid(rand(), TRUE));
$this->set('invoiceID', $invoiceID);
if ($this->_paymentProcessor) {
$payment = $this->_paymentProcessor['object'];
//.........这里部分代码省略.........
示例9: postProcess
/**
* Function to process the form
*
* @access public
*
* @return None
*/
public function postProcess()
{
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
//set as Primary participant
$params['is_primary'] = 1;
if ($this->_values['event']['is_pay_later'] && !array_key_exists('hidden_processor', $params)) {
$params['is_pay_later'] = 1;
} else {
$params['is_pay_later'] = 0;
}
$this->set('is_pay_later', $params['is_pay_later']);
// assign pay later stuff
$this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
$this->assign('is_pay_later', $params['is_pay_later']);
if ($params['is_pay_later']) {
$this->assign('pay_later_text', $this->_values['event']['pay_later_text']);
$this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
}
if (!$this->_allowConfirmation) {
// check if the participant is already registered
if (!$this->_skipDupeRegistrationCheck) {
$params['contact_id'] = self::checkRegistration($params, $this, FALSE, TRUE, TRUE);
}
}
if (CRM_Utils_Array::value('image_URL', $params)) {
CRM_Contact_BAO_Contact::processImageParams($params);
}
//carry campaign to partcipants.
if (array_key_exists('participant_campaign_id', $params)) {
$params['campaign_id'] = $params['participant_campaign_id'];
} else {
$params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
}
//hack to allow group to register w/ waiting
$primaryParticipantCount = self::getParticipantCount($this, $params);
$totalParticipants = $primaryParticipantCount;
if (CRM_Utils_Array::value('additional_participants', $params)) {
$totalParticipants += $params['additional_participants'];
}
if (!$this->_allowConfirmation && CRM_Utils_Array::value('bypass_payment', $params) && is_numeric($this->_availableRegistrations) && $totalParticipants > $this->_availableRegistrations) {
$this->_allowWaitlist = TRUE;
$this->set('allowWaitlist', TRUE);
}
//carry participant id if pre-registered.
if ($this->_allowConfirmation && $this->_participantId) {
$params['participant_id'] = $this->_participantId;
}
$params['defaultRole'] = 1;
if (array_key_exists('participant_role', $params)) {
$params['participant_role_id'] = $params['participant_role'];
}
if (array_key_exists('participant_role_id', $params)) {
$params['defaultRole'] = 0;
}
if (!CRM_Utils_Array::value('participant_role_id', $params) && $this->_values['event']['default_role_id']) {
$params['participant_role_id'] = $this->_values['event']['default_role_id'];
}
$config = CRM_Core_Config::singleton();
$params['currencyID'] = $config->defaultCurrency;
if ($this->_values['event']['is_monetary']) {
// we first reset the confirm page so it accepts new values
$this->controller->resetPage('Confirm');
//added for discount
$discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
if (!empty($this->_values['discount'][$discountId])) {
$params['discount_id'] = $discountId;
$params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
$params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
} elseif (empty($params['priceSetId'])) {
if (!empty($params['amount'])) {
$params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
$params['amount'] = $this->_values['fee'][$params['amount']]['value'];
} else {
$params['amount_level'] = $params['amount'] = '';
}
} else {
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
$this->set('lineItem', array($lineItem));
$this->set('lineItemParticipantsCount', array($primaryParticipantCount));
}
$this->set('amount', $params['amount']);
$this->set('amount_level', $params['amount_level']);
// generate and set an invoiceID for this transaction
$invoiceID = md5(uniqid(rand(), TRUE));
$this->set('invoiceID', $invoiceID);
if (is_array($this->_paymentProcessor)) {
$payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
}
// default mode is direct
$this->set('contributeMode', 'direct');
if (isset($params["state_province_id-{$this->_bltID}"]) && $params["state_province_id-{$this->_bltID}"]) {
//.........这里部分代码省略.........
示例10: setIsQuickConfig
/**
* Change is_quick_config priceSet to complex.
*
*/
public static function setIsQuickConfig()
{
$id = $context = NULL;
if (!empty($_REQUEST['id'])) {
$id = CRM_Utils_Type::escape($_REQUEST['id'], 'Integer');
}
if (!empty($_REQUEST['context'])) {
$context = CRM_Utils_Type::escape($_REQUEST['context'], 'String');
}
// return false if $id is null and
// $context is not civicrm_event or civicrm_contribution_page
if (!$id || !in_array($context, array('civicrm_event', 'civicrm_contribution_page'))) {
return FALSE;
}
$priceSetId = CRM_Price_BAO_PriceSet::getFor($context, $id, NULL);
if ($priceSetId) {
$result = CRM_Price_BAO_PriceSet::setIsQuickConfig($priceSetId, 0);
if ($context == 'civicrm_event') {
$sql = "UPDATE\n civicrm_price_set cps\n INNER JOIN civicrm_discount cd ON cd.price_set_id = cps.id\n SET cps.is_quick_config = 0\n WHERE cd.entity_id = (%1) AND cd.entity_table = 'civicrm_event' ";
$params = array(1 => array($id, 'Integer'));
CRM_Core_DAO::executeQuery($sql, $params);
CRM_Core_BAO_Discount::del($id, $context);
}
}
if (!$result) {
$priceSetId = NULL;
}
CRM_Utils_JSON::output($priceSetId);
}
示例11: postProcess
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess()
{
//get the button name.
$button = substr($this->controller->getButtonName(), -4);
//take the participant instance.
$addParticipantNum = substr($this->_name, 12);
if ($button == 'skip') {
//hack for free/zero amount event.
if ($this->_resetAllowWaitlist) {
$this->_allowWaitlist = false;
$this->set('allowWaitlist', false);
if ($this->_requireApproval) {
$status = ts("You have skipped last participant and which result into event having enough spaces, but your registration require approval, Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.");
} else {
$status = ts("You have skipped last participant and which result into event having enough spaces, hence your group become as register participants though you selected on wait list.");
}
CRM_Core_Session::setStatus($status);
}
$this->_params[$addParticipantNum] = 'skip';
if (isset($this->_lineItem)) {
$this->_lineItem[$addParticipantNum] = 'skip';
}
} else {
$params = $this->controller->exportValues($this->_name);
if ($this->_values['event']['is_monetary']) {
//added for discount
require_once 'CRM/Core/BAO/Discount.php';
$discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
if (!empty($this->_values['discount'][$discountId])) {
$params['discount_id'] = $discountId;
$params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
$params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
} else {
if (empty($params['priceSetId'])) {
$params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
$params['amount'] = $this->_values['fee'][$params['amount']]['value'];
} else {
$lineItem = array();
require_once 'CRM/Price/BAO/Set.php';
CRM_Price_BAO_Set::processAmount($this->_values['fee']['fields'], $params, $lineItem);
//build the line item..
if (array_key_exists($addParticipantNum, $this->_lineItem)) {
$this->_lineItem[$addParticipantNum] = $lineItem;
} else {
$this->_lineItem[] = $lineItem;
}
}
}
}
if (!CRM_Utils_Array::value('participant_role_id', $params) && $this->_values['event']['default_role_id']) {
$params['participant_role_id'] = $this->_values['event']['default_role_id'];
}
if (CRM_Utils_Array::value('is_pay_later', $this->_params[0])) {
$params['is_pay_later'] = 1;
}
//carry additional participant id, contact id if pre-registered.
if ($this->_allowConfirmation && $this->_additionalParticipantId) {
$params['contact_id'] = $this->_contactID;
$params['participant_id'] = $this->_additionalParticipantId;
}
//build the params array.
if (array_key_exists($addParticipantNum, $this->_params)) {
$this->_params[$addParticipantNum] = $params;
} else {
$this->_params[] = $params;
}
}
//finally set the params.
$this->set('params', $this->_params);
//set the line item.
if ($this->_lineItem) {
$this->set('lineItem', $this->_lineItem);
}
$participantNo = count($this->_params);
if ($button != 'skip') {
require_once "CRM/Core/Session.php";
$statusMsg = ts('Registration information for participant %1 has been saved.', array(1 => $participantNo));
CRM_Core_Session::setStatus("{$statusMsg}");
}
//to check whether call processRegistration()
if (!$this->_values['event']['is_monetary'] && CRM_Utils_Array::value('additional_participants', $this->_params[0]) && $this->isLastParticipant()) {
require_once 'CRM/Event/Form/Registration/Register.php';
CRM_Event_Form_Registration_Register::processRegistration($this->_params, null);
}
}
示例12: setDefaultValues
//.........这里部分代码省略.........
$defaults[$form->_pId]["price_{$key}"][$keys] = 1;
} else {
$defaults[$form->_pId]["price_{$key}"] = $keys;
}
}
}
}
}
$form->assign('totalAmount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
if ($form->_action == CRM_Core_Action::UPDATE) {
$fee_level = $defaults[$form->_pId]['fee_level'];
CRM_Event_BAO_Participant::fixEventLevel($fee_level);
$form->assign("fee_level", $fee_level);
$form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
}
} else {
$optionGroupId = null;
// if user has selected discount use that to set default
if (isset($form->_discountId)) {
$defaults[$form->_pId]['discount_id'] = $form->_discountId;
//hack to set defaults for already selected discount value
if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) {
$form->_originalDiscountId = $defaults[$form->_pId]['discount_id'];
if ($form->_originalDiscountId) {
$optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_Discount", $form->_originalDiscountId, 'option_group_id');
$defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId;
}
}
}
if ($form->_action == CRM_Core_Action::ADD) {
// this case is for add mode, where we show discount automatically
if (!isset($form->_discountId)) {
require_once 'CRM/Core/BAO/Discount.php';
$discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
} else {
$discountId = $form->_discountId;
}
if ($form->_eventId && $discountId) {
$defaultDiscountId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $form->_eventId, 'default_discount_fee_id');
if ($defaultDiscountId) {
$discountKey = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_OptionValue", $defaultDiscountId, 'weight');
}
$defaults[$form->_pId]['discount_id'] = $discountId;
$defaults[$form->_pId]['amount'] = key(array_slice($form->_values['discount'][$discountId], $discountKey - 1, $discountKey, true));
$optionGroupId = CRM_Core_DAO::getFieldValue("CRM_Core_DAO_Discount", $discountId, 'option_group_id');
} else {
if ($form->_eventId) {
$defaults[$form->_pId]['amount'] = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $form->_eventId, 'default_fee_id');
}
}
}
if (CRM_Utils_Array::value('event_id', $defaults[$form->_pId]) && ($form->_action == CRM_Core_Action::UPDATE || $form->_allowConfirmation)) {
if (!empty($form->_feeBlock)) {
$feeLevel = CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]);
$feeAmount = CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]);
foreach ($form->_feeBlock as $amountId => $amountInfo) {
if ($amountInfo['label'] == $feeLevel && $amountInfo['value'] == $feeAmount) {
$defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
}
// if amount is not set do fuzzy matching
if (!isset($defaults[$form->_pId]['amount'])) {
// if only level use that
if ($amountInfo['label'] == $feeLevel) {
$defaults[$form->_pId]['amount'] = $amountInfo['amount_id'];
} else {
if (strpos($feeLevel, $amountInfo['label']) !== false) {
示例13: postProcess
/**
* Process the form
*
* @return void
* @access public
*/
public function postProcess()
{
$params = array();
$params = $this->exportValues();
$this->set('discountSection', 0);
if (CRM_Utils_Array::value('_qf_Fee_submit', $_POST)) {
$this->buildAmountLabel();
$this->set('discountSection', 1);
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/manage', '#isDiscount'));
return;
}
$params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, 0);
if ($this->_id) {
require_once 'CRM/Price/BAO/Set.php';
// delete all the prior label values or discounts in the custom options table
// and delete a price set if one exists
if (!CRM_Price_BAO_Set::removeFrom('civicrm_event', $this->_id)) {
require_once 'CRM/Core/OptionGroup.php';
CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}");
CRM_Core_OptionGroup::deleteAssoc("civicrm_event.amount.{$this->_id}.discount.%", "LIKE");
}
}
if ($params['is_monetary']) {
if ($params['price_set_id']) {
CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $params['price_set_id']);
} else {
// if there are label / values, create custom options for them
$labels = CRM_Utils_Array::value('label', $params);
$values = CRM_Utils_Array::value('value', $params);
$default = CRM_Utils_Array::value('default', $params);
$options = array();
if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
for ($i = 1; $i < self::NUM_OPTION; $i++) {
if (!empty($labels[$i]) && !CRM_Utils_System::isNull($values[$i])) {
$options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
}
}
if (!empty($options)) {
$params['default_fee_id'] = null;
CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}", $options, $params['default_fee_id']);
}
}
if (CRM_Utils_Array::value('is_discount', $params) == 1) {
// if there are discounted set of label / values,
// create custom options for them
$labels = CRM_Utils_Array::value('discounted_label', $params);
$values = CRM_Utils_Array::value('discounted_value', $params);
$default = CRM_Utils_Array::value('discounted_default', $params);
if (!CRM_Utils_System::isNull($labels) && !CRM_Utils_System::isNull($values)) {
for ($j = 1; $j <= self::NUM_DISCOUNT; $j++) {
$discountOptions = array();
for ($i = 1; $i < self::NUM_OPTION; $i++) {
if (!empty($labels[$i]) && CRM_Utils_Array::value($j, $values[$i])) {
$discountOptions[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i][$j])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i);
}
}
if (!empty($discountOptions)) {
$params['default_discount_fee_id'] = null;
$discountOptionsGroupId = CRM_Core_OptionGroup::createAssoc("civicrm_event.amount.{$this->_id}.discount.{$params['discount_name'][$j]}", $discountOptions, $params['default_discount_fee_id'], $params['discount_name'][$j]);
$discountParams = array('entity_table' => 'civicrm_event', 'entity_id' => $this->_id, 'option_group_id' => $discountOptionsGroupId, 'start_date' => CRM_Utils_Date::format($params["discount_start_date"][$j]), 'end_date' => CRM_Utils_Date::format($params["discount_end_date"][$j]));
require_once 'CRM/Core/BAO/Discount.php';
CRM_Core_BAO_Discount::add($discountParams);
}
}
}
}
}
} else {
$params['contribution_type_id'] = '';
}
//update events table
require_once 'CRM/Event/BAO/Event.php';
$params['id'] = $this->_id;
CRM_Event_BAO_Event::add($params);
parent::endPostProcess();
}
示例14: postProcess
/**
* Function to process the form
*
* @access public
* @return None
*/
public function postProcess()
{
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);
//set as Primary participant
$params['is_primary'] = 1;
//hack to allow group to register w/ waiting
if (!$this->_allowConfirmation && CRM_Utils_Array::value('bypass_payment', $params) && is_numeric($this->_availableRegistrations) && CRM_Utils_Array::value('additional_participants', $params) >= $this->_availableRegistrations) {
$this->_allowWaitlist = true;
$this->set('allowWaitlist', true);
}
//carry participant id if pre-registered.
if ($this->_allowConfirmation && $this->_participantId) {
$params['participant_id'] = $this->_participantId;
}
$params['defaultRole'] = 1;
if (array_key_exists('participant_role_id', $params)) {
$params['defaultRole'] = 0;
}
if (!CRM_Utils_Array::value('participant_role_id', $params) && $this->_values['event']['default_role_id']) {
$params['participant_role_id'] = $this->_values['event']['default_role_id'];
}
if ($this->_values['event']['is_monetary']) {
$config =& CRM_Core_Config::singleton();
// we first reset the confirm page so it accepts new values
$this->controller->resetPage('Confirm');
// get the submitted form values.
$params['currencyID'] = $config->defaultCurrency;
//added for discount
require_once 'CRM/Core/BAO/Discount.php';
$discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
if (!empty($this->_values['discount'][$discountId])) {
$params['discount_id'] = $discountId;
$params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
$params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
} else {
if (empty($params['priceSetId'])) {
$params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
$params['amount'] = $this->_values['fee'][$params['amount']]['value'];
} else {
$lineItem = array();
require_once "CRM/Price/BAO/Set.php";
CRM_Price_BAO_Set::processAmount($this->_values['fee']['fields'], $params, $lineItem);
$priceSet = array();
$priceSet[] = $lineItem;
$this->set('lineItem', $priceSet);
}
}
$this->set('amount', $params['amount']);
$this->set('amount_level', $params['amount_level']);
// generate and set an invoiceID for this transaction
$invoiceID = md5(uniqid(rand(), true));
$this->set('invoiceID', $invoiceID);
if (is_array($this->_paymentProcessor)) {
$payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this);
}
// default mode is direct
$this->set('contributeMode', 'direct');
if (isset($params["state_province_id-{$this->_bltID}"]) && $params["state_province_id-{$this->_bltID}"]) {
$params["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["state_province_id-{$this->_bltID}"]);
}
if (isset($params["country_id-{$this->_bltID}"]) && $params["country_id-{$this->_bltID}"]) {
$params["country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["country_id-{$this->_bltID}"]);
}
if (isset($params['credit_card_exp_date'])) {
$params['year'] = $params['credit_card_exp_date']['Y'];
$params['month'] = $params['credit_card_exp_date']['M'];
}
if ($this->_values['event']['is_monetary']) {
$params['ip_address'] = CRM_Utils_System::ipAddress();
$params['currencyID'] = $config->defaultCurrency;
$params['payment_action'] = 'Sale';
$params['invoiceID'] = $invoiceID;
}
$this->_params = array();
$this->_params[] = $params;
$this->set('params', $this->_params);
if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
//get the button name
$buttonName = $this->controller->getButtonName();
if (in_array($buttonName, array($this->_expressButtonName, $this->_expressButtonName . '_x', $this->_expressButtonName . '_y')) && !isset($params['is_pay_later']) && !$this->_allowWaitlist && !$this->_requireApproval) {
$this->set('contributeMode', 'express');
// Send Event Name & Id in Params
$params['eventName'] = $this->_values['event']['title'];
$params['eventId'] = $this->_values['event']['id'];
$params['cancelURL'] = CRM_Utils_System::url('civicrm/event/register', '_qf_Register_display=1', true, null, false);
if (CRM_Utils_Array::value('additional_participants', $params, false)) {
$urlArgs = "_qf_Participant_1_display=1&rfp=1&qfKey={$this->controller->_key}";
} else {
$urlArgs = '_qf_Confirm_display=1&rfp=1';
}
$params['returnURL'] = CRM_Utils_System::url('civicrm/event/register', $urlArgs, true, null, false);
$params['invoiceID'] = $invoiceID;
//default action is Sale
//.........这里部分代码省略.........
示例15: setDefaultValues
/**
* This function sets the default values for the form in edit/view mode
* the default values are retrieved from the database
*
*
* @param CRM_Core_Form $form
*
* @return void
*/
public static function setDefaultValues(&$form)
{
$defaults = array();
if ($form->_eventId) {
//get receipt text and financial type
$returnProperities = array('confirm_email_text', 'financial_type_id', 'campaign_id', 'start_date');
$details = array();
CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities);
if (!empty($details[$form->_eventId]['financial_type_id'])) {
$defaults[$form->_pId]['financial_type_id'] = $details[$form->_eventId]['financial_type_id'];
}
}
if ($form->_pId) {
$ids = array();
$params = array('id' => $form->_pId);
CRM_Event_BAO_Participant::getValues($params, $defaults, $ids);
if ($form->_action == CRM_Core_Action::UPDATE) {
$discounts = array();
if (!empty($form->_values['discount'])) {
foreach ($form->_values['discount'] as $key => $value) {
$value = current($value);
$discounts[$key] = $value['name'];
}
}
if ($form->_discountId && !empty($discounts[$defaults[$form->_pId]['discount_id']])) {
$form->assign('discount', $discounts[$defaults[$form->_pId]['discount_id']]);
}
$form->assign('fee_amount', CRM_Utils_Array::value('fee_amount', $defaults[$form->_pId]));
$form->assign('fee_level', CRM_Utils_Array::value('fee_level', $defaults[$form->_pId]));
}
$defaults[$form->_pId]['send_receipt'] = 0;
} else {
$defaults[$form->_pId]['send_receipt'] = strtotime(CRM_Utils_Array::value('start_date', $details[$form->_eventId])) >= time() ? 1 : 0;
if ($form->_eventId && !empty($details[$form->_eventId]['confirm_email_text'])) {
//set receipt text
$defaults[$form->_pId]['receipt_text'] = $details[$form->_eventId]['confirm_email_text'];
}
list($defaults[$form->_pId]['receive_date']) = CRM_Utils_Date::setDateDefaults();
}
//CRM-11601 we should keep the record contribution
//true by default while adding participant
if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent) {
$defaults[$form->_pId]['record_contribution'] = 1;
}
//CRM-13420
if (empty($defaults['payment_instrument_id'])) {
$defaults[$form->_pId]['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
}
if ($form->_mode) {
$config = CRM_Core_Config::singleton();
// set default country from config if no country set
if (empty($defaults[$form->_pId]["billing_country_id-{$form->_bltID}"])) {
$defaults[$form->_pId]["billing_country_id-{$form->_bltID}"] = $config->defaultContactCountry;
}
if (empty($defaults["billing_state_province_id-{$form->_bltID}"])) {
$defaults[$form->_pId]["billing_state_province_id-{$form->_bltID}"] = $config->defaultContactStateProvince;
}
$billingDefaults = $form->getProfileDefaults('Billing', $form->_contactId);
$defaults[$form->_pId] = array_merge($defaults[$form->_pId], $billingDefaults);
// // hack to simplify credit card entry for testing
// $defaults[$form->_pId]['credit_card_type'] = 'Visa';
// $defaults[$form->_pId]['credit_card_number'] = '4807731747657838';
// $defaults[$form->_pId]['cvv2'] = '000';
// $defaults[$form->_pId]['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' );
}
// if user has selected discount use that to set default
if (isset($form->_discountId)) {
$defaults[$form->_pId]['discount_id'] = $form->_discountId;
//hack to set defaults for already selected discount value
if ($form->_action == CRM_Core_Action::UPDATE && !$form->_originalDiscountId) {
$form->_originalDiscountId = $defaults[$form->_pId]['discount_id'];
if ($form->_originalDiscountId) {
$defaults[$form->_pId]['discount_id'] = $form->_originalDiscountId;
}
}
$discountId = $form->_discountId;
} else {
$discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
}
if ($discountId) {
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
} else {
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $form->_eventId);
}
if ($form->_action == CRM_Core_Action::ADD && $form->_eventId && $discountId) {
// this case is for add mode, where we show discount automatically
$defaults[$form->_pId]['discount_id'] = $discountId;
}
if ($priceSetId) {
// get price set default values, CRM-4090
if (in_array(get_class($form), array('CRM_Event_Form_Participant', 'CRM_Event_Form_Registration_Register', 'CRM_Event_Form_Registration_AdditionalParticipant'))) {
//.........这里部分代码省略.........