From e622655c70429e9436a7113217670f2d6bfcc9e0 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sat, 30 Jan 2021 14:20:44 +0000 Subject: [PATCH] Initial simplification of buildMembershipBlock --- CRM/Contribute/Form/Contribution/Confirm.php | 56 +------------- CRM/Contribute/Form/Contribution/Main.php | 74 ++++++++----------- CRM/Contribute/Form/Contribution/ThankYou.php | 62 +--------------- 3 files changed, 36 insertions(+), 156 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 44048a1121..b0cf2cf1a3 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -527,9 +527,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr ) { $this->buildMembershipBlock( $this->_membershipContactID, - FALSE, - $params['selectMembership'], - FALSE + $params['selectMembership'] ); if (!empty($params['auto_renew'])) { $this->assign('auto_renew', TRUE); @@ -659,13 +657,8 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr * * @param int $cid * Contact checked for having a current membership for a particular membership. - * @param bool $isContributionMainPage - * Is this the main page? If so add form input fields. - * (or better yet don't have this functionality in a function shared with forms that don't share it). * @param int|array $selectedMembershipTypeID * Selected membership id. - * @param bool $thankPage - * Thank you page. * @param null $isTest * * @return bool @@ -674,14 +667,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr * @throws \CiviCRM_API3_Exception * @throws \CRM_Core_Exception */ - protected function buildMembershipBlock( - $cid, - $isContributionMainPage = FALSE, - $selectedMembershipTypeID = NULL, - $thankPage = FALSE, - $isTest = NULL - ) { - + private function buildMembershipBlock($cid, $selectedMembershipTypeID = NULL, $isTest = NULL) { $separateMembershipPayment = FALSE; if ($this->_membershipBlock) { $this->_currentMemberships = []; @@ -744,7 +730,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr if ($memType['id'] == $selectedMembershipTypeID) { $this->assign('minimum_fee', $memType['minimum_fee'] ?? NULL); $this->assign('membership_name', $memType['name']); - if (!$thankPage && $cid) { + if ($cid) { $membership = new CRM_Member_DAO_Membership(); $membership->contact_id = $cid; $membership->membership_type_id = $memType['id']; @@ -815,7 +801,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } $this->assign('membershipBlock', $this->_membershipBlock); - $this->assign('showRadio', $isContributionMainPage); + $this->assign('showRadio', FALSE); $this->assign('membershipTypes', $membershipTypes); $this->assign('allowAutoRenewMembership', $allowAutoRenewMembership); $this->assign('autoRenewMembershipTypeOptions', json_encode($autoRenewMembershipTypeOptions)); @@ -833,40 +819,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr else { $this->assign('autoRenewOption', $autoRenewOption); } - - if ($isContributionMainPage) { - if (!$membershipPriceset) { - if (!$this->_membershipBlock['is_required']) { - $this->assign('showRadioNoThanks', TRUE); - $radio['no_thanks'] = NULL; - $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); - } - elseif ($this->_membershipBlock['is_required'] && count($radio) == 1) { - $temp = array_keys($radio); - $this->add('hidden', 'selectMembership', $temp[0], ['id' => 'selectMembership']); - $this->assign('singleMembership', TRUE); - $this->assign('showRadio', FALSE); - } - else { - foreach ($radioOptAttrs as $opt => $attrs) { - $attrs['class'] = ' required'; - } - $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); - } - - $this->addRule('selectMembership', ts('Please select one of the memberships.'), 'required'); - } - - if ((!$this->_values['is_pay_later'] || is_array($this->_paymentProcessors)) && ($allowAutoRenewMembership || $autoRenewOption)) { - if ($autoRenewOption == 2) { - $this->addElement('hidden', 'auto_renew', ts('Please renew my membership automatically.')); - } - else { - $this->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.')); - } - } - - } } return $separateMembershipPayment; diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index d6cada6b04..223d2c7805 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -361,7 +361,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->_separateMembershipPayment = $this->buildMembershipBlock( $this->_membershipContactID, - TRUE, NULL, FALSE, + NULL, $isTest ); } @@ -511,13 +511,8 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu * * @param int $cid * Contact checked for having a current membership for a particular membership. - * @param bool $isContributionMainPage - * Is this the main page? If so add form input fields. - * (or better yet don't have this functionality in a function shared with forms that don't share it). * @param int|array $selectedMembershipTypeID * Selected membership id. - * @param bool $thankPage - * Thank you page. * @param null $isTest * * @return bool @@ -526,14 +521,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu * @throws \CiviCRM_API3_Exception * @throws \CRM_Core_Exception */ - protected function buildMembershipBlock( - $cid, - $isContributionMainPage = FALSE, - $selectedMembershipTypeID = NULL, - $thankPage = FALSE, - $isTest = NULL - ) { - + private function buildMembershipBlock($cid, $selectedMembershipTypeID = NULL, $isTest = NULL) { $separateMembershipPayment = FALSE; if ($this->_membershipBlock) { $this->_currentMemberships = []; @@ -596,7 +584,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu if ($memType['id'] == $selectedMembershipTypeID) { $this->assign('minimum_fee', $memType['minimum_fee'] ?? NULL); $this->assign('membership_name', $memType['name']); - if (!$thankPage && $cid) { + if ($cid) { $membership = new CRM_Member_DAO_Membership(); $membership->contact_id = $cid; $membership->membership_type_id = $memType['id']; @@ -667,7 +655,7 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } $this->assign('membershipBlock', $this->_membershipBlock); - $this->assign('showRadio', $isContributionMainPage); + $this->assign('showRadio', TRUE); $this->assign('membershipTypes', $membershipTypes); $this->assign('allowAutoRenewMembership', $allowAutoRenewMembership); $this->assign('autoRenewMembershipTypeOptions', json_encode($autoRenewMembershipTypeOptions)); @@ -686,39 +674,37 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->assign('autoRenewOption', $autoRenewOption); } - if ($isContributionMainPage) { - if (!$membershipPriceset) { - if (!$this->_membershipBlock['is_required']) { - $this->assign('showRadioNoThanks', TRUE); - $radio['no_thanks'] = NULL; - $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); - } - elseif ($this->_membershipBlock['is_required'] && count($radio) == 1) { - $temp = array_keys($radio); - $this->add('hidden', 'selectMembership', $temp[0], ['id' => 'selectMembership']); - $this->assign('singleMembership', TRUE); - $this->assign('showRadio', FALSE); - } - else { - foreach ($radioOptAttrs as $opt => $attrs) { - $attrs['class'] = ' required'; - } - $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); - } - - $this->addRule('selectMembership', ts('Please select one of the memberships.'), 'required'); + if (!$membershipPriceset) { + if (!$this->_membershipBlock['is_required']) { + $this->assign('showRadioNoThanks', TRUE); + $radio['no_thanks'] = NULL; + $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); } - - if ((!$this->_values['is_pay_later'] || is_array($this->_paymentProcessors)) && ($allowAutoRenewMembership || $autoRenewOption)) { - if ($autoRenewOption == 2) { - $this->addElement('hidden', 'auto_renew', ts('Please renew my membership automatically.')); - } - else { - $this->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.')); + elseif ($this->_membershipBlock['is_required'] && count($radio) == 1) { + $temp = array_keys($radio); + $this->add('hidden', 'selectMembership', $temp[0], ['id' => 'selectMembership']); + $this->assign('singleMembership', TRUE); + $this->assign('showRadio', FALSE); + } + else { + foreach ($radioOptAttrs as $opt => $attrs) { + $attrs['class'] = ' required'; } + $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); } + $this->addRule('selectMembership', ts('Please select one of the memberships.'), 'required'); } + + if ((!$this->_values['is_pay_later'] || is_array($this->_paymentProcessors)) && ($allowAutoRenewMembership || $autoRenewOption)) { + if ($autoRenewOption == 2) { + $this->addElement('hidden', 'auto_renew', ts('Please renew my membership automatically.')); + } + else { + $this->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.')); + } + } + } return $separateMembershipPayment; diff --git a/CRM/Contribute/Form/Contribution/ThankYou.php b/CRM/Contribute/Form/Contribution/ThankYou.php index 8702d61d22..172cb1fb53 100644 --- a/CRM/Contribute/Form/Contribution/ThankYou.php +++ b/CRM/Contribute/Form/Contribution/ThankYou.php @@ -167,9 +167,7 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont $this->buildMembershipBlock( $this->_membershipContactID, - FALSE, $membershipTypeID, - TRUE, NULL ); @@ -294,13 +292,8 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont * * @param int $cid * Contact checked for having a current membership for a particular membership. - * @param bool $isContributionMainPage - * Is this the main page? If so add form input fields. - * (or better yet don't have this functionality in a function shared with forms that don't share it). * @param int|array $selectedMembershipTypeID * Selected membership id. - * @param bool $thankPage - * Thank you page. * @param null $isTest * * @return bool @@ -309,14 +302,7 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont * @throws \CiviCRM_API3_Exception * @throws \CRM_Core_Exception */ - protected function buildMembershipBlock( - $cid, - $isContributionMainPage = FALSE, - $selectedMembershipTypeID = NULL, - $thankPage = FALSE, - $isTest = NULL - ) { - + private function buildMembershipBlock($cid, $selectedMembershipTypeID = NULL, $isTest = NULL) { $separateMembershipPayment = FALSE; if ($this->_membershipBlock) { $this->_currentMemberships = []; @@ -379,16 +365,6 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont if ($memType['id'] == $selectedMembershipTypeID) { $this->assign('minimum_fee', $memType['minimum_fee'] ?? NULL); $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; } } @@ -450,7 +426,7 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont } $this->assign('membershipBlock', $this->_membershipBlock); - $this->assign('showRadio', $isContributionMainPage); + $this->assign('showRadio', FALSE); $this->assign('membershipTypes', $membershipTypes); $this->assign('allowAutoRenewMembership', $allowAutoRenewMembership); $this->assign('autoRenewMembershipTypeOptions', json_encode($autoRenewMembershipTypeOptions)); @@ -468,40 +444,6 @@ class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_Cont else { $this->assign('autoRenewOption', $autoRenewOption); } - - if ($isContributionMainPage) { - if (!$membershipPriceset) { - if (!$this->_membershipBlock['is_required']) { - $this->assign('showRadioNoThanks', TRUE); - $radio['no_thanks'] = NULL; - $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); - } - elseif ($this->_membershipBlock['is_required'] && count($radio) == 1) { - $temp = array_keys($radio); - $this->add('hidden', 'selectMembership', $temp[0], ['id' => 'selectMembership']); - $this->assign('singleMembership', TRUE); - $this->assign('showRadio', FALSE); - } - else { - foreach ($radioOptAttrs as $opt => $attrs) { - $attrs['class'] = ' required'; - } - $this->addRadio('selectMembership', NULL, $radio, [], NULL, FALSE, $radioOptAttrs); - } - - $this->addRule('selectMembership', ts('Please select one of the memberships.'), 'required'); - } - - if ((!$this->_values['is_pay_later'] || is_array($this->_paymentProcessors)) && ($allowAutoRenewMembership || $autoRenewOption)) { - if ($autoRenewOption == 2) { - $this->addElement('hidden', 'auto_renew', ts('Please renew my membership automatically.')); - } - else { - $this->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.')); - } - } - - } } return $separateMembershipPayment; -- 2.25.1