INFRA-132 - Comment grammar cleanup
[civicrm-core.git] / CRM / Member / Form.php
index 749bb46ebcc40cd7aa9cf941254259769b0024f4..8918b2d30e1c54130a682fbdc28918c4035cb49b 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  * Base class for offline membership / membership type / membership renewal and membership status forms
  *
  */
-class CRM_Member_Form extends CRM_Core_Form {
+class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
 
   /**
    * The id of the object being edited / created
    *
    * @var int
    */
-  protected $_id;
+  public $_id;
 
   /**
-   * The name of the BAO object for this form
-   *
-   * @var string
+   * Membership Type ID
+   * @var
    */
-  protected $_BAOName;
+  protected $_memType;
+
+  /**
+   * Array of from email ids
+   * @var array
+   */
+  protected $_fromEmails = array();
+
+  public function preProcess() {
+    $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
+    $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'membership');
+    $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
+    $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
+    $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
 
-  function preProcess() {
-    $this->_id = $this->get('id');
-    $this->_BAOName = $this->get('BAOName');
+    $this->assign('context', $this->_context);
+    $this->assign('membershipMode', $this->_mode);
+    $this->assign('contactID', $this->_contactID);
+
+    if ($this->_mode) {
+      $this->assignPaymentRelatedVariables();
+    }
+
+    if ($this->_id) {
+      $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id');
+      $this->_membershipIDs[] = $this->_id;
+    }
+    $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
   }
 
   /**
-   * This function sets the default values for the form. MobileProvider that in edit/view mode
+   * Set default values for the form. MobileProvider that in edit/view mode
    * the default values are retrieved from the database
    *
-   * @access public
    *
    * @return array defaults
    */
-  function setDefaultValues() {
+  public function setDefaultValues() {
     $defaults = array();
-
     if (isset($this->_id)) {
       $params = array('id' => $this->_id);
-      $baoName = $this->_BAOName;
-      $baoName::retrieve($params, $defaults);
+      CRM_Member_BAO_Membership::retrieve($params, $defaults);
     }
 
     if (isset($defaults['minimum_fee'])) {
@@ -98,23 +117,30 @@ class CRM_Member_Form extends CRM_Core_Form {
   }
 
   /**
-   * Function to actually build the form
+   * Build the form object
    *
    * @return void
-   * @access public
    */
   public function buildQuickForm() {
+    if ($this->_mode) {
+      $this->add('select', 'payment_processor_id',
+        ts('Payment Processor'),
+        $this->_processors, TRUE,
+        array('onChange' => "buildAutoRenew( null, this.value );")
+      );
+      CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, TRUE);
+    }
     if ($this->_action & CRM_Core_Action::RENEW) {
       $this->addButtons(array(
           array(
             'type' => 'upload',
             'name' => ts('Renew'),
-            'isDefault' => TRUE
+            'isDefault' => TRUE,
           ),
           array(
             'type' => 'cancel',
-            'name' => ts('Cancel')
-          )
+            'name' => ts('Cancel'),
+          ),
         )
       );
     }
@@ -123,12 +149,12 @@ class CRM_Member_Form extends CRM_Core_Form {
           array(
             'type' => 'next',
             'name' => ts('Delete'),
-            'isDefault' => TRUE
+            'isDefault' => TRUE,
           ),
           array(
             'type' => 'cancel',
-            'name' => ts('Cancel')
-          )
+            'name' => ts('Cancel'),
+          ),
         )
       );
     }
@@ -137,28 +163,28 @@ class CRM_Member_Form extends CRM_Core_Form {
           array(
             'type' => 'upload',
             'name' => ts('Save'),
-            'isDefault' => TRUE
+            'isDefault' => TRUE,
           ),
           array(
             'type' => 'upload',
             'name' => ts('Save and New'),
-            'subName' => 'new'
+            'subName' => 'new',
           ),
           array(
             'type' => 'cancel',
-            'name' => ts('Cancel')
-          )
+            'name' => ts('Cancel'),
+          ),
         )
       );
     }
   }
 
-  /*
-   * Function to extract values from the contact create boxes on the form and assign appropriatley  to
+  /**
+   * Extract values from the contact create boxes on the form and assign appropriately  to
    *
    *  - $this->_contributorEmail,
    *  - $this->_memberEmail &
-   *  - $this->_contributonName
+   *  - $this->_contributionName
    *  - $this->_memberName
    *  - $this->_contactID (effectively memberContactId but changing might have spin-off effects)
    *  - $this->_contributorContactId - id of the contributor
@@ -167,14 +193,12 @@ class CRM_Member_Form extends CRM_Core_Form {
    * If the member & contributor are the same then the values will be the same. But if different people paid
    * then they weill differ
    *
-   * @param $formValues array values from form. The important values we are looking for are
+   * @param array $formValues
+   *   values from form. The important values we are looking for are.
    *  - contact_id
    *  - soft_credit_contact_id
    */
-  /**
-   * @param $formValues
-   */
-  function storeContactFields($formValues){
+  public function storeContactFields($formValues) {
     // in a 'standalone form' (contact id not in the url) the contact will be in the form values
     if (!empty($formValues['contact_id'])) {
       $this->_contactID = $formValues['contact_id'];
@@ -188,8 +212,8 @@ class CRM_Member_Form extends CRM_Core_Form {
     // here we store details in order to do that
     if (!empty($formValues['soft_credit_contact_id'])) {
       $this->_receiptContactId = $this->_contributorContactID = $formValues['soft_credit_contact_id'];
-       list( $this->_contributorDisplayName,
-         $this->_contributorEmail ) = CRM_Contact_BAO_Contact_Location::getEmailDetails( $this->_contributorContactID );
+      list($this->_contributorDisplayName,
+         $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contributorContactID);
     }
     else {
       $this->_receiptContactId = $this->_contributorContactID = $this->_contactID;
@@ -198,4 +222,3 @@ class CRM_Member_Form extends CRM_Core_Form {
     }
   }
 }
-