+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
*
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
class CRM_Event_Form_Registration_AdditionalParticipant extends CRM_Event_Form_Registration {
/**
- * The defaults involved in this page
+ * The defaults involved in this page.
*/
public $_defaults = array();
public $additionalParticipantId = NULL;
/**
- * Set variables up before form is built
+ * Set variables up before form is built.
*
* @return void
*/
$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)) {
}
/**
- * Build the form object
+ * Build the form object.
*
* @return void
*/
}
/**
- * Global form rule
+ * Global form rule.
*
* @param array $fields
* The input form values.
CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors);
- // make sure that credit card number and cvv are valid
- CRM_Core_Payment_Form::validateCreditCard($self->_params[0], $errors);
+ // validate supplied payment instrument values (e.g. credit card number and cvv)
+ $payment_processor_id = $self->_params[0]['payment_processor'];
+ CRM_Core_Payment_Form::validatePaymentInstrument($payment_processor_id, $self->_params[0], $errors, $self);
- if ($errors) {
+ if (!empty($errors)) {
return FALSE;
}
}
}
}
+ return TRUE;
}
/**
- * Process the form submission
+ * Process the form submission.
*
*
* @return void
$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.
}
/**
- * Check whether call current participant is last one
+ * Check whether call current participant is last one.
*
* @param bool $isButtonJs
*
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;
- }
- }
- }
-
}