return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
}
+ /**
+ * Reset values for all options those are full.
+ *
+ */
+ public static function resetElementValue($optionFullIds = array(), &$form) {
+ if (!is_array($optionFullIds) ||
+ empty($optionFullIds) ||
+ !$form->isSubmitted()
+ ) {
+ return;
+ }
+
+ foreach ($optionFullIds as $fldId => $optIds) {
+ $name = "price_$fldId";
+ if (!$form->elementExists($name)) {
+ continue;
+ }
+
+ $element = $form->getElement($name);
+ $eleType = $element->getType();
+
+ $resetSubmitted = FALSE;
+ switch ($eleType) {
+ case 'text':
+ if ($element->getValue() && $element->isFrozen()) {
+ $label = "{$element->getLabel()}<tt>(x)</tt>";
+ $element->setLabel($label);
+ $element->setPersistantFreeze();
+ $resetSubmitted = TRUE;
+ }
+ break;
+
+ case 'group':
+ if (is_array($element->_elements)) {
+ foreach ($element->_elements as $child) {
+ $childType = $child->getType();
+ $methodName = 'getName';
+ if ($childType) {
+ $methodName = 'getValue';
+ }
+ if (in_array($child->{$methodName}(), $optIds) && $child->isFrozen()) {
+ $resetSubmitted = TRUE;
+ $child->setPersistantFreeze();
+ }
+ }
+ }
+ break;
+
+ case 'select':
+ if (in_array($element->getValue()[0], $optIds)) {
+ foreach ($element->_options as $option) {
+ if ($option['attr']['value'] === "crm_disabled_opt-{$element->getValue()[0]}") {
+ $placeholder = html_entity_decode($option['text']);
+ $element->updateAttributes(array('placeholder' => $placeholder));
+ break;
+ }
+ }
+ $resetSubmitted = TRUE;
+ }
+ break;
+ }
+
+ //finally unset values from submitted.
+ if ($resetSubmitted) {
+ self::resetSubmittedValue($name, $optIds, $form);
+ }
+ }
+ }
+
+ /**
+ * @param string $elementName
+ * @param array $optionIds
+ */
+ public static function resetSubmittedValue($elementName, $optionIds = array(), &$form) {
+ if (empty($elementName) ||
+ !$form->elementExists($elementName) ||
+ !$form->getSubmitValue($elementName)
+ ) {
+ return;
+ }
+ foreach (array(
+ 'constantValues',
+ 'submitValues',
+ 'defaultValues',
+ ) as $val) {
+ $values = $form->{"_$val"};
+ if (!is_array($values) || empty($values)) {
+ continue;
+ }
+ $eleVal = CRM_Utils_Array::value($elementName, $values);
+ if (empty($eleVal)) {
+ continue;
+ }
+ if (is_array($eleVal)) {
+ $found = FALSE;
+ foreach ($eleVal as $keyId => $ignore) {
+ if (in_array($keyId, $optionIds)) {
+ $found = TRUE;
+ unset($values[$elementName][$keyId]);
+ }
+ }
+ if ($found && empty($values[$elementName][$keyId])) {
+ $values[$elementName][$keyId] = NULL;
+ }
+ }
+ else {
+ if (!empty($keyId)) {
+ $values[$elementName][$keyId] = NULL;
+ }
+ }
+ }
+ }
+
/**
* Validate price set submitted params for price option limit,
* as well as user should select at least one price field option.
$optionMaxValues[$priceFieldId][$optId]
= $currentMaxValue + CRM_Utils_Array::value($optId, CRM_Utils_Array::value($priceFieldId, $optionMaxValues), 0);
}
-
+ $soldOutPnum[$optId] = $pNum;
}
}
+
+ //validate for price field selection.
+ if (empty($fieldSelected[$pNum])) {
+ $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
+ }
}
//validate for option max value.
$optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
$opDbCount = CRM_Utils_Array::value('db_total_count', $options[$optId], 0);
$total += $opDbCount;
- if ($optMax && $total > $optMax) {
- $errors['soldOutOptions'][] = ts('Option %1 has sold out.', array(1 => $feeBlock[$fieldId]['options'][$optId]['label']));
+ if ($optMax && ($total > $optMax)) {
if ($opDbCount && ($opDbCount >= $optMax)) {
- $errors[$currentParticipantNum]["price_{$fieldId}"]
+ $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
= ts('Sorry, this option is currently sold out.');
}
elseif (($optMax - $opDbCount) == 1) {
- $errors[$currentParticipantNum]["price_{$fieldId}"]
+ $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
= ts('Sorry, currently only a single seat is available for this option.', array(1 => ($optMax - $opDbCount)));
}
else {
- $errors[$currentParticipantNum]["price_{$fieldId}"]
+ $errors[$soldOutPnum[$optId]]["price_{$fieldId}"]
= ts('Sorry, currently only %1 seats are available for this option.', array(1 => ($optMax - $opDbCount)));
}
}
}
}
-
- //validate for price field selection.
- foreach ($params as $pNum => $values) {
- if (!is_array($values) || $values == 'skip') {
- continue;
- }
- if (empty($fieldSelected[$pNum])) {
- $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
- }
- }
-
return $errors;
}
$defaults = array_merge($this->_defaults, $defaults);
//reset values for all options those are full.
- if (!empty($unsetSubmittedOptions) && empty($_POST)) {
- $this->resetElementValue($unsetSubmittedOptions);
- }
+ CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
//load default campaign from page.
if (array_key_exists('participant_campaign_id', $this->_fields)) {
$payment_processor_id = $self->params[0]['payment_processor_id'];
CRM_Core_Payment_Form::validatePaymentInstrument($payment_processor_id, $self->_params[0], $errors, $self);
- if ($errors) {
+ if (!empty($errors)) {
return FALSE;
}
$lineItem = array();
CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
- //build the line item..
- if (array_key_exists($addParticipantNum, $this->_lineItem)) {
- $this->_lineItem[$addParticipantNum] = $lineItem;
- }
- else {
- $this->_lineItem[] = $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;
}
}
}
//build the params array.
- if (array_key_exists($addParticipantNum, $this->_params)) {
- $this->_params[$addParticipantNum] = $params;
- }
- else {
- $this->_params[] = $params;
- }
+ $this->_params[$addParticipantNum] = $params;
}
//finally set the params.
}
return FALSE;
}
-
- /**
- * Reset values for all options those are full.
- *
- */
- public function resetElementValue($optionFullIds = array()) {
- if (!is_array($optionFullIds) ||
- empty($optionFullIds) ||
- !$this->isSubmitted()
- ) {
- return;
- }
-
- foreach ($optionFullIds as $fldId => $optIds) {
- $name = "price_$fldId";
- if (!$this->elementExists($name)) {
- continue;
- }
-
- $element = $this->getElement($name);
- $eleType = $element->getType();
-
- $resetSubmitted = FALSE;
- switch ($eleType) {
- case 'text':
- if ($element->isFrozen()) {
- $element->setValue('');
- $resetSubmitted = TRUE;
- }
- break;
-
- case 'group':
- if (is_array($element->_elements)) {
- foreach ($element->_elements as $child) {
- $childType = $child->getType();
- $methodName = 'getName';
- if ($childType) {
- $methodName = 'getValue';
- }
- if (in_array($child->{$methodName}(), $optIds) && $child->isFrozen()) {
- $resetSubmitted = TRUE;
- $child->updateAttributes(array('checked' => NULL));
- }
- }
- }
- break;
-
- case 'select':
- $resetSubmitted = TRUE;
- $element->_values = array();
- break;
- }
-
- //finally unset values from submitted.
- if ($resetSubmitted) {
- $this->resetSubmittedValue($name, $optIds);
- }
- }
- }
-
- /**
- * @param string $elementName
- * @param array $optionIds
- */
- public function resetSubmittedValue($elementName, $optionIds = array()) {
- if (empty($elementName) ||
- !$this->elementExists($elementName) ||
- !$this->getSubmitValue($elementName)
- ) {
- return;
- }
- foreach (array(
- 'constantValues',
- 'submitValues',
- 'defaultValues',
- ) as $val) {
- $values = &$this->{"_$val"};
- if (!is_array($values) || empty($values)) {
- continue;
- }
- $eleVal = CRM_Utils_Array::value($elementName, $values);
- if (empty($eleVal)) {
- continue;
- }
- if (is_array($eleVal)) {
- $found = FALSE;
- foreach ($eleVal as $keyId => $ignore) {
- if (in_array($keyId, $optionIds)) {
- $found = TRUE;
- unset($values[$elementName][$keyId]);
- }
- }
- if ($found && empty($values[$elementName][$keyId])) {
- $values[$elementName][$keyId] = NULL;
- }
- }
- else {
- $values[$elementName][$keyId] = NULL;
- }
- }
- }
-
}
$self->_feeBlock = $self->_values['fee'];
CRM_Event_Form_Registration_Register::formatFieldsForOptionFull($self);
- if (!empty($self->_priceSetId)) {
+ if (!empty($self->_priceSetId) &&
+ !$self->_requireApproval && !$self->_allowWaitlist
+ ) {
$priceSetErrors = self::validatePriceSet($self, $self->_params);
- //get price set fields errors in.
- $errors = array_merge($errors, CRM_Utils_Array::value(0, $priceSetErrors, array()));
+ if (!empty($priceSetErrors)) {
+ CRM_Core_Session::setStatus(ts('You have been returned to the start of the registration process and any sold out events have been removed from your selections. You will not be able to continue until you review your booking and select different events if you wish. The following events were sold out:'), ts('Unfortunately some of your options have now sold out for one or more participants.'), 'error');
+ CRM_Core_Session::setStatus(ts('Please note that the options which are marked or selected are sold out for participant being viewed.'), ts('Sold out:'), 'error');
+ CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "_qf_Register_display=true&qfKey={$fields['qfKey']}"));
+ }
}
- if (!empty($errors)) {
- $soldOutOptions = implode("<br/>", $priceSetErrors['soldOutOptions']);
- CRM_Core_Session::setStatus(ts('You have been returned to the start of the registration process and any sold out events have been removed from your selections. You will not be able to continue until you review your booking and select different events if you wish. The following events were sold out:'), ts('Unfortunately some of your options have now sold out for one or more participants.'), 'error');
- CRM_Core_Session::setStatus(ts("{$soldOutOptions}"), ts('Sold out:'), 'error');
- CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/register', "_qf_Register_display=true&qfKey=" . $fields['qfKey']));
- }
- return empty($errors) ? TRUE : $errors;
+ return empty($priceSetErrors) ? TRUE : $priceSetErrors;
}
/**
}
if ($this->_priceSetId && !empty($this->_feeBlock)) {
foreach ($this->_feeBlock as $key => $val) {
+ if (empty($val['options'])) {
+ continue;
+ }
+ $optionFullIds = CRM_Utils_Array::value('option_full_ids', $val, array());
foreach ($val['options'] as $keys => $values) {
if ($values['is_default'] && empty($values['is_full'])) {
}
}
}
+ $unsetSubmittedOptions[$val['id']] = $optionFullIds;
}
+ //reset values for all options those are full.
+ CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
}
//set default participant fields, CRM-4320.
$currentOptionsCount = self::getPriceSetOptionCount($form);
$recordedOptionsCount = CRM_Event_BAO_Participant::priceSetOptionsCount($form->_eventId, $skipParticipants);
$optionFullTotalAmount = 0;
-
+ $currentParticipantNo = (int) substr($form->_name, 12);
foreach ($form->_feeBlock as & $field) {
$optionFullIds = array();
$fieldId = $field['id'];
$totalCount = $currentTotalCount + $dbTotalCount;
$isFull = FALSE;
if ($maxValue &&
- (($totalCount > $maxValue) || ($totalCount + $count > $maxValue))
+ (($totalCount >= $maxValue) &&
+ (empty($form->_lineItem[$currentParticipantNo][$optId]['price_field_id']) || $dbTotalCount >= $maxValue))
) {
$isFull = TRUE;
$optionFullIds[$optId] = $optId;
}
// priceset validations
- if (!empty($fields['priceSetId'])) {
+ if (!empty($fields['priceSetId']) &&
+ !$self->_requireApproval && !$self->_allowWaitlist
+ ) {
//format params.
$formatted = self::formatPriceSetParams($self, $fields);
$ppParams = array($formatted);
if ($params['tax_amount']) {
$this->set('tax_amount', $params['tax_amount']);
}
- $this->set('lineItem', array($lineItem));
+ if (!empty($this->get('lineItem')) && is_array($this->get('lineItem'))) {
+ $submittedLineItems = $this->get('lineItem');
+ $submittedLineItems[0] = $lineItem;
+ }
+ else {
+ $submittedLineItems = array($lineItem);
+ }
+ $this->set('lineItem', $submittedLineItems);
$this->set('lineItemParticipantsCount', array($primaryParticipantCount));
}
$params['invoiceID'] = $invoiceID;
}
- $this->_params = array();
- $this->_params[] = $params;
+ if (!empty($this->get('params')) && is_array($this->get('params'))) {
+ $this->_params = $this->get('params');
+ $this->_params[0] = $params;
+ }
+ else {
+ $this->_params = array();
+ $this->_params[] = $params;
+ }
$this->set('params', $this->_params);
if ($this->_paymentProcessor &&
// CRM-6902 - Add "max" option for a price set field
if (in_array($optionKey, $freezeOptions)) {
- self::freezeIfEnabled($element, $freezeOptions);
+ self::freezeIfEnabled($element, $fieldOptions[$optionKey]);
// CRM-14696 - Improve display for sold out price set options
$element->setLabel($label . ' <span class="sold-out-option">' . ts('Sold out') . '</span>');
}
}
}
- $selectOption[$opt['id']] = $opt['label'];
$priceVal[$opt['id']] = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value));
if (!in_array($opt['id'], $freezeOptions)) {
}
// 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') . ')';
}
'' => ts('- select -'),
) + $selectOption,
$useRequired && $field->is_required,
- array('price' => json_encode($priceVal))
+ array('price' => json_encode($priceVal), 'class' => 'crm-select2')
);
// CRM-6902 - Add "max" option for a price set field