From 4aa7d84473f9ce2f97686ae6c017c99b0d820450 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 18 May 2015 21:40:26 +1200 Subject: [PATCH] CRM-16402 consolidate shared code onto parent class --- CRM/Member/Form.php | 60 +++++++++++++++++++++++++++ CRM/Member/Form/Membership.php | 55 ++---------------------- CRM/Member/Form/MembershipRenewal.php | 43 ------------------- 3 files changed, 63 insertions(+), 95 deletions(-) diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index da11de287d..1e873943e0 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -115,6 +115,7 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { * Build the form object. */ public function buildQuickForm() { + if ($this->_mode) { $this->add('select', 'payment_processor_id', ts('Payment Processor'), @@ -123,6 +124,65 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { ); CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE); } + // Build the form for auto renew. This is displayed when in credit card mode or update mode. + // The reason for showing it in update mode is not that clear. + $autoRenew = array(); + $recurProcessor = array(); + if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) { + if (!empty($recurProcessor)) { + $autoRenew = array(); + if (!empty($membershipType)) { + $sql = ' +SELECT id, + auto_renew, + duration_unit, + duration_interval + FROM civicrm_membership_type +WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; + $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql); + while ($recurMembershipTypes->fetch()) { + $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew; + foreach (array( + 'id', + 'auto_renew', + 'duration_unit', + 'duration_interval', + ) as $fld) { + $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->$fld; + } + } + } + + if ($this->_mode) { + if (!empty($this->_recurPaymentProcessors)) { + $this->assign('allowAutoRenew', TRUE); + } + } + + $this->assign('autoRenew', json_encode($autoRenew)); + $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'), + NULL, array('onclick' => "showHideByValue('auto_renew','','send-receipt','table-row','radio',true); showHideNotice( );") + ); + if ($this->_action & CRM_Core_Action::UPDATE) { + $autoRenewElement->freeze(); + } + } + + } + $this->assign('recurProcessor', json_encode($recurProcessor)); + + if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) { + $this->addElement('checkbox', + 'auto_renew', + ts('Membership renewed automatically'), + NULL, + array('onclick' => "buildReceiptANDNotice( );") + ); + + $this->assignPaymentRelatedVariables(); + } + $this->assign('autoRenewOptions', json_encode($autoRenew)); + if ($this->_action & CRM_Core_Action::RENEW) { $this->addButtons(array( array( diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 9f153c633c..88d22638e5 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -97,7 +97,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { protected $_receiptContactId = NULL; /** - * Keep a class variable for ALL membeshipID's so + * Keep a class variable for ALL membership IDs so * postProcess hook function can do something with it * * @var array @@ -105,7 +105,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { protected $_membershipIDs = array(); /** - * An array to hold a list of datefields on the form + * An array to hold a list of date fields on the form * so that they can be converted to ISO in a consistent manner * * @var array @@ -584,52 +584,6 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $memTypeJs = array('onChange' => "CRM.buildCustomData( 'Membership', this.value );"); - //build the form for auto renew. - $autoRenew = array(); - if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) { - $this->addElement('checkbox', - 'auto_renew', - ts('Membership renewed automatically'), - NULL, - array('onclick' => "buildReceiptANDNotice( );") - ); - - $this->assignPaymentRelatedVariables(); - - if ($this->_mode) { - if (!empty($this->_recurPaymentProcessors)) { - if (!empty($membershipType)) { - $sql = ' -SELECT id, - auto_renew, - duration_unit, - duration_interval - FROM civicrm_membership_type -WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; - $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql); - while ($recurMembershipTypes->fetch()) { - $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew; - foreach (array( - 'id', - 'auto_renew', - 'duration_unit', - 'duration_interval', - ) as $fld) { - $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->$fld; - } - } - } - $memTypeJs = array( - 'onChange' => - "CRM.buildCustomData( 'Membership', this.value ); buildAutoRenew(this.value, null );", - ); - $this->assign('allowAutoRenew', TRUE); - } - } - } - - $this->assign('autoRenewOptions', json_encode($autoRenew)); - // for max_related: a little JS to show/hide & set default value $memTypeJs['onChange'] = "buildMaxRelated(this.value,true); " . $memTypeJs['onChange']; $this->add('text', 'max_related', ts('Max related'), @@ -1705,10 +1659,7 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $lineItems = CRM_Price_BAO_LineItem::getLineItems($params['contribution_id'], 'contribution', NULL, TRUE, TRUE); $itemId = key($lineItems); $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id'); - $fieldType = NULL; - if ($itemId && !empty($lineItems[$itemId]['price_field_id'])) { - $fieldType = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'html_type'); - } + $lineItems[$itemId]['unit_price'] = $params['total_amount']; $lineItems[$itemId]['line_total'] = $params['total_amount']; $lineItems[$itemId]['id'] = $itemId; diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 30225d9221..eb977eac39 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -318,49 +318,6 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { } $js = array('onChange' => "setPaymentBlock( ); CRM.buildCustomData( 'Membership', this.value );"); - - //build the form for auto renew. - $recurProcessor = array(); - if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) { - //get the valid recurring processors. - $test = strtolower($this->_mode) == 'test' ? TRUE : FALSE; - $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, $test, 'is_recur = 1'); - $recurProcessor = array_intersect_key($this->_processors, $recurring); - if (!empty($recurProcessor)) { - $autoRenew = array(); - if (!empty($membershipType)) { - $sql = ' -SELECT id, - auto_renew, - duration_unit, - duration_interval - FROM civicrm_membership_type -WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; - $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql); - while ($recurMembershipTypes->fetch()) { - $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew; - foreach (array( - 'id', - 'auto_renew', - 'duration_unit', - 'duration_interval', - ) as $fld) { - $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->$fld; - } - } - } - $js = array('onChange' => "setPaymentBlock(); CRM.buildCustomData( 'Membership', this.value );"); - $this->assign('autoRenew', json_encode($autoRenew)); - } - $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'), - NULL, array('onclick' => "showHideByValue('auto_renew','','send-receipt','table-row','radio',true); showHideNotice( );") - ); - if ($this->_action & CRM_Core_Action::UPDATE) { - $autoRenewElement->freeze(); - } - } - $this->assign('recurProcessor', json_encode($recurProcessor)); - $sel = &$this->addElement('hierselect', 'membership_type_id', ts('Renewal Membership Organization and Type'), $js -- 2.25.1