In order to resolve the conflict on 'protected' I moved functions where it was accessed form ->_paymentProcessors
to an inherited form class. In general the moves make sense - ie. having a function on contribution shared by event is not good,
Nor is having a function on the BAO called by forms.
if (isset($params['selectMembership']) &&
$params['selectMembership'] != 'no_thanks'
) {
- CRM_Member_BAO_Membership::buildMembershipBlock($this,
- $this->_id,
+ $this->buildMembershipBlock(
$this->_membershipContactID,
FALSE,
$params['selectMembership'],
public function preProcess() {
parent::preProcess();
- self::preProcessPaymentOptions($this);
+ $this->_paymentProcessors = $this->get('paymentProcessors');
+ $this->preProcessPaymentOptions();
// Make the contributionPageID available to the template
$this->assign('contributionPageID', $this->_id);
$this->set('useForMember', $this->_useForMember);
}
- $this->_separateMembershipPayment = CRM_Member_BAO_Membership::buildMembershipBlock($this,
- $this->_id,
+ $this->_separateMembershipPayment = $this->buildMembershipBlock(
$this->_membershipContactID,
TRUE, NULL, FALSE,
$isTest
}
- /**
- * Handle Payment Processor switching for contribution and event registration forms.
- *
- * @param CRM_Contribute_Form_Contribution_Main|CRM_Event_Form_Registration_Register $form
- * @param bool $noFees
- */
- public static function preProcessPaymentOptions(&$form, $noFees = FALSE) {
- $form->_snippet = CRM_Utils_Array::value('snippet', $_GET);
-
- $form->_paymentProcessors = $noFees ? array() : $form->get('paymentProcessors');
- $form->_paymentProcessorID = NULL;
- if ($form->_paymentProcessors) {
- if (!empty($form->_submitValues)) {
- $form->_paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $form->_submitValues);
- $form->_paymentProcessor = CRM_Utils_Array::value($form->_paymentProcessorID, $form->_paymentProcessors);
- $form->set('type', $form->_paymentProcessorID);
- $form->set('mode', $form->_mode);
- $form->set('paymentProcessor', $form->_paymentProcessor);
- }
- // Set default payment processor
- else {
- foreach ($form->_paymentProcessors as $values) {
- if (!empty($values['is_default']) || count($form->_paymentProcessors) == 1) {
- $form->_paymentProcessorID = $values['id'];
- break;
- }
- }
- }
- if ($form->_paymentProcessorID) {
- CRM_Core_Payment_ProcessorForm::preProcess($form);
- }
- else {
- $form->_paymentProcessor = array();
- }
- CRM_Financial_Form_Payment::addCreditCardJs();
- }
- $form->assign('paymentProcessorID', $form->_paymentProcessorID);
- }
-
/**
* @param $invoiceID
* @param $params
$this->assign('membership_amount', $membershipAmount);
$this->assign('renewal_mode', $renewalMode);
- CRM_Member_BAO_Membership::buildMembershipBlock($this,
- $this->_id,
+ $this->buildMembershipBlock(
$this->_membershipContactID,
FALSE,
$membershipTypeID,
}
}
+ /**
+ * Build Membership Block in Contribution Pages.
+ *
+ * @param CRM_Core_Form $form
+ * Form object.
+ * @param int $pageID
+ * Unused?.
+ * @param int $cid
+ * Contact checked for having a current membership for a particular membership.
+ * @param bool $formItems
+ * @param int $selectedMembershipTypeID
+ * Selected membership id.
+ * @param bool $thankPage
+ * Thank you page.
+ * @param null $isTest
+ *
+ * @return bool
+ * Is this a separate membership payment
+ */
+ protected function buildMembershipBlock(
+ $cid,
+ $formItems = FALSE,
+ $selectedMembershipTypeID = NULL,
+ $thankPage = FALSE,
+ $isTest = NULL
+ ) {
+
+ $separateMembershipPayment = FALSE;
+ if ($this->_membershipBlock) {
+ $this->_currentMemberships = array();
+
+ $membershipBlock = $this->_membershipBlock;
+ $membershipTypeIds = $membershipTypes = $radio = array();
+ $membershipPriceset = (!empty($this->_priceSetId) && $this->_useForMember) ? TRUE : FALSE;
+
+ $allowAutoRenewMembership = $autoRenewOption = FALSE;
+ $autoRenewMembershipTypeOptions = array();
+
+ $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
+
+ $separateMembershipPayment = CRM_Utils_Array::value('is_separate_payment', $membershipBlock);
+
+ if ($membershipPriceset) {
+ foreach ($this->_priceSet['fields'] as $pField) {
+ if (empty($pField['options'])) {
+ continue;
+ }
+ foreach ($pField['options'] as $opId => $opValues) {
+ if (empty($opValues['membership_type_id'])) {
+ continue;
+ }
+ $membershipTypeIds[$opValues['membership_type_id']] = $opValues['membership_type_id'];
+ }
+ }
+ }
+ elseif (!empty($membershipBlock['membership_types'])) {
+ $membershipTypeIds = explode(',', $membershipBlock['membership_types']);
+ }
+
+ if (!empty($membershipTypeIds)) {
+ //set status message if wrong membershipType is included in membershipBlock
+ if (isset($this->_mid) && !$membershipPriceset) {
+ $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
+ $this->_mid,
+ 'membership_type_id'
+ );
+ if (!in_array($membershipTypeID, $membershipTypeIds)) {
+ CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Invalid Membership'), 'error');
+ }
+ }
+
+ $membershipTypeValues = self::buildMembershipTypeValues($this, $membershipTypeIds);
+ $this->_membershipTypeValues = $membershipTypeValues;
+ $endDate = NULL;
+ foreach ($membershipTypeIds as $value) {
+ $memType = $membershipTypeValues[$value];
+ if ($selectedMembershipTypeID != NULL) {
+ if ($memType['id'] == $selectedMembershipTypeID) {
+ $this->assign('minimum_fee',
+ CRM_Utils_Array::value('minimum_fee', $memType)
+ );
+ $this->assign('membership_name', $memType['name']);
+ if (!$thankPage && $cid) {
+ $membership = new CRM_Member_DAO_Membership();
+ $membership->contact_id = $cid;
+ $membership->membership_type_id = $memType['id'];
+ if ($membership->find(TRUE)) {
+ $this->assign('renewal_mode', TRUE);
+ $memType['current_membership'] = $membership->end_date;
+ $this->_currentMemberships[$membership->membership_type_id] = $membership->membership_type_id;
+ }
+ }
+ $membershipTypes[] = $memType;
+ }
+ }
+ elseif ($memType['is_active']) {
+ $javascriptMethod = NULL;
+ $allowAutoRenewOpt = 1;
+ if (is_array($this->_paymentProcessors)) {
+ foreach ($this->_paymentProcessors as $id => $val) {
+ if (!$val['is_recur']) {
+ $allowAutoRenewOpt = 0;
+ continue;
+ }
+ }
+ }
+
+ $javascriptMethod = array('onclick' => "return showHideAutoRenew( this.value );");
+ $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = (int) $allowAutoRenewOpt * CRM_Utils_Array::value($value, CRM_Utils_Array::value('auto_renew', $this->_membershipBlock));;
+
+ if ($allowAutoRenewOpt) {
+ $allowAutoRenewMembership = TRUE;
+ }
+
+ //add membership type.
+ $radio[$memType['id']] = $this->createElement('radio', NULL, NULL, NULL,
+ $memType['id'], $javascriptMethod
+ );
+ if ($cid) {
+ $membership = new CRM_Member_DAO_Membership();
+ $membership->contact_id = $cid;
+ $membership->membership_type_id = $memType['id'];
+
+ //show current membership, skip pending and cancelled membership records,
+ //because we take first membership record id for renewal
+ $membership->whereAdd('status_id != 5 AND status_id !=6');
+
+ if (!is_null($isTest)) {
+ $membership->is_test = $isTest;
+ }
+
+ //CRM-4297
+ $membership->orderBy('end_date DESC');
+
+ if ($membership->find(TRUE)) {
+ if (!$membership->end_date) {
+ unset($radio[$memType['id']]);
+ $this->assign('islifetime', TRUE);
+ continue;
+ }
+ $this->assign('renewal_mode', TRUE);
+ $this->_currentMemberships[$membership->membership_type_id] = $membership->membership_type_id;
+ $memType['current_membership'] = $membership->end_date;
+ if (!$endDate) {
+ $endDate = $memType['current_membership'];
+ $this->_defaultMemTypeId = $memType['id'];
+ }
+ if ($memType['current_membership'] < $endDate) {
+ $endDate = $memType['current_membership'];
+ $this->_defaultMemTypeId = $memType['id'];
+ }
+ }
+ }
+ $membershipTypes[] = $memType;
+ }
+ }
+ }
+
+ $this->assign('showRadio', $formItems);
+ if ($formItems) {
+ if (!$membershipPriceset) {
+ if (!$membershipBlock['is_required']) {
+ $this->assign('showRadioNoThanks', TRUE);
+ $radio[''] = $this->createElement('radio', NULL, NULL, NULL, 'no_thanks', NULL);
+ $this->addGroup($radio, 'selectMembership', NULL);
+ }
+ elseif ($membershipBlock['is_required'] && count($radio) == 1) {
+ $temp = array_keys($radio);
+ $this->add('hidden', 'selectMembership', $temp[0], array('id' => 'selectMembership'));
+ $this->assign('singleMembership', TRUE);
+ $this->assign('showRadio', FALSE);
+ }
+ else {
+ $this->addGroup($radio, 'selectMembership', NULL);
+ }
+
+ $this->addRule('selectMembership', ts('Please select one of the memberships.'), 'required');
+ }
+ else {
+ $autoRenewOption = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId);
+ $this->assign('autoRenewOption', $autoRenewOption);
+ }
+
+ if (!$this->_values['is_pay_later'] && is_array($this->_paymentProcessors) && ($allowAutoRenewMembership || $autoRenewOption)) {
+ $this->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.'));
+ }
+
+ }
+
+ $this->assign('membershipBlock', $membershipBlock);
+ $this->assign('membershipTypes', $membershipTypes);
+ $this->assign('allowAutoRenewMembership', $allowAutoRenewMembership);
+ $this->assign('autoRenewMembershipTypeOptions', json_encode($autoRenewMembershipTypeOptions));
+
+ //give preference to user submitted auto_renew value.
+ $takeUserSubmittedAutoRenew = (!empty($_POST) || $this->isSubmitted()) ? TRUE : FALSE;
+ $this->assign('takeUserSubmittedAutoRenew', $takeUserSubmittedAutoRenew);
+ }
+
+ return $separateMembershipPayment;
+ }
+
+
}
* @var array
* An array of payment processor details with objects loaded in the 'object' field.
*/
- public $_paymentProcessors;
+ protected $_paymentProcessors;
/**
* Available payment processors (IDS).
}
}
+ /**
+ * Handle Payment Processor switching for contribution and event registration forms.
+ *
+ * This function is shared between contribution & event forms & this is their common class.
+ *
+ * However, this should be seen as an in-progress refactor, the end goal being to also align the
+ * backoffice forms that action payments.
+ *
+ * This function overlaps assignPaymentProcessor, in a bad way.
+ */
+ protected function preProcessPaymentOptions() {
+ $this->_paymentProcessorID = NULL;
+ if ($this->_paymentProcessors) {
+ if (!empty($this->_submitValues)) {
+ $this->_paymentProcessorID = CRM_Utils_Array::value('payment_processor_id', $this->_submitValues);
+ $this->_paymentProcessor = CRM_Utils_Array::value($this->_paymentProcessorID, $this->_paymentProcessors);
+ $this->set('type', $this->_paymentProcessorID);
+ $this->set('mode', $this->_mode);
+ $this->set('paymentProcessor', $this->_paymentProcessor);
+ }
+ // Set default payment processor
+ else {
+ foreach ($this->_paymentProcessors as $values) {
+ if (!empty($values['is_default']) || count($this->_paymentProcessors) == 1) {
+ $this->_paymentProcessorID = $values['id'];
+ break;
+ }
+ }
+ }
+ if ($this->_paymentProcessorID) {
+ CRM_Core_Payment_ProcessorForm::preProcess($this);
+ }
+ else {
+ $this->_paymentProcessor = array();
+ }
+ CRM_Financial_Form_Payment::addCreditCardJs();
+ }
+ $this->assign('paymentProcessorID', $this->_paymentProcessorID);
+ }
/**
* Setter function for options.
// We hide the payment fields if the event is full or requires approval,
// and the current user has not yet been approved CRM-12279
$this->_noFees = (($eventFull || $this->_requireApproval) && !$this->_allowConfirmation);
- CRM_Contribute_Form_Contribution_Main::preProcessPaymentOptions($this, $this->_noFees);
+ $this->_paymentProcessors = $this->_noFees ? array() : $this->get('paymentProcessors');
+ $this->preProcessPaymentOptions();
if ($this->_snippet) {
return;
}
return NULL;
}
- /**
- * Build Membership Block in Contribution Pages.
- *
- * @param CRM_Core_Form $form
- * Form object.
- * @param int $pageID
- * Unused?.
- * @param int $cid
- * Contact checked for having a current membership for a particular membership.
- * @param bool $formItems
- * @param int $selectedMembershipTypeID
- * Selected membership id.
- * @param bool $thankPage
- * Thank you page.
- * @param null $isTest
- *
- * @return bool
- * Is this a separate membership payment
- */
- public static function buildMembershipBlock(
- &$form,
- $pageID,
- $cid,
- $formItems = FALSE,
- $selectedMembershipTypeID = NULL,
- $thankPage = FALSE,
- $isTest = NULL
- ) {
-
- $separateMembershipPayment = FALSE;
- if ($form->_membershipBlock) {
- $form->_currentMemberships = array();
-
- $membershipBlock = $form->_membershipBlock;
- $membershipTypeIds = $membershipTypes = $radio = array();
- $membershipPriceset = (!empty($form->_priceSetId) && $form->_useForMember) ? TRUE : FALSE;
-
- $allowAutoRenewMembership = $autoRenewOption = FALSE;
- $autoRenewMembershipTypeOptions = array();
-
- $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
-
- $separateMembershipPayment = CRM_Utils_Array::value('is_separate_payment', $membershipBlock);
-
- if ($membershipPriceset) {
- foreach ($form->_priceSet['fields'] as $pField) {
- if (empty($pField['options'])) {
- continue;
- }
- foreach ($pField['options'] as $opId => $opValues) {
- if (empty($opValues['membership_type_id'])) {
- continue;
- }
- $membershipTypeIds[$opValues['membership_type_id']] = $opValues['membership_type_id'];
- }
- }
- }
- elseif (!empty($membershipBlock['membership_types'])) {
- $membershipTypeIds = explode(',', $membershipBlock['membership_types']);
- }
-
- if (!empty($membershipTypeIds)) {
- //set status message if wrong membershipType is included in membershipBlock
- if (isset($form->_mid) && !$membershipPriceset) {
- $membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
- $form->_mid,
- 'membership_type_id'
- );
- if (!in_array($membershipTypeID, $membershipTypeIds)) {
- CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Invalid Membership'), 'error');
- }
- }
-
- $membershipTypeValues = self::buildMembershipTypeValues($form, $membershipTypeIds);
- $form->_membershipTypeValues = $membershipTypeValues;
- $endDate = NULL;
- foreach ($membershipTypeIds as $value) {
- $memType = $membershipTypeValues[$value];
- if ($selectedMembershipTypeID != NULL) {
- if ($memType['id'] == $selectedMembershipTypeID) {
- $form->assign('minimum_fee',
- CRM_Utils_Array::value('minimum_fee', $memType)
- );
- $form->assign('membership_name', $memType['name']);
- if (!$thankPage && $cid) {
- $membership = new CRM_Member_DAO_Membership();
- $membership->contact_id = $cid;
- $membership->membership_type_id = $memType['id'];
- if ($membership->find(TRUE)) {
- $form->assign('renewal_mode', TRUE);
- $memType['current_membership'] = $membership->end_date;
- $form->_currentMemberships[$membership->membership_type_id] = $membership->membership_type_id;
- }
- }
- $membershipTypes[] = $memType;
- }
- }
- elseif ($memType['is_active']) {
- $javascriptMethod = NULL;
- $allowAutoRenewOpt = 1;
- if (is_array($form->_paymentProcessors)) {
- foreach ($form->_paymentProcessors as $id => $val) {
- if (!$val['is_recur']) {
- $allowAutoRenewOpt = 0;
- continue;
- }
- }
- }
-
- $javascriptMethod = array('onclick' => "return showHideAutoRenew( this.value );");
- $autoRenewMembershipTypeOptions["autoRenewMembershipType_{$value}"] = (int) $allowAutoRenewOpt * CRM_Utils_Array::value($value, CRM_Utils_Array::value('auto_renew', $form->_membershipBlock));;
-
- if ($allowAutoRenewOpt) {
- $allowAutoRenewMembership = TRUE;
- }
-
- //add membership type.
- $radio[$memType['id']] = $form->createElement('radio', NULL, NULL, NULL,
- $memType['id'], $javascriptMethod
- );
- if ($cid) {
- $membership = new CRM_Member_DAO_Membership();
- $membership->contact_id = $cid;
- $membership->membership_type_id = $memType['id'];
-
- //show current membership, skip pending and cancelled membership records,
- //because we take first membership record id for renewal
- $membership->whereAdd('status_id != 5 AND status_id !=6');
-
- if (!is_null($isTest)) {
- $membership->is_test = $isTest;
- }
-
- //CRM-4297
- $membership->orderBy('end_date DESC');
-
- if ($membership->find(TRUE)) {
- if (!$membership->end_date) {
- unset($radio[$memType['id']]);
- $form->assign('islifetime', TRUE);
- continue;
- }
- $form->assign('renewal_mode', TRUE);
- $form->_currentMemberships[$membership->membership_type_id] = $membership->membership_type_id;
- $memType['current_membership'] = $membership->end_date;
- if (!$endDate) {
- $endDate = $memType['current_membership'];
- $form->_defaultMemTypeId = $memType['id'];
- }
- if ($memType['current_membership'] < $endDate) {
- $endDate = $memType['current_membership'];
- $form->_defaultMemTypeId = $memType['id'];
- }
- }
- }
- $membershipTypes[] = $memType;
- }
- }
- }
-
- $form->assign('showRadio', $formItems);
- if ($formItems) {
- if (!$membershipPriceset) {
- if (!$membershipBlock['is_required']) {
- $form->assign('showRadioNoThanks', TRUE);
- $radio[''] = $form->createElement('radio', NULL, NULL, NULL, 'no_thanks', NULL);
- $form->addGroup($radio, 'selectMembership', NULL);
- }
- elseif ($membershipBlock['is_required'] && count($radio) == 1) {
- $temp = array_keys($radio);
- $form->add('hidden', 'selectMembership', $temp[0], array('id' => 'selectMembership'));
- $form->assign('singleMembership', TRUE);
- $form->assign('showRadio', FALSE);
- }
- else {
- $form->addGroup($radio, 'selectMembership', NULL);
- }
-
- $form->addRule('selectMembership', ts('Please select one of the memberships.'), 'required');
- }
- else {
- $autoRenewOption = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($form->_priceSetId);
- $form->assign('autoRenewOption', $autoRenewOption);
- }
-
- if (!$form->_values['is_pay_later'] && is_array($form->_paymentProcessors) && ($allowAutoRenewMembership || $autoRenewOption)) {
- $form->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.'));
- }
-
- }
-
- $form->assign('membershipBlock', $membershipBlock);
- $form->assign('membershipTypes', $membershipTypes);
- $form->assign('allowAutoRenewMembership', $allowAutoRenewMembership);
- $form->assign('autoRenewMembershipTypeOptions', json_encode($autoRenewMembershipTypeOptions));
-
- //give preference to user submitted auto_renew value.
- $takeUserSubmittedAutoRenew = (!empty($_POST) || $form->isSubmitted()) ? TRUE : FALSE;
- $form->assign('takeUserSubmittedAutoRenew', $takeUserSubmittedAutoRenew);
- }
-
- return $separateMembershipPayment;
- }
-
/**
* Return Membership Block info in Contribution Pages.
*