CRM-16402 consolidate shared code onto parent class
authorEileen McNaughton <eileen@fuzion.co.nz>
Mon, 18 May 2015 09:40:26 +0000 (21:40 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Mon, 18 May 2015 09:42:15 +0000 (21:42 +1200)
CRM/Member/Form.php
CRM/Member/Form/Membership.php
CRM/Member/Form/MembershipRenewal.php

index da11de287d8cede35505a3361b21674daf4789bb..1e873943e018f6567c1ef549eee9e8035aae1b5b 100644 (file)
@@ -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(
index 9f153c633c6234cfcc3b06079fbbc63780ba1b5f..88d22638e562f645b669123569d4edbe68c55223 100644 (file)
@@ -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;
index 30225d9221b34da69d51b541e5f8776c08e8a4ad..eb977eac39ed5ee7f79561265f91fb7ab0194fed 100644 (file)
@@ -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