X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FEvent%2FForm%2FRegistration%2FRegister.php;h=7947fdb1ea20b5cee09134cee0431ead438cb9ec;hb=2ab5ff1dbdd3d9457a4297c3004af734b2096fff;hp=df56a419a1c60040d7fad296f02b296c5a23ecf9;hpb=3a28c768118532ff3981f8559500dbf385e6520f;p=civicrm-core.git diff --git a/CRM/Event/Form/Registration/Register.php b/CRM/Event/Form/Registration/Register.php index df56a419a1..7947fdb1ea 100644 --- a/CRM/Event/Form/Registration/Register.php +++ b/CRM/Event/Form/Registration/Register.php @@ -1,7 +1,7 @@ _defaults = array(); + $contactID = $this->getContactID(); if ($contactID) { //@todo CRM-11915 I observed that even when the billing block is not present the routine to retrieve the billing defaults is still called - which seems a bit redundant. - $names = array( - 'first_name', 'middle_name', 'last_name', - "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", - "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}", - ); - - foreach ($names as $name) { - $fields[$name] = 1; - } - $fields["state_province-{$this->_bltID}"] = 1; - $fields["country-{$this->_bltID}"] = 1; - $fields["email-{$this->_bltID}"] = 1; - $fields['email-Primary'] = 1; - - CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults); - - // use primary email address if billing email address is empty - if (empty($this->_defaults["email-{$this->_bltID}"]) && - !empty($this->_defaults['email-Primary']) - ) { - $this->_defaults["email-{$this->_bltID}"] = $this->_defaults['email-Primary']; - } - - foreach ($names as $name) { - if (isset($this->_defaults[$name])) { - $this->_defaults['billing_' . $name] = $this->_defaults[$name]; - } - } + $billingDefaults = $this->getProfileDefaults('Billing', $contactID); + $this->_defaults = array_merge($this->_defaults, $billingDefaults); } $config = CRM_Core_Config::singleton(); // set default country from config if no country set @@ -179,10 +153,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { $this->_defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry; } - // now fix all state country selectors - CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); - if ($this->_snippet) { + // now fix all state country selectors + CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); return $this->_defaults; } @@ -214,6 +187,9 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { CRM_Core_BAO_UFGroup::setProfileDefaults($contactID, $fields, $this->_defaults); } + // now fix all state country selectors + CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); + // Set default payment processor as default payment_processor radio button value if (!empty($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $pid => $value) { @@ -333,6 +309,19 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { * @access public */ public function buildQuickForm() { + // build profiles first so that we can determine address fields etc + // and then show copy address checkbox + $this->buildCustom($this->_values['custom_pre_id'], 'customPre'); + $this->buildCustom($this->_values['custom_post_id'], 'customPost'); + + if (!empty($this->_fields)) { + $profileAddressFields = array(); + foreach ($this->_fields as $key => $value) { + CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields); + } + $this->set('profileAddressFields', $profileAddressFields); + } + // Build payment processor form if ($this->_ppType) { CRM_Core_Payment_ProcessorForm::buildQuickForm($this); @@ -342,11 +331,10 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } } - $contactID = parent::getContactID(); + $contactID = $this->getContactID(); $this->assign('contact_id', $contactID); $this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID)); - $config = CRM_Core_Config::singleton(); $this->add('hidden', 'scriptFee', NULL); $this->add('hidden', 'scriptArray', NULL); @@ -405,9 +393,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { $this->assign('allowGroupOnWaitlist', $allowGroupOnWaitlist); $this->assign('isAdditionalParticipants', $isAdditionalParticipants); - $this->buildCustom($this->_values['custom_pre_id'], 'customPre'); - $this->buildCustom($this->_values['custom_post_id'], 'customPost'); - //lets get js on two different qf elements. $showHidePayfieldName = NULL; $showHidePaymentInformation = FALSE; @@ -415,14 +400,21 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { self::buildAmount($this); } - $pps = NULL; + $pps = array(); + //@todo this processor adding fn is another one duplicated on contribute - a shared + // common class would make this sort of thing extractable if (!empty($this->_paymentProcessors)) { - $pps = $this->_paymentProcessors; - foreach ($pps as $key => & $name) { + foreach ($this->_paymentProcessors as $key => $name) { + if($name['billing_mode'] == 1) { + $onlinePaymentProcessorEnabled = TRUE; + } $pps[$key] = $name['name']; } } - + if($this->getContactID() === '0' && !$this->_values['event']['is_multiple_registrations']) { + //@todo we are blocking for multiple registrations because we haven't tested + $this->addCidZeroOptions($onlinePaymentProcessorEnabled); + } if (CRM_Utils_Array::value('is_pay_later', $this->_values['event']) && ($this->_allowConfirmation || (!$this->_requireApproval && !$this->_allowWaitlist)) ) { @@ -449,7 +441,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { $this->assign('bypassPayment', $bypassPayment); $this->assign('showHidePaymentInformation', $showHidePaymentInformation); - $userID = parent::getContactID(); + $userID = $this->getContactID(); if (!$userID) { $createCMSUser = FALSE; @@ -617,7 +609,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } //build the element. - CRM_Price_BAO_Field::addQuickFormElement($form, + CRM_Price_BAO_PriceField::addQuickFormElement($form, $elementName, $fieldId, FALSE, @@ -833,13 +825,16 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } $lineItem = array(); - CRM_Price_BAO_Set::processAmount($self->_values['fee'], $fields, $lineItem); + CRM_Price_BAO_PriceSet::processAmount($self->_values['fee'], $fields, $lineItem); if ($fields['amount'] < 0) { $errors['_qf_default'] = ts('Event Fee(s) can not be less than zero. Please select the options accordingly'); } } if ($self->_values['event']['is_monetary']) { + if (($fields['amount'] > 0) && !isset($fields['payment_processor'])) { + $errors['payment_processor'] = ts('Please select a Payment Method'); + } if (is_array($self->_paymentProcessor)) { $payment = CRM_Core_Payment::singleton($self->_mode, $self->_paymentProcessor, $this); $error = $payment->checkConfig($self->_mode); @@ -848,7 +843,6 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } } // return if this is express mode - $config = CRM_Core_Config::singleton(); if ($self->_paymentProcessor && $self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON ) { @@ -860,7 +854,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } } - $isZeroAmount = $skipPayementValidation = FALSE; + $isZeroAmount = $skipPaymentValidation = FALSE; if (CRM_Utils_Array::value('priceSetId', $fields)) { if (CRM_Utils_Array::value('amount', $fields) == 0) { $isZeroAmount = TRUE; @@ -882,13 +876,13 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } if ($isZeroAmount && !($self->_forcePayement && CRM_Utils_Array::value('additional_participants', $fields))) { - $skipPayementValidation = TRUE; + $skipPaymentValidation = TRUE; } // also return if paylater mode or zero fees for valid members if (CRM_Utils_Array::value('is_pay_later', $fields) || CRM_Utils_Array::value('bypass_payment', $fields) || - $skipPayementValidation || + $skipPaymentValidation || (!$self->_allowConfirmation && ($self->_requireApproval || $self->_allowWaitlist)) ) { return empty($errors) ? TRUE : $errors; @@ -1041,7 +1035,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { } else { $lineItem = array(); - CRM_Price_BAO_Set::processAmount($this->_values['fee'], $params, $lineItem); + CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem); $this->set('lineItem', array($lineItem)); $this->set('lineItemParticipantsCount', array($primaryParticipantCount)); } @@ -1225,7 +1219,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { $contactID = $value['contact_id']; } else { - $contactID = parent::getContactID(); + $contactID = $this->getContactID(); } CRM_Event_Form_Registration_Confirm::fixLocationFields($value, $fields); @@ -1240,7 +1234,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { // we dont store in userID in case the user is doing multiple // transactions etc // for things like tell a friend - if (!parent::getContactID() && CRM_Utils_Array::value('is_primary', $value)) { + if (!$this->getContactID() && CRM_Utils_Array::value('is_primary', $value)) { $session->set('transaction.userID', $contactID); } @@ -1372,7 +1366,7 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration { $contactID = NULL; $session = CRM_Core_Session::singleton(); if (!$isAdditional) { - $contactID = parent::getContactID(); + $contactID = $self->getContactID(); } if (!$contactID && is_array($fields) && $fields) {